Skip to content

test: benchmark route-flexible MetaSwap caveats - #202

Open
hanzel98 wants to merge 1 commit into
mainfrom
test/metaswap-existing-enforcers
Open

test: benchmark route-flexible MetaSwap caveats#202
hanzel98 wants to merge 1 commit into
mainfrom
test/metaswap-existing-enforcers

Conversation

@hanzel98

@hanzel98 hanzel98 commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Demonstrates an atomic EIP-7702 MetaSwap flow using only existing enforcers: AllowedTargetsEnforcer, AllowedMethodsEnforcer, ValueLteEnforcer, four AllowedCalldataEnforcer caveats, LimitedCallsEnforcer, and ERC20BalanceChangeEnforcer.
  • Signs placeholder aggregator and route data, then redeems with different dynamic values to prove the swap calldata does not need to be known when signing.
  • Covers native input, ERC-20 approve(amount), and ERC-20 approve(0) + approve(amount).

Gas comparison

Compared with the MetaSwapBatchCalldataEnforcer proposed in PR #201, using estimated transaction gas (21,000 + calldata gas + measured execution gas) and equivalent one-use/output-balance protections:

  • Native: 390,484 vs 242,482 — existing composition costs 148,002 more gas (+61.04%).
  • ERC-20 approval: 455,432 vs 302,092 — costs 153,340 more gas (+50.76%).
  • ERC-20 reset approval: 462,621 vs 303,965 — costs 158,656 more 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 -vv
  • forge test --no-match-contract \"DelegationMetaSwapAdapterForkTest|VedaLendingTest\" (1,028 tests 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, four AllowedCalldata slices, LimitedCalls, ERC20BalanceChange), plus a minimal IMetaSwap mock.

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), and approve(0) + approve(amount).

This is test-only instrumentation intended to compare against the specialized MetaSwapBatchCalldataEnforcer approach (~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.

Demonstrate an atomic EIP-7702 swap built only from existing enforcers and measure its redemption cost with unknown route data.
@hanzel98
hanzel98 requested a review from a team as a code owner August 31, 2026 05:08
@hanzel98 hanzel98 added the invalid This doesn't seem right label Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

invalid This doesn't seem right

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant