Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 78 additions & 76 deletions .gas-snapshot
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amiecorso did we update .gas-snapshot when pushing v1.1? Feels weird for the diff to be so big unless its fuzzing variance?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we did actually... See the file on the v1.1 commit here

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

differences could have to do with how things are compiled before snapshotting though... since control of that stuff is a mess

Original file line number Diff line number Diff line change
@@ -1,76 +1,78 @@
AddOwnerAddressTest:testEmitsAddOwner() (gas: 91954)
AddOwnerAddressTest:testIncreasesOwnerIndex() (gas: 90492)
AddOwnerAddressTest:testRevertsIfAlreadyOwner() (gas: 92327)
AddOwnerAddressTest:testRevertsIfCalledByNonOwner() (gas: 11831)
AddOwnerAddressTest:testSetsIsOwner() (gas: 90125)
AddOwnerAddressTest:testSetsOwnerAtIndex() (gas: 99961)
AddOwnerPublicKeyTest:testEmitsAddOwner() (gas: 115024)
AddOwnerPublicKeyTest:testFuzzIsOwnerPublicKey(bytes32,bytes32) (runs: 256, μ: 114454, ~: 114454)
AddOwnerPublicKeyTest:testRevertsIfAlreadyOwner() (gas: 115392)
AddOwnerPublicKeyTest:testRevertsIfCalledByNonOwner() (gas: 11895)
AddOwnerPublicKeyTest:testSetsIsOwner() (gas: 113193)
AddOwnerPublicKeyTest:testSetsOwnerAtIndex() (gas: 130925)
CoinbaseSmartWallet1271InputGeneratorTest:testGetReplaySafeHashForDeployedAccount() (gas: 311701)
CoinbaseSmartWallet1271InputGeneratorTest:testGetReplaySafeHashForUndeployedAccount() (gas: 293976)
CoinbaseSmartWalletFactoryTest:testDeployDeterministicPassValues() (gas: 270581)
CoinbaseSmartWalletFactoryTest:test_CreateAccount_ReturnsPredeterminedAddress_WhenAccountAlreadyExists() (gas: 289811)
CoinbaseSmartWalletFactoryTest:test_RevertsIfLength32ButLargerThanAddress() (gas: 303514)
CoinbaseSmartWalletFactoryTest:test_constructor_revertsIfImplementationIsNotDeployed(address) (runs: 256, μ: 39338, ~: 39348)
CoinbaseSmartWalletFactoryTest:test_constructor_setsImplementation(address) (runs: 256, μ: 455736, ~: 455736)
CoinbaseSmartWalletFactoryTest:test_createAccountDeploysToPredeterminedAddress() (gas: 271825)
CoinbaseSmartWalletFactoryTest:test_createAccountSetsOwnersCorrectly() (gas: 281476)
CoinbaseSmartWalletFactoryTest:test_createAccount_emitsAccountCreatedEvent(uint256) (runs: 256, μ: 273358, ~: 273358)
CoinbaseSmartWalletFactoryTest:test_exitIfAccountIsAlreadyInitialized() (gas: 271307)
CoinbaseSmartWalletFactoryTest:test_implementation_returnsExpectedAddress() (gas: 7698)
CoinbaseSmartWalletFactoryTest:test_initCodeHash() (gas: 7913)
CoinbaseSmartWalletFactoryTest:test_revertsIfNoOwners() (gas: 29256)
ERC1271Test:test_returnsExpectedDomainHashWhenProxy() (gas: 31630)
ERC1271Test:test_static() (gas: 4046108)
MultiOwnableInitializeTest:testRevertsIfLength32ButLargerThanAddress() (gas: 80861)
MultiOwnableInitializeTest:testRevertsIfLength32NotAddress() (gas: 81027)
MultiOwnableInitializeTest:testRevertsIfLengthNot32Or64() (gas: 103534)
RemoveLastOwnerTest:test_emitsRemoveOwner() (gas: 50105)
RemoveLastOwnerTest:test_removesOwner() (gas: 48993)
RemoveLastOwnerTest:test_removesOwnerAtIndex() (gas: 49127)
RemoveLastOwnerTest:test_revert_whenCalledByNonOwner(address) (runs: 256, μ: 19210, ~: 19210)
RemoveLastOwnerTest:test_revert_whenNoOwnerAtIndex() (gas: 48103)
RemoveLastOwnerTest:test_revert_whenWrongOwnerAtIndex() (gas: 34023)
RemoveLastOwnerTest:test_reverts_whenNotLastOwner() (gas: 123054)
RemoveOwnerAtIndexTest:test_emitsRemoveOwner() (gas: 55370)
RemoveOwnerAtIndexTest:test_removesOwner() (gas: 54324)
RemoveOwnerAtIndexTest:test_removesOwnerAtIndex() (gas: 54222)
RemoveOwnerAtIndexTest:test_revert_whenCalledByNonOwner(address) (runs: 256, μ: 19232, ~: 19232)
RemoveOwnerAtIndexTest:test_revert_whenNoOwnerAtIndex() (gas: 33098)
RemoveOwnerAtIndexTest:test_revert_whenWrongOwnerAtIndex() (gas: 36598)
RemoveOwnerAtIndexTest:test_reverts_ifIsLastOwner() (gas: 7632833)
TestCanSkipChainIdValidation:test_approvedSelectorsReturnTrue() (gas: 17685)
TestCanSkipChainIdValidation:test_otherSelectorsReturnFalse() (gas: 12561)
TestExecuteWithoutChainIdValidation:testExecute() (gas: 485146)
TestExecuteWithoutChainIdValidation:testExecuteBatch() (gas: 889868)
TestExecuteWithoutChainIdValidation:testExecuteBatch(uint256) (runs: 256, μ: 4544535, ~: 4457018)
TestExecuteWithoutChainIdValidation:test__codesize() (gas: 61710)
TestExecuteWithoutChainIdValidation:test_revertsWithReservedNonce() (gas: 81700)
TestExecuteWithoutChainIdValidation:test_reverts_whenCallerNotEntryPoint() (gas: 11148)
TestExecuteWithoutChainIdValidation:test_reverts_whenOneCallReverts() (gas: 467006)
TestExecuteWithoutChainIdValidation:test_reverts_whenOneSelectorNotApproved() (gas: 179933)
TestExecuteWithoutChainIdValidation:test_reverts_whenSelectorNotApproved() (gas: 106565)
TestExecuteWithoutChainIdValidation:test_succeeds_whenSelectorAllowed() (gas: 424623)
TestImplementation:testImplementation() (gas: 12677)
TestInitialize:testInitialize() (gas: 21146)
TestInitialize:test_cannotInitImplementation() (gas: 3676943)
TestIsValidSignature:testReturnsInvalidIfPasskeySigButWrongOwnerLength() (gas: 40556)
TestIsValidSignature:testRevertsIfEthereumSignatureButWrongOwnerLength() (gas: 24272)
TestIsValidSignature:testRevertsIfOwnerIsInvalidEthereumAddress() (gas: 22001)
TestIsValidSignature:testSmartWalletSigner() (gas: 3967929)
TestIsValidSignature:testValidateSignatureWithEOASigner() (gas: 25053)
TestIsValidSignature:testValidateSignatureWithEOASignerFailsWithWrongSigner() (gas: 23780)
TestIsValidSignature:testValidateSignatureWithPasskeySigner() (gas: 354806)
TestIsValidSignature:testValidateSignatureWithPasskeySignerFailsBadOwnerIndex() (gas: 35960)
TestIsValidSignature:testValidateSignatureWithPasskeySignerFailsWithWrongBadSignature() (gas: 345393)
TestUpgradeToAndCall:testUpgradeToAndCall() (gas: 25322)
TestValidateUserOp:test_reverts_whenReplayableNonceKeyInvalidForSelector() (gas: 14609)
TestValidateUserOp:test_reverts_whenSelectorInvalidForReplayableNonceKey() (gas: 14469)
TestValidateUserOp:test_reverts_whenUpgradeToImplementationWithNoCode(address) (runs: 256, μ: 23208, ~: 23228)
TestValidateUserOp:test_succeedsWithEOASigner() (gas: 456302)
TestValidateUserOp:test_succeedsWithPasskeySigner() (gas: 711409)
TestValidateUserOp:test_succeeds_whenUpgradeToImplementationWithCode() (gas: 3714211)
AddOwnerAddressTest:testEmitsAddOwner() (gas: 95829)
AddOwnerAddressTest:testIncreasesOwnerIndex() (gas: 93811)
AddOwnerAddressTest:testRevertsIfAlreadyOwner() (gas: 97900)
AddOwnerAddressTest:testRevertsIfCalledByNonOwner() (gas: 13315)
AddOwnerAddressTest:testSetsIsOwner() (gas: 94340)
AddOwnerAddressTest:testSetsOwnerAtIndex() (gas: 97345)
AddOwnerPublicKeyTest:testEmitsAddOwner() (gas: 119224)
AddOwnerPublicKeyTest:testFuzzIsOwnerPublicKey(bytes32,bytes32) (runs: 260, μ: 120409, ~: 120409)
AddOwnerPublicKeyTest:testRevertsIfAlreadyOwner() (gas: 121567)
AddOwnerPublicKeyTest:testRevertsIfCalledByNonOwner() (gas: 13468)
AddOwnerPublicKeyTest:testSetsIsOwner() (gas: 117612)
AddOwnerPublicKeyTest:testSetsOwnerAtIndex() (gas: 120856)
CoinbaseSmartWallet1271InputGeneratorTest:testGetReplaySafeHashForDeployedAccount() (gas: 321780)
CoinbaseSmartWallet1271InputGeneratorTest:testGetReplaySafeHashForUndeployedAccount() (gas: 306564)
CoinbaseSmartWalletFactoryTest:testDeployDeterministicPassValues() (gas: 278647)
CoinbaseSmartWalletFactoryTest:test_CreateAccount_ReturnsPredeterminedAddress_WhenAccountAlreadyExists() (gas: 302620)
CoinbaseSmartWalletFactoryTest:test_RevertsIfLength32ButLargerThanAddress() (gas: 312891)
CoinbaseSmartWalletFactoryTest:test_constructor_revertsIfImplementationIsNotDeployed(address) (runs: 260, μ: 40036, ~: 40046)
CoinbaseSmartWalletFactoryTest:test_constructor_setsImplementation(address) (runs: 260, μ: 548238, ~: 548238)
CoinbaseSmartWalletFactoryTest:test_createAccountDeploysToPredeterminedAddress() (gas: 281841)
CoinbaseSmartWalletFactoryTest:test_createAccountSetsOwnersCorrectly() (gas: 293368)
CoinbaseSmartWalletFactoryTest:test_createAccount_emitsAccountCreatedEvent(uint256) (runs: 260, μ: 284216, ~: 284216)
CoinbaseSmartWalletFactoryTest:test_exitIfAccountIsAlreadyInitialized() (gas: 282240)
CoinbaseSmartWalletFactoryTest:test_implementation_returnsExpectedAddress() (gas: 7992)
CoinbaseSmartWalletFactoryTest:test_initCodeHash() (gas: 8307)
CoinbaseSmartWalletFactoryTest:test_revertsIfNoOwners() (gas: 30019)
ERC1271Test:test_returnsExpectedDomainHashWhenProxy() (gas: 23618)
ERC1271Test:test_static() (gas: 5038825)
EndToEndTest:test_transfer_erc20() (gas: 462176)
EndToEndTest:test_transfer_native() (gas: 355253)
MultiOwnableInitializeTest:testRevertsIfLength32ButLargerThanAddress() (gas: 83336)
MultiOwnableInitializeTest:testRevertsIfLength32NotAddress() (gas: 83255)
MultiOwnableInitializeTest:testRevertsIfLengthNot32Or64() (gas: 105695)
RemoveLastOwnerTest:test_emitsRemoveOwner() (gas: 52621)
RemoveLastOwnerTest:test_removesOwner() (gas: 52383)
RemoveLastOwnerTest:test_removesOwnerAtIndex() (gas: 53221)
RemoveLastOwnerTest:test_revert_whenCalledByNonOwner(address) (runs: 260, μ: 20652, ~: 20652)
RemoveLastOwnerTest:test_revert_whenNoOwnerAtIndex() (gas: 50014)
RemoveLastOwnerTest:test_revert_whenWrongOwnerAtIndex() (gas: 37450)
RemoveLastOwnerTest:test_reverts_whenNotLastOwner() (gas: 127056)
RemoveOwnerAtIndexTest:test_emitsRemoveOwner() (gas: 57775)
RemoveOwnerAtIndexTest:test_removesOwner() (gas: 57349)
RemoveOwnerAtIndexTest:test_removesOwnerAtIndex() (gas: 57914)
RemoveOwnerAtIndexTest:test_revert_whenCalledByNonOwner(address) (runs: 260, μ: 20674, ~: 20674)
RemoveOwnerAtIndexTest:test_revert_whenNoOwnerAtIndex() (gas: 35018)
RemoveOwnerAtIndexTest:test_revert_whenWrongOwnerAtIndex() (gas: 40657)
RemoveOwnerAtIndexTest:test_reverts_ifIsLastOwner() (gas: 8529792)
TestCanSkipChainIdValidation:test_approvedSelectorsReturnTrue() (gas: 20637)
TestCanSkipChainIdValidation:test_otherSelectorsReturnFalse() (gas: 13631)
TestExecuteWithoutChainIdValidation:testExecute() (gas: 587208)
TestExecuteWithoutChainIdValidation:testExecuteBatch() (gas: 1087434)
TestExecuteWithoutChainIdValidation:testExecuteBatch(uint256) (runs: 260, μ: 5622658, ~: 5415134)
TestExecuteWithoutChainIdValidation:test__codesize() (gas: 65702)
TestExecuteWithoutChainIdValidation:test_revertsWithReservedNonce() (gas: 87228)
TestExecuteWithoutChainIdValidation:test_reverts_whenCallerNotEntryPoint() (gas: 11407)
TestExecuteWithoutChainIdValidation:test_reverts_whenOneCallReverts() (gas: 475054)
TestExecuteWithoutChainIdValidation:test_reverts_whenOneSelectorNotApproved() (gas: 183931)
TestExecuteWithoutChainIdValidation:test_reverts_whenSelectorNotApproved() (gas: 108819)
TestExecuteWithoutChainIdValidation:test_succeeds_whenSelectorAllowed() (gas: 440590)
TestImplementation:testImplementation() (gas: 12896)
TestInitialize:testInitialize() (gas: 22939)
TestInitialize:test_cannotInitImplementation() (gas: 4597308)
TestIsValidSignature:testReturnsInvalidIfPasskeySigButWrongOwnerLength() (gas: 50912)
TestIsValidSignature:testRevertsIfEthereumSignatureButWrongOwnerLength() (gas: 29788)
TestIsValidSignature:testRevertsIfOwnerIsInvalidEthereumAddress() (gas: 29384)
TestIsValidSignature:testSmartWalletSigner() (gas: 4950306)
TestIsValidSignature:testValidateSignatureWithEOASigner() (gas: 30653)
TestIsValidSignature:testValidateSignatureWithEOASignerFailsWithWrongSigner() (gas: 27974)
TestIsValidSignature:testValidateSignatureWithPasskeySigner() (gas: 275434)
TestIsValidSignature:testValidateSignatureWithPasskeySignerFailsBadOwnerIndex() (gas: 46521)
TestIsValidSignature:testValidateSignatureWithPasskeySignerFailsWithWrongBadSignature() (gas: 270588)
TestUpgradeToAndCall:testUpgradeToAndCall() (gas: 26537)
TestValidateUserOp:test_reverts_whenReplayableNonceKeyInvalidForSelector() (gas: 17983)
TestValidateUserOp:test_reverts_whenSelectorInvalidForReplayableNonceKey() (gas: 19057)
TestValidateUserOp:test_reverts_whenUpgradeToImplementationWithNoCode(address) (runs: 260, μ: 30315, ~: 30315)
TestValidateUserOp:test_succeedsWithEOASigner() (gas: 687856)
TestValidateUserOp:test_succeedsWithPasskeySigner() (gas: 854583)
TestValidateUserOp:test_succeeds_whenUpgradeToImplementationWithCode() (gas: 4688457)
26 changes: 26 additions & 0 deletions foundry.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"lib/account-abstraction": {
"rev": "abff2aca61a8f0934e533d0d352978055fddbd96"
},
"lib/forge-std": {
"tag": {
"name": "v1.10.0",
"rev": "8bbcf6e3f8f62f419e5429a0bd89331c85c37824"
}
},
"lib/openzeppelin-contracts": {
"rev": "5705e8208bc92cd82c7bcdfeac8dbc7377767d96"
},
"lib/p256-verifier": {
"rev": "29475ae300ec95d98d5c7cc34c094846f0aa2dcd"
},
"lib/safe-singleton-deployer-sol": {
"rev": "cf2b89c33fed536c4dd6fef2fb84f39053068868"
},
"lib/solady": {
"rev": "c4c96607cb3aa3807b14c81ae2015bcba061f8fc"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this is a commit, we actually want this to be 5ea5d9f57ed6d24a27d00934f4a3448def931415

},
"lib/webauthn-sol": {
"rev": "619f20ab0f074fef41066ee4ab24849a913263b2"
}
}
2 changes: 1 addition & 1 deletion lib/forge-std
Submodule forge-std updated 55 files
+1 −0 .github/CODEOWNERS
+57 −109 .github/workflows/ci.yml
+3 −1 .github/workflows/sync.yml
+0 −3 .gitmodules
+193 −0 CONTRIBUTING.md
+21 −5 README.md
+5 −3 foundry.toml
+0 −1 lib/ds-test
+1 −1 package.json
+13 −2 scripts/vm.py
+16 −9 src/Base.sol
+1 −0 src/Script.sol
+590 −202 src/StdAssertions.sol
+49 −11 src/StdChains.sol
+17 −5 src/StdCheats.sol
+30 −0 src/StdConstants.sol
+18 −3 src/StdInvariant.sol
+111 −11 src/StdJson.sol
+202 −107 src/StdStorage.sol
+283 −0 src/StdToml.sol
+1 −19 src/StdUtils.sol
+5 −4 src/Test.sol
+1,416 −62 src/Vm.sol
+635 −608 src/console.sol
+1 −1,555 src/console2.sol
+1 −1 src/interfaces/IERC1155.sol
+3 −3 src/interfaces/IERC4626.sol
+72 −0 src/interfaces/IERC6909.sol
+1 −1 src/interfaces/IERC721.sol
+150 −0 src/interfaces/IERC7540.sol
+241 −0 src/interfaces/IERC7575.sol
+0 −216 src/mocks/MockERC20.sol
+0 −221 src/mocks/MockERC721.sol
+693 −4 src/safeconsole.sol
+44 −0 test/CommonBase.t.sol
+35 −909 test/StdAssertions.t.sol
+55 −44 test/StdChains.t.sol
+66 −37 test/StdCheats.t.sol
+38 −0 test/StdConstants.t.sol
+12 −12 test/StdError.t.sol
+49 −0 test/StdJson.t.sol
+12 −22 test/StdMath.t.sol
+190 −17 test/StdStorage.t.sol
+1 −1 test/StdStyle.t.sol
+49 −0 test/StdToml.t.sol
+26 −26 test/StdUtils.t.sol
+9 −6 test/Vm.t.sol
+1 −1 test/compilation/CompilationScript.sol
+1 −1 test/compilation/CompilationScriptBase.sol
+1 −1 test/compilation/CompilationTest.sol
+1 −1 test/compilation/CompilationTestBase.sol
+8 −0 test/fixtures/test.json
+6 −0 test/fixtures/test.toml
+0 −441 test/mocks/MockERC20.t.sol
+0 −721 test/mocks/MockERC721.t.sol
6 changes: 6 additions & 0 deletions snapshots/EndToEndTest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"e2e_transfer_erc20_baseAccount": "159402",
"e2e_transfer_erc20_eoa": "50910",
"e2e_transfer_native_baseAccount": "134635",
"e2e_transfer_native_eoa": "17652"
}
111 changes: 111 additions & 0 deletions test/gas/EndToEnd.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make at parity with codebase so ^0.8.23


import {MockERC20} from "../../lib/solady/test/utils/mocks/MockERC20.sol";
import {CoinbaseSmartWallet} from "../../src/CoinbaseSmartWallet.sol";
import {CoinbaseSmartWalletFactory} from "../../src/CoinbaseSmartWalletFactory.sol";
import {SmartWalletTestBase} from "../CoinbaseSmartWallet/SmartWalletTestBase.sol";

import {Static} from "../CoinbaseSmartWallet/Static.sol";
import {MockTarget} from "../mocks/MockTarget.sol";
import {UserOperation} from "account-abstraction/interfaces/UserOperation.sol";
import {console2} from "forge-std/Test.sol";

/// forge-config: default.isolate = true
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this do?

contract EndToEndTest is SmartWalletTestBase {
address eoaUser = address(0xe0a);

MockERC20 usdc;
MockTarget target;
CoinbaseSmartWalletFactory factory;

function setUp() public override {
vm.etch(0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789, Static.ENTRY_POINT_BYTES);

CoinbaseSmartWallet implementation = new CoinbaseSmartWallet();
factory = new CoinbaseSmartWalletFactory(address(implementation));

signerPrivateKey = 0xa11ce;
signer = vm.addr(signerPrivateKey);
owners.push(abi.encode(signer));
account = factory.createAccount(owners, 0);

vm.deal(address(account), 100 ether);
vm.deal(eoaUser, 100 ether);

usdc = new MockERC20("USD Coin", "USDC", 6);
usdc.mint(address(account), 10000e6);
usdc.mint(eoaUser, 10000e6);

target = new MockTarget();
}

// Native ETH transfer comparison between ERC-4337 and EOA
function test_transfer_native() public {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would benefit from comments to annotate the code sections here for easier skimming

// Dust recipient to control for gas increase for first non-zero balance
vm.deal(address(0x1234), 1 wei);
usdc.mint(eoaUser, 1 wei);

userOpCalldata = abi.encodeCall(CoinbaseSmartWallet.execute, (address(0x1234), 1 ether, ""));
UserOperation memory op = _getUserOpWithSignature();

bytes memory handleOpsCalldata = abi.encodeCall(entryPoint.handleOps, (_makeOpsArray(op), payable(bundler)));
console2.log("test_transfer_native Base Account calldata size:", handleOpsCalldata.length);

vm.startSnapshotGas("e2e_transfer_native_baseAccount");
_sendUserOperation(op);
uint256 gas4337 = vm.stopSnapshotGas();
console2.log("test_transfer_native Base Account gas:", gas4337);

console2.log("test_transfer_native EOA calldata size:", uint256(0));

vm.prank(eoaUser);
vm.startSnapshotGas("e2e_transfer_native_eoa");
payable(address(0x1234)).transfer(1 ether);
uint256 gasEOA = vm.stopSnapshotGas();
console2.log("test_transfer_native EOA gas:", gasEOA);
console2.log("Gas overhead (4337 Base Account / EOA):", (gas4337 * 100) / gasEOA, "%");
}

// ERC20 transfer comparison between ERC-4337 and EOA
function test_transfer_erc20() public {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the https://github.com/coinbase/solidity-style-guide there's a preference for tests only testing one thing. not necessarily a blocker here especially since these are just benchmarks, but if I were to write this I would split it out into the 4 explicit cases of native/erc20, scw/eoa for better org and readability.

// Dust recipient to control for gas increase for first non-zero balance
vm.deal(address(0x5678), 1 wei);
usdc.mint(eoaUser, 1 wei);

userOpCalldata = abi.encodeCall(
CoinbaseSmartWallet.execute, (address(usdc), 0, abi.encodeCall(usdc.transfer, (address(0x5678), 100e6)))
);
UserOperation memory op = _getUserOpWithSignature();

bytes memory handleOpsCalldata = abi.encodeCall(entryPoint.handleOps, (_makeOpsArray(op), payable(bundler)));
console2.log("test_transfer_erc20 Base Account calldata size:", handleOpsCalldata.length);

vm.startSnapshotGas("e2e_transfer_erc20_baseAccount");
_sendUserOperation(op);
uint256 gas4337 = vm.stopSnapshotGas();
console2.log("test_transfer_erc20 Base Account gas:", gas4337);

bytes memory eoaCalldata = abi.encodeCall(usdc.transfer, (address(0x5678), 100e6));
console2.log("test_transfer_erc20 EOA calldata size:", eoaCalldata.length);

vm.prank(eoaUser);
vm.startSnapshotGas("e2e_transfer_erc20_eoa");
usdc.transfer(address(0x5678), 100e6);
uint256 gasEOA = vm.stopSnapshotGas();
console2.log("test_transfer_erc20 EOA gas:", gasEOA);
console2.log("Gas overhead (4337 Base Account / EOA):", (gas4337 * 100) / gasEOA, "%");
}

function _makeOpsArray(UserOperation memory op) internal pure returns (UserOperation[] memory) {
UserOperation[] memory ops = new UserOperation[](1);
ops[0] = op;
return ops;
}

function _sign(UserOperation memory userOp) internal view override returns (bytes memory signature) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should already be available on the SmartWalletTestBase parent contract so I don't think we need to re-write here?

bytes32 toSign = entryPoint.getUserOpHash(userOp);
(uint8 v, bytes32 r, bytes32 s) = vm.sign(signerPrivateKey, toSign);
signature = abi.encode(CoinbaseSmartWallet.SignatureWrapper(0, abi.encodePacked(r, s, v)));
}
}
Loading