- 
                Notifications
    
You must be signed in to change notification settings  - Fork 2.2k
 
fix(anvil): preserve OP receipt fields in convert_to_anvil_receipt #12396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
            mattsse
  merged 6 commits into
  foundry-rs:master
from
Syzygy106:fix/anvil-fork-op-receipt-fields
  
      
      
   
  Oct 31, 2025 
      
    
                
     Merged
            
            fix(anvil): preserve OP receipt fields in convert_to_anvil_receipt #12396
                    mattsse
  merged 6 commits into
  foundry-rs:master
from
Syzygy106:fix/anvil-fork-op-receipt-fields
  
      
      
   
  Oct 31, 2025 
              
            
      
        
          +101
        
        
          −48
        
        
          
        
      
    
  
Conversation
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
    
              
                    mattsse
  
              
              requested changes
              
                  
                    Oct 31, 2025 
                  
              
              
            
            
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great
smol nits
              
                    mattsse
  
              
              previously approved these changes
              
                  
                    Oct 31, 2025 
                  
              
              
            
            
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great
| 
           @Syzygy106 just needs cargo +nightly fmt --all  | 
    
          
 got it  | 
    
              
                    mattsse
  
              
              approved these changes
              
                  
                    Oct 31, 2025 
                  
              
              
            
            
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
      
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
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, andl1GasUsedwere getting lost. These fields are Optimism-specific and don't exist in standard Ethereum receipts, so they didn't fit into Anvil'sTransactionReceipttype.The problem:
Anvil's
ReceiptResponsewas just a plainTransactionReceipt<TypedReceiptRpc>, which meant any extra JSON fields from the upstream node got silently dropped. Optimism stores its L1 gas data in anothermap, butconvert_to_anvil_receiptwas throwing it away.The fix:
ReceiptResponsetoWithOtherFields<TransactionReceipt<TypedReceiptRpc>>so Anvil keeps unknown fields instead of discarding themconvert_to_anvil_receiptto preserve theotherfields.inneraccess where needed (like ineth/api.rs)WithOtherFieldswhen converting to Otterscan API types (to maintain API compatibility while preserving fields internally)WithOtherFieldswith an empty map for consistencyWhy 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:
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.
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