-
Notifications
You must be signed in to change notification settings - Fork 161
feat: E2E gas profiling native and erc20 #122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
shamit05
wants to merge
5
commits into
coinbase:main
from
shamit05:shamit/e2e-gas-profiling-native-erc20
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| }, | ||
| "lib/webauthn-sol": { | ||
| "rev": "619f20ab0f074fef41066ee4ab24849a913263b2" | ||
| } | ||
| } |
Submodule forge-std
updated
55 files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,111 @@ | ||||||
| // SPDX-License-Identifier: MIT | ||||||
| pragma solidity ^0.8.4; | ||||||
|
|
||||||
| import {console2} from "forge-std/Test.sol"; | ||||||
| import {SmartWalletTestBase} from "../CoinbaseSmartWallet/SmartWalletTestBase.sol"; | ||||||
| import {CoinbaseSmartWallet} from "../../src/CoinbaseSmartWallet.sol"; | ||||||
| import {CoinbaseSmartWalletFactory} from "../../src/CoinbaseSmartWalletFactory.sol"; | ||||||
| import {MockTarget} from "../mocks/MockTarget.sol"; | ||||||
| import {UserOperation} from "account-abstraction/interfaces/UserOperation.sol"; | ||||||
| import {MockERC20} from "../../lib/solady/test/utils/mocks/MockERC20.sol"; | ||||||
| import {Static} from "../CoinbaseSmartWallet/Static.sol"; | ||||||
|
|
||||||
| /// forge-config: default.isolate = true | ||||||
| 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 { | ||||||
| // 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 { | ||||||
| // 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); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use fuzzing
Suggested change
|
||||||
| 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) { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not seeing where this is being used. Does the parent test contract require use to override this? |
||||||
| 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))); | ||||||
| } | ||||||
| } | ||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if using fuzzing from earlier comment