Skip to content

feat: E2E gas profiling native and erc20#122

Closed
shamit05 wants to merge 5 commits intocoinbase:mainfrom
shamit05:shamit/e2e-gas-profiling-native-erc20
Closed

feat: E2E gas profiling native and erc20#122
shamit05 wants to merge 5 commits intocoinbase:mainfrom
shamit05:shamit/e2e-gas-profiling-native-erc20

Conversation

@shamit05
Copy link
Copy Markdown
Contributor

@shamit05 shamit05 commented Sep 5, 2025

Gas profiling done for native and erc20 transfers. Results in snapshot folder.
https://docs.google.com/document/d/1G-ReRP_SQ4SvbHSjytj_ubdRwXTTMTdlwPAYSyr7LF4/edit?tab=t.0

@cb-heimdall
Copy link
Copy Markdown
Collaborator

cb-heimdall commented Sep 5, 2025

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 1
Sum 2

@shamit05
Copy link
Copy Markdown
Contributor Author

shamit05 commented Sep 5, 2025

Addressing this previous comment:

does _getUserOpWithSignature use userOpCalldata as calldata for the op?

Yes, it does since it calls internal _getUserOp which uses userOpCalldata.

Copy link
Copy Markdown
Contributor

@ilikesymmetry ilikesymmetry left a comment

Choose a reason for hiding this comment

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

Good pass, handful of comments on cleaning up the conventions

Comment on lines +43 to +44
function test_transfer_native() public {
userOpCalldata = abi.encodeCall(CoinbaseSmartWallet.execute, (address(0x1234), 1 ether, ""));
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.

Recommend fuzzing in general which can remove hardcoded values.

Also there's an increased cost when updating the storage for a users balance from zero to nonzero so we can cover for that by dusting the address first.

Suggested change
function test_transfer_native() public {
userOpCalldata = abi.encodeCall(CoinbaseSmartWallet.execute, (address(0x1234), 1 ether, ""));
function test_transfer_native(address recipient, uint256 amount) public {
vm.assume(amount < 1 ether);
// Dust recipient to control for gas increase for first non-zero balance
vm.deal(recipient, 1 wei);
usdc.mint(eoaUser, 1 wei);
// Prepare userOp
userOpCalldata = abi.encodeCall(CoinbaseSmartWallet.execute, (recipient, amount, "");

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

vm.startSnapshotGas("e2e_transfer_native_4337");
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.

naming nit

Suggested change
vm.startSnapshotGas("e2e_transfer_native_4337");
vm.startSnapshotGas("e2e_transfer_native_baseAccount");


vm.prank(eoaUser);
vm.startSnapshotGas("e2e_transfer_native_eoa");
payable(address(0x1234)).transfer(1 ether);
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 using fuzzing from earlier comment

Suggested change
payable(address(0x1234)).transfer(1 ether);
payable(address(recipient)).transfer(1 ether);

UserOperation memory op = _getUserOpWithSignature();

bytes memory handleOpsCalldata = abi.encodeCall(entryPoint.handleOps, (_makeOpsArray(op), payable(bundler)));
console2.log("test_transfer_native ERC-4337 calldata size:", handleOpsCalldata.length);
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.

also thinking we should log the calldata size for eoa execution as well for easy diff

Comment on lines +66 to +70
function test_transfer_erc20() public {
userOpCalldata = abi.encodeCall(
CoinbaseSmartWallet.execute,
(address(usdc), 0, abi.encodeCall(usdc.transfer, (address(0x5678), 100e6)))
);
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.

same thing here as previous function with:

  1. fuzzing instead of hardcoding values
  2. dust recipients to remove variability from zero->nonzero storage transition

UserOperation memory op = _getUserOpWithSignature();

bytes memory handleOpsCalldata = abi.encodeCall(entryPoint.handleOps, (_makeOpsArray(op), payable(bundler)));
console2.log("test_transfer_erc20 ERC-4337 calldata size:", handleOpsCalldata.length);
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.

also add eoa calldata size for comparison

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

vm.startSnapshotGas("e2e_transfer_erc20_4337");
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.

Suggested change
vm.startSnapshotGas("e2e_transfer_erc20_4337");
vm.startSnapshotGas("e2e_transfer_erc20_baseAccount");


vm.prank(eoaUser);
vm.startSnapshotGas("e2e_transfer_erc20_eoa");
usdc.transfer(address(0x5678), 100e6);
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.

use fuzzing

Suggested change
usdc.transfer(address(0x5678), 100e6);
usdc.transfer(recipient, amount);

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.

Not seeing where this is being used. Does the parent test contract require use to override this?

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.

Think it would be good to separate the lockfile and lib/forge-std diff into its own tiny PR for clarity and merge that first. Might not be worth the effort though, but generally touching build stuff is high enough importance to be isolated.

@ilikesymmetry ilikesymmetry self-requested a review September 8, 2025 20:09
Copy link
Copy Markdown
Contributor

@ilikesymmetry ilikesymmetry left a comment

Choose a reason for hiding this comment

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

Thanks for adding benchmarks :)

@shamit05 shamit05 marked this pull request as ready for review September 8, 2025 20:09
@cb-heimdall
Copy link
Copy Markdown
Collaborator

Review Error for ilikesymmetry @ 2025-09-08 20:10:32 UTC
User failed mfa authentication, see go/mfa-help

@ilikesymmetry ilikesymmetry self-requested a review September 8, 2025 22:34
@cb-heimdall
Copy link
Copy Markdown
Collaborator

Review Error for ilikesymmetry @ 2025-09-08 22:34:51 UTC
User failed mfa authentication, see go/mfa-help

@shamit05 shamit05 closed this Sep 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants