Skip to content

Conversation

shazam8253
Copy link
Contributor

@shazam8253 shazam8253 commented Jul 10, 2025

Fixes #32175.

This fixes the scenario where the blockhash opcode would return 0x0 during RPC simulations when using BlockOverrides with a future block number. The root cause was that BlockOverrides.Apply() only modified the vm.BlockContext, but GetHashFn() depends on the actual types.Header.Number to resolve valid historical block hashes. This caused a mismatch and resulted in incorrect behavior during trace and call simulations.

Changes:
Added a new ApplyHeader method to BlockOverrides, which mutates the *types.Header with overridden fields. Updated the RPC simulation/tracing paths to apply header overrides directly to the Header object before creating the EVM block context. This makes sure that there is consistency between BlockContext.BlockNumber and Header.Number to allow GetHashFn() to function correctly in simulations.

Tests
I reproduced the error in a dev chain on geth and ran the updated code against the issue to ensure correctness.
test
test2
test3

@lightclient lightclient self-assigned this Jul 10, 2025
@rjl493456442 rjl493456442 changed the title apply block header overrides to get the correct blockhash (fixes #32175) eth/tracers: apply block header overrides correctly Jul 15, 2025
rjl493456442
rjl493456442 previously approved these changes Jul 15, 2025
Copy link
Member

@rjl493456442 rjl493456442 left a comment

Choose a reason for hiding this comment

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

please address the comment from matt, otherwise lgtm

@shazam8253
Copy link
Contributor Author

made the changes matt suggested!

@rjl493456442
Copy link
Member

@shazam8253 forgot to push the new commit?

Noticed that the parent hash was not being set. The way we do getHash relies on the parentHash to be cached correctly, so setting the parentHash after doing makeHeader fixes the issue.
@shazam8253
Copy link
Contributor Author

I noticed that the parent hash was not being set. The way we do getHash relies on the parentHash to be cached correctly, so setting the parentHash after doing makeHeader fixes the issue. I have also added a seperate test as well.

@ethereum ethereum deleted a comment from Krzysztofmaki Jul 15, 2025
@ethereum ethereum deleted a comment from Krzysztofmaki Jul 16, 2025
@lightclient lightclient added this to the 1.16.2 milestone Jul 16, 2025
@lightclient lightclient merged commit 30e3a49 into ethereum:master Jul 16, 2025
6 of 8 checks passed
howjmay pushed a commit to iotaledger/go-ethereum that referenced this pull request Aug 27, 2025
Fixes ethereum#32175.

This fixes the scenario where the blockhash opcode would return 0x0
during RPC simulations when using BlockOverrides with a future block
number. The root cause was that BlockOverrides.Apply() only modified the
vm.BlockContext, but GetHashFn() depends on the actual
types.Header.Number to resolve valid historical block hashes. This
caused a mismatch and resulted in incorrect behavior during trace and
call simulations.

---------

Co-authored-by: shantichanal <[email protected]>
Co-authored-by: lightclient <[email protected]>
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.

tracing via debug_traceCall with blockOverrides causes a previous block hash of 0
4 participants