test: benchmark route-flexible MetaSwap caveats - #202
Open
hanzel98 wants to merge 1 commit into
Open
Conversation
Demonstrate an atomic EIP-7702 swap built only from existing enforcers and measure its redemption cost with unknown route data.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
AllowedTargetsEnforcer,AllowedMethodsEnforcer,ValueLteEnforcer, fourAllowedCalldataEnforcercaveats,LimitedCallsEnforcer, andERC20BalanceChangeEnforcer.approve(amount), and ERC-20approve(0) + approve(amount).Gas comparison
Compared with the
MetaSwapBatchCalldataEnforcerproposed in PR #201, using estimated transaction gas (21,000 + calldata gas + measured execution gas) and equivalent one-use/output-balance protections:390,484vs242,482— existing composition costs148,002more gas (+61.04%).455,432vs302,092— costs153,340more gas (+50.76%).462,621vs303,965— costs158,656more gas (+52.20%).The specialized batch enforcer is approximately
33.67%–37.90%cheaper than the existing-enforcer composition. The difference primarily comes from larger signed terms, four independent calldata checks, repeated decoding/hashing, and the additional EIP-7702 self-call.Test plan
forge test --match-contract MetaSwapExistingEnforcersGasTest -vvforge test --no-match-contract \"DelegationMetaSwapAdapterForkTest|VedaLendingTest\"(1,028tests passed)Note
Low Risk
Adds experimental Forge tests and a local mock only; no changes to production enforcers or delegation logic.
Overview
Adds
test/experiments/MetaSwapExistingEnforcersGas.t.sol, an experiment that measures gas for an EIP-7702 MetaSwap redemption built only from existing caveats (AllowedTargets,AllowedMethods,ValueLte, fourAllowedCalldataslices,LimitedCalls,ERC20BalanceChange), plus a minimalIMetaSwapmock.The tests sign delegations against placeholder aggregator/route calldata, then redeem with different dynamic route data to show the swap path does not need to be fixed at sign time. Three scenarios log execution, calldata, and estimated transaction gas: native input, ERC-20
approve(amount), andapprove(0)+approve(amount).This is test-only instrumentation intended to compare against the specialized
MetaSwapBatchCalldataEnforcerapproach (~50–61% higher estimated gas in the scenarios documented in the PR).Reviewed by Cursor Bugbot for commit e75643c. Bugbot is set up for automated code reviews on this repo. Configure here.