Skip to content

Comments

fix: encode calldata in preflight gas estimation#205

Open
haosenwang1018 wants to merge 1 commit intoConway-Research:mainfrom
haosenwang1018:fix/preflight-gas-estimation
Open

fix: encode calldata in preflight gas estimation#205
haosenwang1018 wants to merge 1 commit intoConway-Research:mainfrom
haosenwang1018:fix/preflight-gas-estimation

Conversation

@haosenwang1018
Copy link
Contributor

Summary

  • preflight() in src/registry/erc8004.ts passes data: undefined to estimateGas()
  • This estimates gas for a plain ETH transfer (~21,000 gas) instead of the actual contract call (register, setAgentURI, etc.)
  • The estimation always fails for contract targets, silently falling to the catch() fallback of 200,000 gas
  • The balance check then uses this placeholder value, providing no real protection against insufficient gas
  • Fix: use encodeFunctionData() from viem to encode the actual calldata before gas estimation

Test plan

  • npx tsc --noEmit passes
  • Verify preflight correctly rejects when balance is too low for the actual contract call

🤖 Generated with Claude Code

The preflight() function passed data: undefined to estimateGas(),
which estimates gas for a plain ETH transfer rather than the actual
contract call. This always fails for contract interactions, falling
through to the catch() fallback of 200,000 gas. The balance check
then uses an inaccurate estimate, providing no real protection
against out-of-gas reverts.

Encode the calldata with encodeFunctionData() so estimateGas()
simulates the actual contract call and returns a meaningful estimate.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant