From 34f7cdc293f5057b99dca85d2b2ab17ce0a0ed9d Mon Sep 17 00:00:00 2001 From: Wilson Cusack Date: Wed, 13 Mar 2024 11:32:33 -0400 Subject: [PATCH] use immutable for entryPoint in SmartWallet --- .gas-snapshot | 26 +++++++++---------- src/CoinbaseSmartWallet.sol | 16 +++++------- .../ExecuteWithoutChainIdValidation.t.sol | 2 +- 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/.gas-snapshot b/.gas-snapshot index 3d2fd21..682faf8 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -29,25 +29,25 @@ RemoveOwnerAtIndexTest:testRevertsIfCalledByNonOwner() (gas: 11308) RemoveOwnerAtIndexTest:testRevertsIfNoOwnerAtIndex() (gas: 16624) TestCanSkipChainIdValidation:test_approvedSelectorsReturnTrue() (gas: 15933) TestCanSkipChainIdValidation:test_otherSelectorsReturnFalse() (gas: 12513) -TestExecuteWithoutChainIdValidation:testExecute() (gas: 424907) -TestExecuteWithoutChainIdValidation:testExecuteBatch() (gas: 729143) -TestExecuteWithoutChainIdValidation:testExecuteBatch(uint256) (runs: 256, μ: 3450733, ~: 3582947) -TestExecuteWithoutChainIdValidation:test__codesize() (gas: 49053) -TestExecuteWithoutChainIdValidation:test__codesize() (gas: 49288) -TestExecuteWithoutChainIdValidation:test_canChangeOwnerWithoutChainId() (gas: 287727) -TestExecuteWithoutChainIdValidation:test_cannotCallExec() (gas: 220025) -TestExecuteWithoutChainIdValidation:test_revertsIfCallerNotEntryPoint() (gas: 8598) -TestExecuteWithoutChainIdValidation:test_revertsIfWrongNonceKey() (gas: 62275) -TestExecuteWithoutChainIdValidation:test_revertsWithReservedNonce() (gas: 82324) +TestExecuteWithoutChainIdValidation:testExecute() (gas: 424961) +TestExecuteWithoutChainIdValidation:testExecuteBatch() (gas: 729179) +TestExecuteWithoutChainIdValidation:testExecuteBatch(uint256) (runs: 256, μ: 3464532, ~: 3316512) +TestExecuteWithoutChainIdValidation:test__codesize() (gas: 49268) +TestExecuteWithoutChainIdValidation:test__codesize() (gas: 49503) +TestExecuteWithoutChainIdValidation:test_canChangeOwnerWithoutChainId() (gas: 287799) +TestExecuteWithoutChainIdValidation:test_cannotCallExec() (gas: 220097) +TestExecuteWithoutChainIdValidation:test_revertsIfCallerNotEntryPoint() (gas: 8616) +TestExecuteWithoutChainIdValidation:test_revertsIfWrongNonceKey() (gas: 62329) +TestExecuteWithoutChainIdValidation:test_revertsWithReservedNonce() (gas: 82342) TestInitialize:testInitialize() (gas: 21034) -TestInitialize:test_cannotInitImplementation() (gas: 2714468) +TestInitialize:test_cannotInitImplementation() (gas: 2738240) TestIsValidSignature:testReturnsInvalidIfPasskeySigButWrongOwnerLength() (gas: 39469) TestIsValidSignature:testRevertsIfEthereumSignatureButWrongOwnerLength() (gas: 24040) -TestIsValidSignature:testSmartWalletSigner() (gas: 2990421) +TestIsValidSignature:testSmartWalletSigner() (gas: 3018423) TestIsValidSignature:testValidateSignatureWithEOASigner() (gas: 24922) TestIsValidSignature:testValidateSignatureWithEOASignerFailsWithWrongSigner() (gas: 23877) TestIsValidSignature:testValidateSignatureWithPasskeySigner() (gas: 421256) TestIsValidSignature:testValidateSignatureWithPasskeySignerFailsBadOwnerIndex() (gas: 34958) TestIsValidSignature:testValidateSignatureWithPasskeySignerFailsWithWrongBadSignature() (gas: 428722) TestUpgradeToAndCall:testUpgradeToAndCall() (gas: 25477) -TestValidateUserOp:testValidateUserOp() (gas: 447275) \ No newline at end of file +TestValidateUserOp:testValidateUserOp() (gas: 447335) \ No newline at end of file diff --git a/src/CoinbaseSmartWallet.sol b/src/CoinbaseSmartWallet.sol index 0c48b44..1519b76 100644 --- a/src/CoinbaseSmartWallet.sol +++ b/src/CoinbaseSmartWallet.sol @@ -63,7 +63,7 @@ contract CoinbaseSmartWallet is MultiOwnable, UUPSUpgradeable, Receiver, ERC1271 /// @notice Reverts if the caller is not the EntryPoint. modifier onlyEntryPoint() virtual { - if (msg.sender != entryPoint()) { + if (msg.sender != entryPoint) { revert Unauthorized(); } @@ -72,7 +72,7 @@ contract CoinbaseSmartWallet is MultiOwnable, UUPSUpgradeable, Receiver, ERC1271 /// @notice Reverts if the caller is neither the EntryPoint, the owner, nor the account itself. modifier onlyEntryPointOrOwner() virtual { - if (msg.sender != entryPoint()) { + if (msg.sender != entryPoint) { _checkOwner(); } @@ -99,6 +99,9 @@ contract CoinbaseSmartWallet is MultiOwnable, UUPSUpgradeable, Receiver, ERC1271 } } + /// @notice The address of the v0.6 EntryPoint contract. + address public immutable entryPoint = 0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789; + constructor() { // Implementation should not be initializable (does not affect proxies which use their own storage). bytes[] memory owners = new bytes[](1); @@ -211,13 +214,6 @@ contract CoinbaseSmartWallet is MultiOwnable, UUPSUpgradeable, Receiver, ERC1271 } } - /// @notice Returns the address of the EntryPoint v0.6. - /// - /// @return The address of the EntryPoint v0.6 - function entryPoint() public view virtual returns (address) { - return 0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789; - } - /// @notice Computes the hash of the `UserOperation` in the same way as EntryPoint v0.6, but /// leaves out the chain ID. /// @@ -232,7 +228,7 @@ contract CoinbaseSmartWallet is MultiOwnable, UUPSUpgradeable, Receiver, ERC1271 virtual returns (bytes32 userOpHash) { - return keccak256(abi.encode(UserOperationLib.hash(userOp), entryPoint())); + return keccak256(abi.encode(UserOperationLib.hash(userOp), entryPoint)); } /// @notice Returns the implementation of the ERC1967 proxy. diff --git a/test/CoinbaseSmartWallet/ExecuteWithoutChainIdValidation.t.sol b/test/CoinbaseSmartWallet/ExecuteWithoutChainIdValidation.t.sol index e92e83a..941ab44 100644 --- a/test/CoinbaseSmartWallet/ExecuteWithoutChainIdValidation.t.sol +++ b/test/CoinbaseSmartWallet/ExecuteWithoutChainIdValidation.t.sol @@ -42,7 +42,7 @@ contract TestExecuteWithoutChainIdValidation is SmartWalletTestBase { UserOperation memory userOp = _getUserOpWithSignature(); vm.expectEmit(true, true, true, true); emit IEntryPoint.UserOperationEvent( - entryPoint.getUserOpHash(userOp), userOp.sender, address(0), userOp.nonce, false, 0, 48005 + entryPoint.getUserOpHash(userOp), userOp.sender, address(0), userOp.nonce, false, 0, 48059 ); _sendUserOperation(userOp); }