Skip to content

test(tests): add BLOCKHASH genesis hash availability test#2228

Merged
marioevz merged 2 commits intoethereum:mainfrom
bshastry:genesis-blockhash-test
Oct 1, 2025
Merged

test(tests): add BLOCKHASH genesis hash availability test#2228
marioevz merged 2 commits intoethereum:mainfrom
bshastry:genesis-blockhash-test

Conversation

@bshastry
Copy link
Contributor

🗒️ Description

Add minimal regression test for BLOCKHASH opcode to verify genesis hash availability in blockchain tests. This test ensures that BLOCKHASH(0) returns the genesis hash (non-zero value) when executed in block 1, validating that blockchain test infrastructure properly initializes the block_hashes mapping before execution.

Context: This is a regression test for a bug found in the revm blockchaintest runner where block_hashes weren't being populated, causing BLOCKHASH(0) to incorrectly return 0. This broke tests using dynamic address computations like BLOCKHASH(0) | TIMESTAMP, where the computed address would be wrong, leading to test failures.

The test validates infrastructure correctness by:

  1. Executing ISZERO(BLOCKHASH(0)) in a contract deployed in block 1
  2. Verifying the result is 0 (false), proving the genesis hash exists and is non-zero
  3. Ensuring future tests with BLOCKHASH-derived addresses will work correctly

🔗 Related Issues or PRs

N/A.

✅ Checklist

  • All: Ran fast tox checks to avoid unnecessary CI fails, see also Code Standards and Enabling Pre-commit Checks:
    uvx --with=tox-uv tox -e lint,typecheck,spellcheck,markdownlint
  • All: PR title adheres to the repo standard - it will be used as the squash commit message and should start type(scope):.
  • All: Considered adding an entry to CHANGELOG.md.
  • All: Considered updating the online docs in the ./docs/ directory.
  • All: Set appropriate labels for the changes (only maintainers can apply labels).
  • Tests: Ran mkdocs serve locally and verified the auto-generated docs for new tests in the Test Case Reference are correctly formatted.
  • Tests: For PRs implementing a missed test case, update the post-mortem document to add an entry the list.
  • Ported Tests: All converted JSON/YML tests from ethereum/tests or tests/static have been assigned @ported_from marker.

📝 Additional Notes

File Added: tests/frontier/opcodes/test_blockhash.py

  • Test: test_genesis_hash_available (57 lines)
  • Valid from: Frontier (earliest fork with BLOCKHASH support)
  • Test type: BlockchainTestFiller (requires multiple blocks)

Quality Checks Passed:

  • ruff check - no linting issues
  • ruff format - properly formatted
  • mypy - no type errors
  • uv run fill --fork=Frontier - generates valid fixtures
  • uv run fill --fork=Cancun - works across all forks

Suggested PR Title:

test(tests): add BLOCKHASH genesis hash availability test

@bshastry
Copy link
Contributor Author

CC @rakita who asked for such a test (upstream fix PR bluealloy/revm#3024)

@rakita
Copy link

rakita commented Sep 30, 2025

Would be great to add additional block, and in block 2 to fetch block 1 hash, so that we can test both genesis and first executed block insertion.

Copy link
Collaborator

@LouisTsai-Csie LouisTsai-Csie left a comment

Choose a reason for hiding this comment

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

The current test structure looks good, but it is worth considering @rakita’s suggestion to include an additional scenario.

Add regression test verifying BLOCKHASH(0) returns genesis hash in block 1.
Tests blockchain test infrastructure properly populates genesis hash before
execution, preventing BLOCKHASH(0) from returning 0.

Regression context: revm blockchaintest runner wasn't inserting block_hashes
into state, causing BLOCKHASH(0) to return 0. This broke tests with dynamic
address computations like BLOCKHASH(0) | TIMESTAMP, where the computed
address would be incorrect, leading to balance transfer failures.

Test validates infrastructure setup by storing ISZERO(BLOCKHASH(0)) which
should be 0 (false) when genesis hash is properly available.
@bshastry bshastry force-pushed the genesis-blockhash-test branch from a9e1ac7 to 50adff8 Compare October 1, 2025 08:10
Extends test_genesis_hash_available to verify both genesis (block 0)
and first executed block (block 1) hash insertion by adding a second
block that calls the contract, testing BLOCKHASH(0) and BLOCKHASH(1).

Addresses PR feedback to test complete block hash infrastructure.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@bshastry
Copy link
Contributor Author

bshastry commented Oct 1, 2025

Would be great to add additional block, and in block 2 to fetch block 1 hash, so that we can test both genesis and first executed block insertion.

Thank you for your feedback. I have updated the test accordingly such that after both blocks in the test are executed, the storage at key 0, 1 are expected to be zero (as per the logic of iszero(blockhash(0)) and iszero(blockhash(1))). Hope this change is fine @LouisTsai-Csie 🙏

Copy link
Member

@marioevz marioevz left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@marioevz marioevz merged commit b37336d into ethereum:main Oct 1, 2025
26 of 30 checks passed
kclowes pushed a commit to kclowes/execution-spec-tests that referenced this pull request Oct 20, 2025
)

* test(tests): add BLOCKHASH genesis hash availability test

Add regression test verifying BLOCKHASH(0) returns genesis hash in block 1.
Tests blockchain test infrastructure properly populates genesis hash before
execution, preventing BLOCKHASH(0) from returning 0.

Regression context: revm blockchaintest runner wasn't inserting block_hashes
into state, causing BLOCKHASH(0) to return 0. This broke tests with dynamic
address computations like BLOCKHASH(0) | TIMESTAMP, where the computed
address would be incorrect, leading to balance transfer failures.

Test validates infrastructure setup by storing ISZERO(BLOCKHASH(0)) which
should be 0 (false) when genesis hash is properly available.

* test(tests): extend BLOCKHASH test to verify block 1 hash availability

Extends test_genesis_hash_available to verify both genesis (block 0)
and first executed block (block 1) hash insertion by adding a second
block that calls the contract, testing BLOCKHASH(0) and BLOCKHASH(1).

Addresses PR feedback to test complete block hash infrastructure.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
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.

4 participants