Skip to content

Commit 994399d

Browse files
Amxxarr00ernestognw
authored
Address audit findings (5.3 diff audit) (#5584)
Co-authored-by: Arr00 <[email protected]> Co-authored-by: Ernesto García <[email protected]>
1 parent bfdbb67 commit 994399d

File tree

10 files changed

+34
-14
lines changed

10 files changed

+34
-14
lines changed

contracts/access/manager/AuthorityUtils.sol

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ library AuthorityUtils {
2626
if staticcall(gas(), authority, add(data, 0x20), mload(data), 0x00, 0x40) {
2727
immediate := mload(0x00)
2828
delay := mload(0x20)
29+
30+
// If delay does not fit in a uint32, return 0 (no delay)
31+
// equivalent to: if gt(delay, 0xFFFFFFFF) { delay := 0 }
32+
delay := mul(delay, iszero(shr(32, delay)))
2933
}
3034
}
3135
}

contracts/governance/extensions/GovernorVotesSuperQuorumFraction.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ abstract contract GovernorVotesSuperQuorumFraction is GovernorVotesQuorumFractio
6161

6262
/**
6363
* @dev Returns the super quorum for a `timepoint`, in terms of number of votes: `supply * numerator / denominator`.
64+
* See {GovernorSuperQuorum-superQuorum} for more details.
6465
*/
6566
function superQuorum(uint256 timepoint) public view virtual override returns (uint256) {
6667
return Math.mulDiv(token().getPastTotalSupply(timepoint), superQuorumNumerator(timepoint), quorumDenominator());

contracts/interfaces/draft-IERC6909.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ interface IERC6909 is IERC165 {
4949
function isOperator(address owner, address spender) external view returns (bool);
5050

5151
/**
52-
* @dev Sets an approval to `spender` for `amount` tokens of type `id` from the caller's tokens.
52+
* @dev Sets an approval to `spender` for `amount` of tokens of type `id` from the caller's tokens. An `amount` of
53+
* `type(uint256).max` signifies an unlimited approval.
5354
*
5455
* Must return true.
5556
*/

contracts/mocks/AuthorityMock.sol

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ contract NotAuthorityMock is IAuthority {
1212
}
1313

1414
contract AuthorityNoDelayMock is IAuthority {
15-
bool _immediate;
15+
bool private _immediate;
1616

1717
function canCall(
1818
address /* caller */,
@@ -28,22 +28,22 @@ contract AuthorityNoDelayMock is IAuthority {
2828
}
2929

3030
contract AuthorityDelayMock {
31-
bool _immediate;
32-
uint32 _delay;
31+
bool private _immediate;
32+
uint256 private _delay;
3333

3434
function canCall(
3535
address /* caller */,
3636
address /* target */,
3737
bytes4 /* selector */
38-
) external view returns (bool immediate, uint32 delay) {
38+
) external view returns (bool immediate, uint256 delay) {
3939
return (_immediate, _delay);
4040
}
4141

4242
function _setImmediate(bool immediate) external {
4343
_immediate = immediate;
4444
}
4545

46-
function _setDelay(uint32 delay) external {
46+
function _setDelay(uint256 delay) external {
4747
_delay = delay;
4848
}
4949
}

contracts/token/ERC6909/draft-ERC6909.sol

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ contract ERC6909 is Context, ERC165, IERC6909 {
7979

8080
/**
8181
* @dev Creates `amount` of token `id` and assigns them to `account`, by transferring it from address(0).
82-
* Relies on the `_update` mechanism
82+
* Relies on the `_update` mechanism.
8383
*
8484
* Emits a {Transfer} event with `from` set to the zero address.
8585
*
@@ -93,10 +93,9 @@ contract ERC6909 is Context, ERC165, IERC6909 {
9393
}
9494

9595
/**
96-
* @dev Moves `amount` of token `id` from `from` to `to` without checking for approvals.
97-
*
98-
* This internal function is equivalent to {transfer}, and can be used to
99-
* e.g. implement automatic token fees, slashing mechanisms, etc.
96+
* @dev Moves `amount` of token `id` from `from` to `to` without checking for approvals. This function verifies
97+
* that neither the sender nor the receiver are address(0), which means it cannot mint or burn tokens.
98+
* Relies on the `_update` mechanism.
10099
*
101100
* Emits a {Transfer} event.
102101
*

contracts/token/ERC6909/extensions/draft-ERC6909TokenSupply.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ contract ERC6909TokenSupply is ERC6909, IERC6909TokenSupply {
2626
}
2727
if (to == address(0)) {
2828
unchecked {
29-
// amount <= _balances[id][from] <= _totalSupplies[id]
29+
// amount <= _balances[from][id] <= _totalSupplies[id]
3030
_totalSupplies[id] -= amount;
3131
}
3232
}

contracts/utils/Strings.sol

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,10 @@ library Strings {
438438
* @dev Escape special characters in JSON strings. This can be useful to prevent JSON injection in NFT metadata.
439439
*
440440
* WARNING: This function should only be used in double quoted JSON strings. Single quotes are not escaped.
441+
*
442+
* NOTE: This function escapes all unicode characters, and not just the ones in ranges defined in section 2.5 of
443+
* RFC-4627 (U+0000 to U+001F, U+0022 and U+005C). ECMAScript's `JSON.parse` does recover escaped unicode
444+
* characters that are not in this range, but other tooling may provide different results.
441445
*/
442446
function escapeJSON(string memory input) internal pure returns (string memory) {
443447
bytes memory buffer = bytes(input);

contracts/utils/structs/MerkleTree.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ library MerkleTree {
178178
* root (before the update) and "new" root (after the update). The caller must verify that the reconstructed old
179179
* root is the last known one.
180180
*
181-
* The `proof` must be an up-to-date inclusion proof for the leaf being update. This means that this function is
181+
* The `proof` must be an up-to-date inclusion proof for the leaf being updated. This means that this function is
182182
* vulnerable to front-running. Any {push} or {update} operation (that changes the root of the tree) would render
183183
* all "in flight" updates invalid.
184184
*

test/access/manager/AuthorityUtils.test.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ const { ethers } = require('hardhat');
22
const { expect } = require('chai');
33
const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
44

5+
const { MAX_UINT32, MAX_UINT64 } = require('../../helpers/constants');
6+
57
async function fixture() {
68
const [user, other] = await ethers.getSigners();
79

@@ -70,7 +72,7 @@ describe('AuthorityUtils', function () {
7072
});
7173

7274
for (const immediate of [true, false]) {
73-
for (const delay of [0n, 42n]) {
75+
for (const delay of [0n, 42n, MAX_UINT32]) {
7476
it(`returns (immediate=${immediate}, delay=${delay})`, async function () {
7577
await this.authority._setImmediate(immediate);
7678
await this.authority._setDelay(delay);
@@ -80,6 +82,14 @@ describe('AuthorityUtils', function () {
8082
});
8183
}
8284
}
85+
86+
it('out of bound delay', async function () {
87+
await this.authority._setImmediate(false);
88+
await this.authority._setDelay(MAX_UINT64); // bigger than the expected uint32
89+
const result = await this.mock.$canCallWithDelay(this.authority, this.user, this.other, '0x12345678');
90+
expect(result.immediate).to.equal(false);
91+
expect(result.delay).to.equal(0n);
92+
});
8393
});
8494

8595
describe('when authority replies with empty data', function () {

test/helpers/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module.exports = {
2+
MAX_UINT32: 2n ** 32n - 1n,
23
MAX_UINT48: 2n ** 48n - 1n,
34
MAX_UINT64: 2n ** 64n - 1n,
45
};

0 commit comments

Comments
 (0)