Skip to content

Commit

Permalink
Merge pull request #58 from coinbase/wilson/bytes4
Browse files Browse the repository at this point in the history
Optimize getting function selector
  • Loading branch information
wilsoncusack authored Apr 19, 2024
2 parents 89eb5a6 + 3b686e6 commit 29b8235
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
30 changes: 15 additions & 15 deletions .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ CoinbaseSmartWalletFactoryTest:test_implementation_returnsExpectedAddress() (gas
CoinbaseSmartWalletFactoryTest:test_initCodeHash() (gas: 7912)
CoinbaseSmartWalletFactoryTest:test_revertsIfNoOwners() (gas: 29232)
ERC1271Test:test_returnsExpectedDomainHashWhenProxy() (gas: 29198)
ERC1271Test:test_static() (gas: 3249331)
ERC1271Test:test_static() (gas: 3229650)
MultiOwnableInitializeTest:testRevertsIfLength32ButLargerThanAddress() (gas: 81111)
MultiOwnableInitializeTest:testRevertsIfLength32NotAddress() (gas: 81092)
MultiOwnableInitializeTest:testRevertsIfLengthNot32Or64() (gas: 103395)
Expand All @@ -45,29 +45,29 @@ TestCanSkipChainIdValidation:test_approvedSelectorsReturnTrue() (gas: 17781)
TestCanSkipChainIdValidation:test_otherSelectorsReturnFalse() (gas: 12579)
TestExecuteWithoutChainIdValidation:testExecute() (gas: 424837)
TestExecuteWithoutChainIdValidation:testExecuteBatch() (gas: 728897)
TestExecuteWithoutChainIdValidation:testExecuteBatch(uint256) (runs: 256, μ: 3631749, ~: 3655292)
TestExecuteWithoutChainIdValidation:test__codesize() (gas: 49987)
TestExecuteWithoutChainIdValidation:test__codesize() (gas: 50222)
TestExecuteWithoutChainIdValidation:test_revertsWithReservedNonce() (gas: 82347)
TestExecuteWithoutChainIdValidation:testExecuteBatch(uint256) (runs: 256, μ: 3597261, ~: 3458766)
TestExecuteWithoutChainIdValidation:test__codesize() (gas: 49890)
TestExecuteWithoutChainIdValidation:test__codesize() (gas: 50125)
TestExecuteWithoutChainIdValidation:test_revertsWithReservedNonce() (gas: 81983)
TestExecuteWithoutChainIdValidation:test_reverts_whenCallerNotEntryPoint() (gas: 11053)
TestExecuteWithoutChainIdValidation:test_reverts_whenOneCallReverts() (gas: 467957)
TestExecuteWithoutChainIdValidation:test_reverts_whenOneSelectorNotApproved() (gas: 179805)
TestExecuteWithoutChainIdValidation:test_reverts_whenSelectorNotApproved() (gas: 106879)
TestExecuteWithoutChainIdValidation:test_succeeds_whenSelectorAllowed() (gas: 424401)
TestExecuteWithoutChainIdValidation:test_reverts_whenOneCallReverts() (gas: 467715)
TestExecuteWithoutChainIdValidation:test_reverts_whenOneSelectorNotApproved() (gas: 179684)
TestExecuteWithoutChainIdValidation:test_reverts_whenSelectorNotApproved() (gas: 106758)
TestExecuteWithoutChainIdValidation:test_succeeds_whenSelectorAllowed() (gas: 423916)
TestImplementation:testImplementation() (gas: 12623)
TestInitialize:testInitialize() (gas: 21034)
TestInitialize:test_cannotInitImplementation() (gas: 2904513)
TestInitialize:test_cannotInitImplementation() (gas: 2885066)
TestIsValidSignature:testReturnsInvalidIfPasskeySigButWrongOwnerLength() (gas: 40187)
TestIsValidSignature:testRevertsIfEthereumSignatureButWrongOwnerLength() (gas: 24040)
TestIsValidSignature:testRevertsIfOwnerIsInvalidEthereumAddress() (gas: 22021)
TestIsValidSignature:testSmartWalletSigner() (gas: 3180147)
TestIsValidSignature:testSmartWalletSigner() (gas: 3160701)
TestIsValidSignature:testValidateSignatureWithEOASigner() (gas: 24922)
TestIsValidSignature:testValidateSignatureWithEOASignerFailsWithWrongSigner() (gas: 23877)
TestIsValidSignature:testValidateSignatureWithPasskeySigner() (gas: 423238)
TestIsValidSignature:testValidateSignatureWithPasskeySignerFailsBadOwnerIndex() (gas: 35664)
TestIsValidSignature:testValidateSignatureWithPasskeySignerFailsWithWrongBadSignature() (gas: 430704)
TestUpgradeToAndCall:testUpgradeToAndCall() (gas: 25477)
TestValidateUserOp:test_reverts_whenReplayableNonceKeyInvalidForSelector() (gas: 14551)
TestValidateUserOp:test_reverts_whenSelectorInvalidForReplayableNonceKey() (gas: 14816)
TestValidateUserOp:test_succeedsWithEOASigner() (gas: 447664)
TestValidateUserOp:test_succeedsWithPasskeySigner() (gas: 785032)
TestValidateUserOp:test_reverts_whenReplayableNonceKeyInvalidForSelector() (gas: 14187)
TestValidateUserOp:test_reverts_whenSelectorInvalidForReplayableNonceKey() (gas: 14452)
TestValidateUserOp:test_succeedsWithEOASigner() (gas: 447938)
TestValidateUserOp:test_succeedsWithPasskeySigner() (gas: 785169)
6 changes: 2 additions & 4 deletions src/CoinbaseSmartWallet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,7 @@ contract CoinbaseSmartWallet is MultiOwnable, UUPSUpgradeable, Receiver, ERC1271
{
uint256 key = userOp.nonce >> 64;

if (
userOp.callData.length >= 4 && bytes4(userOp.callData[0:4]) == this.executeWithoutChainIdValidation.selector
) {
if (bytes4(userOp.callData) == this.executeWithoutChainIdValidation.selector) {
userOpHash = getUserOpHashWithoutChainId(userOp);
if (key != REPLAYABLE_NONCE_KEY) {
revert InvalidNonceKey(key);
Expand Down Expand Up @@ -181,7 +179,7 @@ contract CoinbaseSmartWallet is MultiOwnable, UUPSUpgradeable, Receiver, ERC1271
function executeWithoutChainIdValidation(bytes[] calldata calls) public payable virtual onlyEntryPoint {
for (uint256 i; i < calls.length; i++) {
bytes calldata call = calls[i];
bytes4 selector = bytes4(call[0:4]);
bytes4 selector = bytes4(call);
if (!canSkipChainIdValidation(selector)) {
revert SelectorNotAllowed(selector);
}
Expand Down

0 comments on commit 29b8235

Please sign in to comment.