Skip to content
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

new(tests): Blockhash at 255/256/257 (ethereum/execution-specs#374) #988

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

codeofcarson
Copy link

@codeofcarson codeofcarson commented Dec 3, 2024

🗒️ Description

This adds tests designed to test the BLOCKHASH opcode for when there are 255, 256, and 257 blocks in the chain.

Filled with https://github.com/ethereum/execution-specs#9b95554a88d2a8485f8180254d0f6a493a593fda

🔗 Related Issues

This is actually issue (ethereum/execution-specs#374) in the execution-specs

✅ Checklist

  • All: Set appropriate labels for the changes.
  • All: Considered squashing commits to improve commit history.
  • All: Added an entry to CHANGELOG.md.
  • All: Considered updating the online docs in the ./docs/ directory.
  • Tests: All converted JSON/YML tests from ethereum/tests have been added to converted-ethereum-tests.txt.
  • Tests: A PR with removal of converted JSON/YML tests from ethereum/tests have been opened.
  • Tests: Included the type and version of evm t8n tool used to locally execute test cases: e.g., ref with commit hash or geth 1.13.1-stable-3f40e65.
  • Tests: Ran mkdocs serve locally and verified the auto-generated docs for new tests in the Test Case Reference are correctly formatted.

I will add the CHANGELOG update before this gets merged after review.

Do I need to update the docs in the codebase for this one too?

@codeofcarson codeofcarson marked this pull request as draft December 3, 2024 20:38
@codeofcarson
Copy link
Author

For this one I sneakily grabbed the hashes off of the outputs for the tests when I ran them. You won't be able to do that with future forks right? Is there a way that it could be computed on the fly?

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.

Thanks for implementing this! And sorry about the delay on the review.

Some comments regarding the test implementation, not all have to be addressed in this PR, but it would be nice to discuss.

Comment on lines +34 to +35
Note: Hardcoded blockhashes to get us started. Will look for a better
way of doing this in future
Copy link
Member

Choose a reason for hiding this comment

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

Definitely, we would use such a solution for other tests also. There are some tests that use up to 8000+ blocks and significantly slow down the fixture generation process for us, so having a way of pre-generating the tests would be very beneficial.

Comment on lines +47 to +51
post = {
account: Account(
storage={"0x0": expected},
),
}
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps outside of the scope of this PR, but I think we could maybe enhance the way we generate tests to make post more dynamic.

I'm thinking that maybe the post object could be a callable/function that receives all the generated blocks and returns the post dictionary?

We would need to update the framework for something like this to work since this has never been done before, but it might benefit other tests too, potentially EIP-2935 tests.

cc @danceratopz to comment on this idea.

Copy link
Author

Choose a reason for hiding this comment

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

I'll wait for your cc to reply before taking action on this. Interesting idea!

tests/frontier/opcodes/test_chain_sync.py Outdated Show resolved Hide resolved
@@ -0,0 +1,70 @@
"""
abstract: Test the chain synchronization feature.
Copy link
Member

Choose a reason for hiding this comment

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

In this specific case, for us to test the actual sync we would need to enable the verify_sync flag for the BlockchainTest object (blockchain_test in line 65), which is kind of an obscure feature and only gets really used when the test is consumed in hive, but I think this kind of test is perfect for it.

tests/frontier/opcodes/test_chain_sync.py Outdated Show resolved Hide resolved
env = Environment()
sender = pre.fund_eoa()
blockhash_code = Op.SSTORE(
0,
Copy link
Member

Choose a reason for hiding this comment

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

We could save this value to a key derived from the offset (or the offset itself) instead of zero, because I think we can save up test generation time by testing all offsets in one-shot instead of parametrizing its value (normally we prefer parametrization but in this case we are generating a ton of blocks).

Copy link
Author

Choose a reason for hiding this comment

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

Hmmm, that's a good point. Okay I'll rewrite that part.

@marioevz
Copy link
Member

marioevz commented Jan 6, 2025

Do I need to update the docs in the codebase for this one too?

As it is right now, there's no need to update the docs, they should be updated automatically.

For this one I sneakily grabbed the hashes off of the outputs for the tests when I ran them. You won't be able to do that with future forks right? Is there a way that it could be computed on the fly?

See my comment in the review. I think this approach is ok for now, but if you want to adventure into modifying the framework to implement the dynamic-post feature I mention, maybe in a separate PR, I'll gladly guide you through it!

codeofcarson and others added 2 commits January 8, 2025 14:59
The nonce being equal to 0 is implicit and does not need to be state explicitly

Co-authored-by: Mario Vega <[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.

2 participants