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

cannon: Fix inverted hint writing conditional check #10514

Merged

Conversation

mbaxter
Copy link
Contributor

@mbaxter mbaxter commented May 13, 2024

Description

Fix hint writing logic in mips.go: we should read hints while the accumulated hint data is >= the current hint's length prefix.

Tests

  • Add some unit tests around hint writing.
  • Update hint writing fuzz test to set random data at the memory range that is being used in the syscall.

Additional context

This is part of the work to address the Coinbase security audit of Cannon.

Metadata

Part of: https://github.com/ethereum-optimism/client-pod/issues/761 (H-01)

Copy link

codecov bot commented May 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 42.35%. Comparing base (3508670) to head (7d53412).
Report is 2 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #10514      +/-   ##
===========================================
+ Coverage    42.31%   42.35%   +0.04%     
===========================================
  Files           73       73              
  Lines         4838     4838              
  Branches       766      766              
===========================================
+ Hits          2047     2049       +2     
+ Misses        2682     2681       -1     
+ Partials       109      108       -1     
Flag Coverage Δ
cannon-go-tests 81.77% <100.00%> (+0.18%) ⬆️
chain-mon-tests 27.14% <ø> (ø)
common-ts-tests 26.72% <ø> (ø)
contracts-ts-tests 12.25% <ø> (ø)
core-utils-tests 44.03% <ø> (ø)
sdk-tests 40.27% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
cannon/mipsevm/mips.go 95.20% <100.00%> (+0.41%) ⬆️
cannon/mipsevm/state.go 87.23% <ø> (ø)

@mbaxter mbaxter requested a review from Inphi May 13, 2024 14:20
@mbaxter mbaxter marked this pull request as ready for review May 13, 2024 14:20
@mbaxter mbaxter requested a review from a team as a code owner May 13, 2024 14:20
Copy link
Contributor

coderabbitai bot commented May 13, 2024

Walkthrough

Walkthrough

The recent updates involve enhancements and modifications across several files in the cannon/mipsevm module. Key changes include the addition of a new test function and a type for hint tracking, adjustments to hint processing logic in syscall handling, and the introduction of randomness in fuzz testing. These changes aim to refine the system's handling of hints and improve testing robustness.

Changes

File(s) Summary of Changes
.../evm_test.go Added TestEVMSysWriteHint and hintTrackingOracle type with associated methods.
.../fuzz_evm_test.go Updated imports and modified FuzzStateHintWrite to use a new randSeed parameter for random data generation.
mips.go, state.go Changed hint length processing logic in handleSyscall and reading LastHint conditions from >= to <=.

Recent Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 043ee4d and 7d53412.
Files selected for processing (4)
  • cannon/mipsevm/evm_test.go (2 hunks)
  • cannon/mipsevm/fuzz_evm_test.go (4 hunks)
  • cannon/mipsevm/mips.go (1 hunks)
  • cannon/mipsevm/state.go (1 hunks)
Additional comments not posted (6)
cannon/mipsevm/state.go (1)

41-41: Change in conditional logic correctly ensures that hints are only processed when the data is sufficient.

cannon/mipsevm/mips.go (1)

126-126: Change in conditional logic correctly ensures that hints are only processed when the data is sufficient.

cannon/mipsevm/fuzz_evm_test.go (2)

4-5: Addition of imports supports new functionality for generating random data in fuzz tests.


Line range hint 403-425: Enhancements to FuzzStateHintWrite function with randSeed parameter and logic for generating random data improve the robustness of fuzz tests.

cannon/mipsevm/evm_test.go (2)

253-429: The implementation of TestEVMSysWriteHint appears comprehensive and well-structured. It tests various scenarios of hint writing, ensuring robustness in the system's handling of edge cases. The use of hintTrackingOracle to capture the hints for verification is a clever approach, enhancing the test's ability to assert correctness directly.


575-585: The hintTrackingOracle type is effectively used in tests to track hints. However, the GetPreimage method currently returns nil, which might be intentional for the current tests but could limit the utility of this oracle in scenarios where actual preimage data is needed for more comprehensive testing.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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>.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

@mbaxter mbaxter added this pull request to the merge queue May 13, 2024
@mbaxter mbaxter removed this pull request from the merge queue due to a manual request May 13, 2024
@Inphi Inphi added this pull request to the merge queue May 13, 2024
Merged via the queue into ethereum-optimism:develop with commit 2fadb4c May 13, 2024
67 of 69 checks passed
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