Skip to content

Conversation

@Syzygy106
Copy link
Contributor

Motivation

I decided to help Foundry community and fix the following bug: #12345
Closes #12345

Solution

Anvil now preserves Optimism's L1 gas fields when forking

When running Anvil in fork mode against Optimism, receipt fields like l1Fee, l1GasPrice, and l1GasUsed were getting lost. These fields are Optimism-specific and don't exist in standard Ethereum receipts, so they didn't fit into Anvil's TransactionReceipt type.

The problem:
Anvil's ReceiptResponse was just a plain TransactionReceipt<TypedReceiptRpc>, which meant any extra JSON fields from the upstream node got silently dropped. Optimism stores its L1 gas data in an other map, but convert_to_anvil_receipt was throwing it away.

The fix:

  • Changed ReceiptResponse to WithOtherFields<TransactionReceipt<TypedReceiptRpc>> so Anvil keeps unknown fields instead of discarding them
  • Updated convert_to_anvil_receipt to preserve the other fields
  • Added .inner access where needed (like in eth/api.rs)
  • Unwrapped WithOtherFields when converting to Otterscan API types (to maintain API compatibility while preserving fields internally)
  • Made sure locally-built receipts also use WithOtherFields with an empty map for consistency
  • Added a test that creates a synthetic Optimism receipt and verifies all L1 fields survive the conversion

Why it works:
WithOtherFields<T> from alloy-serde does exactly what we need—it preserves unknown JSON keys without touching the core schema. Now Anvil keeps all of Optimism's extra receipt data intact. Regular Ethereum receipts without these fields still work exactly as before.

Notes for reviewers:

  1. I didn't add documentation since this fix brings the behavior in line with what users would naturally expect. If you think docs are needed somewhere, happy to add them—just let me know where.

  2. I changed the response type and updated all the places where it's unpacked. I've run the tests and builds, and everything looks good, but I'd appreciate another set of eyes on the downstream logic—just in case I missed something that might be affected by the type change.

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

great

smol nits

@Syzygy106 Syzygy106 requested a review from mattsse October 31, 2025 18:00
mattsse
mattsse previously approved these changes Oct 31, 2025
Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

great

@mattsse
Copy link
Member

mattsse commented Oct 31, 2025

@Syzygy106 just needs cargo +nightly fmt --all

@Syzygy106
Copy link
Contributor Author

@Syzygy106 just needs cargo +nightly fmt --all

got it

@mattsse mattsse added this pull request to the merge queue Oct 31, 2025
Merged via the queue into foundry-rs:master with commit 1de93fc Oct 31, 2025
15 checks passed
@github-project-automation github-project-automation bot moved this to Done in Foundry Oct 31, 2025
@Syzygy106 Syzygy106 deleted the fix/anvil-fork-op-receipt-fields branch October 31, 2025 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

bug(anvil): The returned receipts in fork mode for on-chain txs are missing Optimism fields

2 participants