Skip to content

Commit 1489ddc

Browse files
authored
♻️ Tidy ERC4337 (ethereum#650)
1 parent bcf187d commit 1489ddc

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

.gas-snapshot

+8-8
Original file line numberDiff line numberDiff line change
@@ -221,27 +221,27 @@ ERC2981Test:testRoyaltyOverflowCheckDifferential(uint256,uint256) (runs: 256, μ
221221
ERC2981Test:testSetAndGetRoyaltyInfo(uint256) (runs: 256, μ: 107629, ~: 104801)
222222
ERC2981Test:test__codesize() (gas: 8419)
223223
ERC4337FactoryTest:testDeploy() (gas: 112614)
224-
ERC4337FactoryTest:testDeploy(uint256) (runs: 256, μ: 135781, ~: 135781)
225-
ERC4337FactoryTest:testDeployDeterministic(uint256) (runs: 256, μ: 132993, ~: 137165)
224+
ERC4337FactoryTest:testDeploy(uint256) (runs: 256, μ: 135780, ~: 135781)
225+
ERC4337FactoryTest:testDeployDeterministic(uint256) (runs: 256, μ: 132593, ~: 137159)
226226
ERC4337FactoryTest:testDeployDeterministicRevertWithDeploymentFailed() (gas: 96883638)
227-
ERC4337FactoryTest:test__codesize() (gas: 11354)
227+
ERC4337FactoryTest:test__codesize() (gas: 11343)
228228
ERC4337Test:testDelegateExecute() (gas: 370417)
229-
ERC4337Test:testDelegateExecute(uint256) (runs: 256, μ: 354765, ~: 343995)
229+
ERC4337Test:testDelegateExecute(uint256) (runs: 256, μ: 353981, ~: 343995)
230230
ERC4337Test:testDelegateExecuteRevertsIfOwnerSlotValueChanged() (gas: 318832)
231-
ERC4337Test:testDepositFunctions() (gas: 502796)
231+
ERC4337Test:testDepositFunctions() (gas: 502811)
232232
ERC4337Test:testDirectStorage() (gas: 70943)
233233
ERC4337Test:testETHReceived() (gas: 16606)
234234
ERC4337Test:testExecute() (gas: 382275)
235-
ERC4337Test:testExecuteBatch() (gas: 691383)
236-
ERC4337Test:testExecuteBatch(uint256) (runs: 256, μ: 530520, ~: 571824)
235+
ERC4337Test:testExecuteBatch() (gas: 691377)
236+
ERC4337Test:testExecuteBatch(uint256) (runs: 256, μ: 532071, ~: 367759)
237237
ERC4337Test:testInitializer() (gas: 285354)
238238
ERC4337Test:testIsValidSignature() (gas: 66115)
239239
ERC4337Test:testIsValidSignatureWrapped() (gas: 388471)
240240
ERC4337Test:testOnERC1155BatchReceived() (gas: 1393612)
241241
ERC4337Test:testOnERC1155Received() (gas: 1390956)
242242
ERC4337Test:testOnERC721Received() (gas: 1311297)
243243
ERC4337Test:testValidateUserOp() (gas: 491252)
244-
ERC4337Test:test__codesize() (gas: 44409)
244+
ERC4337Test:test__codesize() (gas: 44398)
245245
ERC4626Test:testDepositWithNoApprovalReverts() (gas: 16371)
246246
ERC4626Test:testDepositWithNotEnoughApprovalReverts() (gas: 89884)
247247
ERC4626Test:testDifferentialFullMulDiv(uint256,uint256,uint256) (runs: 256, μ: 3336, ~: 3201)

src/accounts/ERC4337.sol

+13-12
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ import {SignatureCheckerLib} from "../utils/SignatureCheckerLib.sol";
1313
///
1414
/// Recommended usage:
1515
/// 1. Deploy the ERC4337 as an implementation contract, and verify it on Etherscan.
16-
/// 2. Create a simple factory that uses `LibClone.deployERC1967` or
16+
/// 2. Create a factory that uses `LibClone.deployERC1967` or
1717
/// `LibClone.deployDeterministicERC1967` to clone the implementation.
18+
/// See: `ERC4337Factory.sol`.
1819
contract ERC4337 is Ownable, UUPSUpgradeable, Receiver {
1920
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
2021
/* STRUCTS */
@@ -89,8 +90,8 @@ contract ERC4337 is Ownable, UUPSUpgradeable, Receiver {
8990
_validateNonce(userOp.nonce);
9091
}
9192

92-
/// @dev Validates the signature with ERC1271 return.
93-
/// So this account can also be used as a signer.
93+
/// @dev Validates the signature with ERC1271 return,
94+
/// so that this account can also be used as a signer.
9495
function isValidSignature(bytes32 hash, bytes calldata signature)
9596
public
9697
view
@@ -220,14 +221,15 @@ contract ERC4337 is Ownable, UUPSUpgradeable, Receiver {
220221
}
221222
mstore(r, m) // Append `m` into `results`.
222223
mstore(m, returndatasize()) // Store the length,
223-
returndatacopy(add(m, 0x20), 0x00, returndatasize()) // and copy the returndata.
224-
m := add(add(m, 0x20), returndatasize()) // Advance `m`.
224+
let p := add(m, 0x20)
225+
returndatacopy(p, 0x00, returndatasize()) // and copy the returndata.
226+
m := add(p, returndatasize()) // Advance `m`.
225227
}
226228
mstore(0x40, m) // Allocate the memory.
227229
}
228230
}
229231

230-
/// @dev Executes a delegatecall with `delegate` on this account.
232+
/// @dev Execute a delegatecall with `delegate` on this account.
231233
function delegateExecute(address delegate, bytes calldata data)
232234
public
233235
payable
@@ -238,9 +240,9 @@ contract ERC4337 is Ownable, UUPSUpgradeable, Receiver {
238240
{
239241
/// @solidity memory-safe-assembly
240242
assembly {
241-
// Forwards the `data` to `delegate` via delegatecall.
242243
result := mload(0x40)
243244
calldatacopy(result, data.offset, data.length)
245+
// Forwards the `data` to `delegate` via delegatecall.
244246
if iszero(delegatecall(gas(), delegate, result, data.length, codesize(), 0x00)) {
245247
// Bubble up the revert if the call reverts.
246248
returndatacopy(result, 0x00, returndatasize())
@@ -253,8 +255,7 @@ contract ERC4337 is Ownable, UUPSUpgradeable, Receiver {
253255
}
254256
}
255257

256-
/// @dev Guard to ensure that the owner slot's and implementation slot's values
257-
/// aren't changed by the function.
258+
/// @dev Ensures that the owner and implementation slots' values aren't changed.
258259
/// You can override this modifier to ensure the sanctity of other storage slots too.
259260
modifier storageGuard() virtual {
260261
bytes32 ownerSlotValue = _ownerSlotValue();
@@ -305,14 +306,14 @@ contract ERC4337 is Ownable, UUPSUpgradeable, Receiver {
305306
address ep = entryPoint();
306307
/// @solidity memory-safe-assembly
307308
assembly {
308-
mstore(0x14, address()) // Store the `account` argument.
309-
mstore(0x00, 0x70a08231000000000000000000000000) // `balanceOf(address)`.
309+
mstore(0x20, address()) // Store the `account` argument.
310+
mstore(0x00, 0x70a08231) // `balanceOf(address)`.
310311
result :=
311312
mul( // Returns 0 if the EntryPoint does not exist.
312313
mload(0x20),
313314
and( // The arguments of `and` are evaluated from right to left.
314315
gt(returndatasize(), 0x1f), // At least 32 bytes returned.
315-
staticcall(gas(), ep, 0x10, 0x24, 0x20, 0x20)
316+
staticcall(gas(), ep, 0x1c, 0x24, 0x20, 0x20)
316317
)
317318
)
318319
}

0 commit comments

Comments
 (0)