Repository navigation
test(anvil): assert Monad transfer receipts match charged fees - #18608
Conversation
There was a problem hiding this comment.
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.
| 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); |
There was a problem hiding this comment.
doesn't compile: http_provider's estimate_gas takes WithOtherFields (E0308). wrap it with WithOtherFields::new(transfer.clone()); the test passes after that.
Signed-off-by: pjdurden <[email protected]>
stevencartavia
left a comment
There was a problem hiding this comment.
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.
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,
cumulativeGasUsedand blockgasUsedfrom 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
masterhas already fixed this through the evm2 migration that amaintainer mentioned on the issue.
monad-evm2(pinned rev95db06b) setsMonadTxResultExt::charged_gas = gas_limit(
monad-evm2/src/transaction.rs:301). Anvil now usesresult.ext.charged_gasfor:crates/anvil/src/eth/backend/executor.rs:416)TransactionInfo::gas_used(executor.rs:725), which feeds receipts and tracesgasUsed(crates/anvil/src/eth/backend/mem/mod.rs:6599)eth_simulateV1receiptseth_estimateGasandeth_createAccessListstill 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 receiptgasUsedand blockgasUsed. No test checked the issue's exact reproduction: does the sender'sbalance debit equal
receipt.gasUsed * effectiveGasPricefor a plain transfer,and is
cumulativeGasUsedcorrect across several transactions in one block?I added
monad_transfer_receipts_match_charged_feesto lock that in. Itestimates a plain transfer (expects 21,000), then mines two transfers with
100k and 200k limits into one block. It asserts that each receipt's
gasUsedequals its limit, that
cumulativeGasUsedadds up correctly, that blockgasUsedequals the total, and that the sender's balance debit equals thereceipt-derived fees plus the transferred value.
3. Files changed
crates/anvil/tests/it/monad.rs: new testmonad_transfer_receipts_match_charged_feesappended at the end of the file.
4. Risk / uncertainty
6 GB of free disk, too little for a full
anvil --features monadbuild. CImust 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}).holds for
NodeConfig::test_monad(), where the coinbase is not a dev account.rather than take the extra test.
5. Verification
monad-evm2source to confirmthat
charged_gasequals the gas limit and that receipts, cumulative gas andblock gas use it.
rustfmt +nightly --edition 2024 --check crates/anvil/tests/it/monad.rspasses.cargo nextest run -p anvil --features monad --test it -E 'test(monad_transfer_receipts_match_charged_fees)'(not enough disk space;
cargo-nextestis also not installed).