Skip to content

Conversation

@Thegaram
Copy link

@Thegaram Thegaram commented Jul 17, 2025

1. Purpose or design rationale of this PR

Ensure behavior of blockhash opcode in blocks shortly after the Feynman transition is consistent with scroll-revm.

2. PR title

Your PR title must follow conventional commits (as we are doing squash merge for each PR), so it must start with one of the following types:

  • fix: A bug fix

3. Deployment tag versioning

Has the version in params/version.go been updated?

  • This PR doesn't involve a new deployment, git tag, docker image tag, and it doesn't affect traces
  • Yes

4. Breaking change label

Does this PR have the breaking-change label?

  • This PR is not a breaking change
  • Yes

Summary by CodeRabbit

  • Bug Fixes

    • Improved reliability of block hash retrieval for recent blocks with enhanced handling around protocol fork boundaries.
  • Chores

    • Updated the application patch version to 0.71.
  • Tests

    • Added new tests to verify block hash behavior before and after the protocol fork.

@coderabbitai
Copy link

coderabbitai bot commented Jul 17, 2025

Walkthrough

The opBlockhashPostFeynman function was updated to change the mechanism for retrieving block hashes within the last 256 blocks, now using a ring index and fetching from history storage instead of the EVM context. The patch version constant was incremented from 70 to 71. A new test was added to verify the behavior of the blockhash opcode around the Feynman fork boundary.

Changes

File(s) Change Summary
core/vm/instructions.go Updated opBlockhashPostFeynman to fetch block hashes via ring index from history storage, removing direct EVM context access and witness recording.
params/version.go Incremented VersionPatch constant from 70 to 71.
core/state_processor_test.go Added TestFeynmanBlockhashOpcode to test blockhash opcode behavior before and after the Feynman fork, including helper functions and interface.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant opBlockhashPostFeynman
    participant StateDB

    Caller->>opBlockhashPostFeynman: Invoke with block number
    opBlockhashPostFeynman->>opBlockhashPostFeynman: Compute ring index (blockNum % window)
    opBlockhashPostFeynman->>opBlockhashPostFeynman: Encode key (last 8 bytes of 32-byte hash)
    opBlockhashPostFeynman->>StateDB: Get block hash from history storage using key
    StateDB-->>opBlockhashPostFeynman: Return block hash
    opBlockhashPostFeynman->>Caller: Set block hash on stack value (or clear if out of range)
Loading

Possibly related PRs

Suggested labels

bump-version

Suggested reviewers

  • colinlyguo
  • georgehao

Poem

A hop and a skip through history’s ring,
Block hashes fetched with a clever new swing.
No more direct calls, no witness in sight,
Just storage and keys, all working right.
Version bumped up, the code’s feeling spry—
A rabbit’s delight as the blocks hop by! 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Thegaram Thegaram requested a review from Copilot July 17, 2025 11:54
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes the blockhash opcode implementation in the post-Feynman transition to serve blockhash values directly from state storage instead of using the context's GetHash method, ensuring consistency with scroll-revm behavior.

  • Changes the opBlockhashPostFeynman function to retrieve blockhash values from the history storage system contract
  • Updates version patch number from 70 to 71 for deployment tracking
  • Removes witness-related code and simplifies the blockhash retrieval logic

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
params/version.go Updates patch version from 70 to 71
core/vm/instructions.go Modifies blockhash opcode to serve values from state storage instead of context
Comments suppressed due to low confidence (1)

core/vm/instructions.go:492

  • The change from using interpreter.evm.Context.GetHash() to StateDB.GetState() represents a significant behavioral change that should have comprehensive test coverage to ensure the state storage contains the expected blockhash values.
		res := interpreter.evm.StateDB.GetState(params.HistoryStorageAddress, key)

colinlyguo
colinlyguo previously approved these changes Jul 17, 2025
greged93
greged93 previously approved these changes Jul 17, 2025
Copy link

@greged93 greged93 left a comment

Choose a reason for hiding this comment

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

I'm trying to see how the L1 handled this but can't find anything rn on revm

@Thegaram
Copy link
Author

I'm trying to see how the L1 handled this but can't find anything rn on revm

Revm does not serve blockhash from the system contract storage, it serves it from block context (like before). We needed to change this so that we can prove the opcode execution.

@greged93
Copy link

We needed to change this so that we can prove the opcode execution.

Makes sense!

georgehao
georgehao previously approved these changes Jul 17, 2025
@Thegaram Thegaram dismissed stale reviews from georgehao, greged93, and colinlyguo via 69bbb41 July 17, 2025 14:31
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (3)
core/state_processor_test.go (3)

524-533: Consider adding the Solidity source code for better maintainability.

While the bytecode is documented with the Solidity version, including the actual source code would improve maintainability and make it easier to verify the bytecode.

Add the complete Solidity source code as a comment:

 		// pragma solidity =0.8.24;
 		//
 		// contract GetBlockHash {
+		// 	fallback() external payable {}
 		// 	function get(uint256 blockNumber) external view returns (bytes32) {
 		// 		return blockhash(blockNumber);
 		// 	}
 		// }

547-547: Consider reducing the gas limit for better test efficiency.

The gas limit of 30,000,000 seems excessive for a simple blockhash query. A more reasonable limit would improve test efficiency.

-			30_000_000,           // gasLimit
+			100_000,              // gasLimit

And update line 558 accordingly:

-		ret, _, _ := evm.Call(vm.AccountRef(msg.From()), *msg.To(), msg.Data(), 30_000_000, common.Big0, nil)
+		ret, _, _ := evm.Call(vm.AccountRef(msg.From()), *msg.To(), msg.Data(), 100_000, common.Big0, nil)

Also applies to: 558-558


651-651: Add type assertion check for safety.

The type assertion could panic if the implementation changes.

-	hasher := sha3.NewLegacyKeccak256().(keccakState)
+	hasher, ok := sha3.NewLegacyKeccak256().(keccakState)
+	if !ok {
+		panic("sha3.NewLegacyKeccak256() does not implement keccakState")
+	}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bc78141 and 69bbb41.

📒 Files selected for processing (1)
  • core/state_processor_test.go (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: test
  • GitHub Check: check
  • GitHub Check: Analyze (go)
🔇 Additional comments (2)
core/state_processor_test.go (2)

22-22: LGTM!

The hash import is correctly added and necessary for the keccakState interface.


640-643: LGTM!

The keccakState interface correctly combines hash.Hash with Read method for type assertion of the Keccak256 hasher.

@Thegaram Thegaram merged commit d1fcb78 into develop Jul 17, 2025
14 checks passed
@Thegaram Thegaram deleted the fix-serve-blockhash-from-state branch July 17, 2025 14:41
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.

5 participants