Skip to content

Commit ccb5f2d

Browse files
authored
Fix 5.2 audit L-05, N-03, N-04, N-05 and N-06 issues (#5308)
1 parent ffca412 commit ccb5f2d

File tree

11 files changed

+21
-39
lines changed

11 files changed

+21
-39
lines changed

Diff for: contracts/account/utils/draft-ERC4337Utils.sol

+3-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
pragma solidity ^0.8.20;
44

5-
import {IEntryPoint, PackedUserOperation} from "../../interfaces/draft-IERC4337.sol";
5+
import {PackedUserOperation} from "../../interfaces/draft-IERC4337.sol";
66
import {Math} from "../../utils/math/Math.sol";
77
import {Packing} from "../../utils/Packing.sol";
88

@@ -71,12 +71,7 @@ library ERC4337Utils {
7171
return (aggregator_, block.timestamp < validAfter || validUntil < block.timestamp);
7272
}
7373

74-
/// @dev Computes the hash of a user operation with the current entrypoint and chainid.
75-
function hash(PackedUserOperation calldata self) internal view returns (bytes32) {
76-
return hash(self, address(this), block.chainid);
77-
}
78-
79-
/// @dev Sames as {hash}, but with a custom entrypoint and chainid.
74+
/// @dev Computes the hash of a user operation for a given entrypoint and chainid.
8075
function hash(
8176
PackedUserOperation calldata self,
8277
address entrypoint,
@@ -129,7 +124,7 @@ library ERC4337Utils {
129124
// Following values are "per gas"
130125
uint256 maxPriorityFee = maxPriorityFeePerGas(self);
131126
uint256 maxFee = maxFeePerGas(self);
132-
return Math.ternary(maxFee == maxPriorityFee, maxFee, Math.min(maxFee, maxPriorityFee + block.basefee));
127+
return Math.min(maxFee, maxPriorityFee + block.basefee);
133128
}
134129
}
135130

Diff for: contracts/account/utils/draft-ERC7579Utils.sol

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,19 @@ library ERC7579Utils {
2222
using Packing for *;
2323

2424
/// @dev A single `call` execution.
25-
CallType constant CALLTYPE_SINGLE = CallType.wrap(0x00);
25+
CallType internal constant CALLTYPE_SINGLE = CallType.wrap(0x00);
2626

2727
/// @dev A batch of `call` executions.
28-
CallType constant CALLTYPE_BATCH = CallType.wrap(0x01);
28+
CallType internal constant CALLTYPE_BATCH = CallType.wrap(0x01);
2929

3030
/// @dev A `delegatecall` execution.
31-
CallType constant CALLTYPE_DELEGATECALL = CallType.wrap(0xFF);
31+
CallType internal constant CALLTYPE_DELEGATECALL = CallType.wrap(0xFF);
3232

3333
/// @dev Default execution type that reverts on failure.
34-
ExecType constant EXECTYPE_DEFAULT = ExecType.wrap(0x00);
34+
ExecType internal constant EXECTYPE_DEFAULT = ExecType.wrap(0x00);
3535

3636
/// @dev Execution type that does not revert on failure.
37-
ExecType constant EXECTYPE_TRY = ExecType.wrap(0x01);
37+
ExecType internal constant EXECTYPE_TRY = ExecType.wrap(0x01);
3838

3939
/// @dev Emits when an {EXECTYPE_TRY} execution fails.
4040
event ERC7579TryExecuteFail(uint256 batchExecutionIndex, bytes result);

Diff for: contracts/governance/extensions/GovernorCountingOverridable.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {GovernorVotes} from "./GovernorVotes.sol";
99

1010
/**
1111
* @dev Extension of {Governor} which enables delegatees to override the vote of their delegates. This module requires a
12-
* token token that inherits `VotesExtended`.
12+
* token that inherits {VotesExtended}.
1313
*/
1414
abstract contract GovernorCountingOverridable is GovernorVotes {
1515
bytes32 public constant OVERRIDE_BALLOT_TYPEHASH =

Diff for: contracts/governance/utils/VotesExtended.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {Votes} from "./Votes.sol";
66
import {SafeCast} from "../../utils/math/SafeCast.sol";
77

88
/**
9-
* @dev Extension of {Votes} that adds exposes checkpoints for delegations and balances.
9+
* @dev Extension of {Votes} that adds checkpoints for delegations and balances.
1010
*/
1111
abstract contract VotesExtended is Votes {
1212
using SafeCast for uint256;

Diff for: contracts/interfaces/draft-IERC4337.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pragma solidity ^0.8.20;
1111
* - `callData` (`bytes`): The data to pass to the sender during the main execution call
1212
* - `callGasLimit` (`uint256`): The amount of gas to allocate the main execution call
1313
* - `verificationGasLimit` (`uint256`): The amount of gas to allocate for the verification step
14-
* - `preVerificationGas` (`uint256`): Extra gas to pay the bunder
14+
* - `preVerificationGas` (`uint256`): Extra gas to pay the bundler
1515
* - `maxFeePerGas` (`uint256`): Maximum fee per gas (similar to EIP-1559 max_fee_per_gas)
1616
* - `maxPriorityFeePerGas` (`uint256`): Maximum priority fee per gas (similar to EIP-1559 max_priority_fee_per_gas)
1717
* - `paymaster` (`address`): Address of paymaster contract, (or empty, if account pays for itself)

Diff for: contracts/proxy/Clones.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ library Clones {
5757
* @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`.
5858
*
5959
* This function uses the create2 opcode and a `salt` to deterministically deploy
60-
* the clone. Using the same `implementation` and `salt` multiple time will revert, since
60+
* the clone. Using the same `implementation` and `salt` multiple times will revert, since
6161
* the clones cannot be deployed twice at the same address.
6262
*/
6363
function cloneDeterministic(address implementation, bytes32 salt) internal returns (address instance) {
@@ -163,7 +163,7 @@ library Clones {
163163
* access the arguments within the implementation, use {fetchCloneArgs}.
164164
*
165165
* This function uses the create2 opcode and a `salt` to deterministically deploy the clone. Using the same
166-
* `implementation` and `salt` multiple time will revert, since the clones cannot be deployed twice at the same
166+
* `implementation` and `salt` multiple times will revert, since the clones cannot be deployed twice at the same
167167
* address.
168168
*/
169169
function cloneDeterministicWithImmutableArgs(

Diff for: contracts/utils/Bytes.sol

+5-7
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,13 @@ library Bytes {
2727
* NOTE: replicates the behavior of https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf[Javascript's `Array.indexOf`]
2828
*/
2929
function indexOf(bytes memory buffer, bytes1 s, uint256 pos) internal pure returns (uint256) {
30-
unchecked {
31-
uint256 length = buffer.length;
32-
for (uint256 i = pos; i < length; ++i) {
33-
if (bytes1(_unsafeReadBytesOffset(buffer, i)) == s) {
34-
return i;
35-
}
30+
uint256 length = buffer.length;
31+
for (uint256 i = pos; i < length; ++i) {
32+
if (bytes1(_unsafeReadBytesOffset(buffer, i)) == s) {
33+
return i;
3634
}
37-
return type(uint256).max;
3835
}
36+
return type(uint256).max;
3937
}
4038

4139
/**

Diff for: contracts/utils/CAIP10.sol

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
pragma solidity ^0.8.24;
44

5-
import {SafeCast} from "./math/SafeCast.sol";
65
import {Bytes} from "./Bytes.sol";
7-
import {CAIP2} from "./CAIP2.sol";
86
import {Strings} from "./Strings.sol";
7+
import {CAIP2} from "./CAIP2.sol";
98

109
/**
1110
* @dev Helper library to format and parse CAIP-10 identifiers
@@ -16,7 +15,6 @@ import {Strings} from "./Strings.sol";
1615
* account_address: [-.%a-zA-Z0-9]{1,128}
1716
*/
1817
library CAIP10 {
19-
using SafeCast for uint256;
2018
using Strings for address;
2119
using Bytes for bytes;
2220

Diff for: contracts/utils/CAIP2.sol

-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
pragma solidity ^0.8.24;
44

5-
import {SafeCast} from "./math/SafeCast.sol";
65
import {Bytes} from "./Bytes.sol";
76
import {Strings} from "./Strings.sol";
87

@@ -15,7 +14,6 @@ import {Strings} from "./Strings.sol";
1514
* reference: [-_a-zA-Z0-9]{1,32}
1615
*/
1716
library CAIP2 {
18-
using SafeCast for uint256;
1917
using Strings for uint256;
2018
using Bytes for bytes;
2119

Diff for: contracts/utils/NoncesKeyed.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pragma solidity ^0.8.20;
44
import {Nonces} from "./Nonces.sol";
55

66
/**
7-
* @dev Alternative to {Nonces}, that support key-ed nonces.
7+
* @dev Alternative to {Nonces}, that supports key-ed nonces.
88
*
99
* Follows the https://eips.ethereum.org/EIPS/eip-4337#semi-abstracted-nonce-support[ERC-4337's semi-abstracted nonce system].
1010
*/
@@ -19,7 +19,7 @@ abstract contract NoncesKeyed is Nonces {
1919
/**
2020
* @dev Consumes the next unused nonce for an address and key.
2121
*
22-
* Returns the current value without the key prefix. Consumed nonce is increased, so calling this functions twice
22+
* Returns the current value without the key prefix. Consumed nonce is increased, so calling this function twice
2323
* with the same arguments will return different (sequential) results.
2424
*/
2525
function _useNonce(address owner, uint192 key) internal virtual returns (uint256) {

Diff for: test/account/utils/draft-ERC4337Utils.test.js

-7
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,6 @@ describe('ERC4337Utils', function () {
133133
});
134134

135135
describe('hash', function () {
136-
it('returns the user operation hash', async function () {
137-
const userOp = new UserOperation({ sender: this.sender, nonce: 1 });
138-
const chainId = await ethers.provider.getNetwork().then(({ chainId }) => chainId);
139-
140-
expect(this.utils.$hash(userOp.packed)).to.eventually.equal(userOp.hash(this.utils.target, chainId));
141-
});
142-
143136
it('returns the operation hash with specified entrypoint and chainId', async function () {
144137
const userOp = new UserOperation({ sender: this.sender, nonce: 1 });
145138
const chainId = 0xdeadbeef;

0 commit comments

Comments
 (0)