Skip to content

test(anvil): assert Monad transfer receipts match charged fees - #18608

Merged
mattsse merged 2 commits into
foundry-rs:masterfrom
pjdurden:fix/17759
Nov 28, 2026
Merged

mattsse merged 2 commits into
foundry-rs:masterfrom
pjdurden:fix/17759

Conversation

@pjdurden

Copy link
Copy Markdown
Contributor

Notes: #17759 (Monad receipts underreport charged gas)

1. Root cause

Monad charges the full transaction gas limit and pays no refunds. On the old
revm-based stack, anvil built receipts, cumulativeGasUsed and block gasUsed
from consumed execution gas. A 21,000-gas transfer sent with a 100,000 limit
therefore reported 21,000 while the sender was debited for 100,000.

The current master has already fixed this through the evm2 migration that a
maintainer mentioned on the issue. monad-evm2 (pinned rev 95db06b) sets
MonadTxResultExt::charged_gas = gas_limit
(monad-evm2/src/transaction.rs:301). Anvil now uses result.ext.charged_gas for:

  • per-transaction and cumulative receipt gas (crates/anvil/src/eth/backend/executor.rs:416)
  • the stored TransactionInfo::gas_used (executor.rs:725), which feeds receipts and traces
  • block gasUsed (crates/anvil/src/eth/backend/mem/mod.rs:6599)
  • eth_simulateV1 receipts

eth_estimateGas and eth_createAccessList still report consumption (21,000).

2. The fix and why

No production code change is needed, and I made none on purpose. Existing
tests (monad_estimates_consumption_and_receipts_charge_the_limit,
test_call_tracer_mined_gas_limits) already check receipt gasUsed and block
gasUsed. No test checked the issue's exact reproduction: does the sender's
balance debit equal receipt.gasUsed * effectiveGasPrice for a plain transfer,
and is cumulativeGasUsed correct across several transactions in one block?

I added monad_transfer_receipts_match_charged_fees to lock that in. It
estimates a plain transfer (expects 21,000), then mines two transfers with
100k and 200k limits into one block. It asserts that each receipt's gasUsed
equals its limit, that cumulativeGasUsed adds up correctly, that block
gasUsed equals the total, and that the sender's balance debit equals the
receipt-derived fees plus the transferred value.

3. Files changed

  • crates/anvil/tests/it/monad.rs: new test monad_transfer_receipts_match_charged_fees
    appended at the end of the file.

4. Risk / uncertainty

  • Test-only change, so there is no runtime risk.
  • The new test was not compiled or run locally. The machine has only about
    6 GB of free disk, too little for a full anvil --features monad build. CI
    must confirm it. It uses only APIs already used in this file and in
    traces.rs (anvil_set_auto_mine, mine_one, ReceiptResponse::{gas_used, cumulative_gas_used, effective_gas_price}).
  • The balance check assumes the dev sender is not the block beneficiary. That
    holds for NodeConfig::test_monad(), where the coinbase is not a dev account.
  • Maintainers may prefer to close the issue as fixed by the evm2 migration
    rather than take the extra test.

5. Verification

  • Read the code paths listed above and the pinned monad-evm2 source to confirm
    that charged_gas equals the gas limit and that receipts, cumulative gas and
    block gas use it.
  • rustfmt +nightly --edition 2024 --check crates/anvil/tests/it/monad.rs passes.
  • Not done: cargo nextest run -p anvil --features monad --test it -E 'test(monad_transfer_receipts_match_charged_fees)'
    (not enough disk space; cargo-nextest is also not installed).

Copilot AI balanced review requested due to automatic review settings November 19, 2026 15:14

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

Comment thread crates/anvil/tests/it/monad.rs Outdated
let sender = handle.dev_accounts().next().unwrap();
let to = Address::repeat_byte(0x55);
let transfer = TransactionRequest::default().from(sender).to(to).value(U256::from(1));
assert_eq!(provider.estimate_gas(transfer.clone()).await.unwrap(), 21_000);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

doesn't compile: http_provider's estimate_gas takes WithOtherFields (E0308). wrap it with WithOtherFields::new(transfer.clone()); the test passes after that.

@mattsse
mattsse enabled auto-merge (squash) November 27, 2026 21:18

@stevencartavia stevencartavia left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Test-only change. The new Monad test passed in CI on this head and checks per-receipt charged gas, cumulative gas across two transactions in one block, block gasUsed, and the sender's balance debit. The only CI failure is tempo::test_tempo_sponsor_without_preference_uses_fallback_fee_tokens, which fails the same way on master at the base commit 9610e13.

@mattsse
mattsse merged commit 451081e into foundry-rs:master Nov 28, 2026
35 of 63 checks passed
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.

5 participants