Skip to content

op-challenger: Implement block number challenge calls in contract bindings#10462

Merged
refcell merged 1 commit intodevelopfrom
aj/challenge-l2-block-number
May 9, 2024
Merged

op-challenger: Implement block number challenge calls in contract bindings#10462
refcell merged 1 commit intodevelopfrom
aj/challenge-l2-block-number

Conversation

@ajsutton
Copy link
Contributor

@ajsutton ajsutton commented May 9, 2024

Description

Implements support for the new challenge L2 block number calls in the contract bindings so the challenge actually challenges block numbers. Compatibility with older versions of contracts is preserved.

Tests

Updated unit tests. Added e2e test to confirm challenging works.

Metadata

@ajsutton ajsutton requested a review from a team as a code owner May 9, 2024 03:24
@ajsutton ajsutton requested a review from tynes May 9, 2024 03:24
@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 9, 2024

Walkthrough

Walkthrough

The recent updates across various modules focus primarily on enhancing the fault dispute mechanisms in blockchain contracts, specifically targeting the challenge and verification of L2 block numbers. New functions and tests have been introduced to manage these disputes more effectively. Additionally, support for multiple contract versions has been improved, and new utility functions have been added to assist in end-to-end testing scenarios.

Changes

File Path Change Summary
.../game/fault/contracts/faultdisputegame.go Added methods for L2 block number challenges and a new outputRootProof struct.
.../game/fault/contracts/faultdisputegame0180.go Introduced FaultDisputeGameContract0180 with methods for challenging L2 block numbers.
.../game/fault/contracts/faultdisputegame080.go Similar to above, added methods for L2 block number challenges in FaultDisputeGameContract080.
.../game/fault/contracts/faultdisputegame_test.go Enhanced testing for new and existing contract versions, including imports and version management.
.../e2eutils/disputegame/output_game_helper.go Added a helper function for waiting on L2 block number challenges.
.../faultproofs/output_cannon_test.go New test function to validate the dispute resolution process for a dishonest claim about a future block.

Recent Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 93e9d15 and c7179bb.
Files ignored due to path filters (1)
  • op-challenger/game/fault/contracts/abis/FaultDisputeGame-0.18.1.json is excluded by !**/*.json
Files selected for processing (6)
  • op-challenger/game/fault/contracts/faultdisputegame.go (4 hunks)
  • op-challenger/game/fault/contracts/faultdisputegame0180.go (1 hunks)
  • op-challenger/game/fault/contracts/faultdisputegame080.go (1 hunks)
  • op-challenger/game/fault/contracts/faultdisputegame_test.go (4 hunks)
  • op-e2e/e2eutils/disputegame/output_game_helper.go (1 hunks)
  • op-e2e/faultproofs/output_cannon_test.go (1 hunks)
Files not reviewed due to errors (1)
  • op-e2e/faultproofs/output_cannon_test.go (no review received)
Additional comments not posted (11)
op-challenger/game/fault/contracts/faultdisputegame0180.go (2)

19-21: Consider adding a comment explaining why IsL2BlockNumberChallenged always returns false, to clarify that this version does not support block number challenges.


23-25: Consider adding a comment explaining why ChallengeL2BlockNumberTx returns an error, to clarify that this version does not support challenging L2 block numbers.

op-challenger/game/fault/contracts/faultdisputegame080.go (2)

136-138: Consider adding a comment explaining why IsL2BlockNumberChallenged always returns false, to clarify that this version does not support block number challenges.


140-142: Consider adding a comment explaining why ChallengeL2BlockNumberTx returns an error, to clarify that this version does not support challenging L2 block numbers.

op-challenger/game/fault/contracts/faultdisputegame.go (2)

438-443: Implementation of IsL2BlockNumberChallenged looks good with proper error handling.


447-456: Implementation of ChallengeL2BlockNumberTx looks good, properly handling the serialization of the header and the output root proof.

op-challenger/game/fault/contracts/faultdisputegame_test.go (5)

6-6: Ensure that the newly added fmt import is used within the file. Unused imports should be removed to keep the code clean.

Verification successful

The verification process has confirmed that the fmt import is indeed used within the faultdisputegame_test.go file. The usage is found in a t.Run function call where fmt.Sprintf is utilized to format test names dynamically. This confirms that the import is necessary and appropriately used in the context of the unit tests.

Usage of fmt import verified:

  • The fmt package is used in the t.Run method to format strings, which is a valid and common use case in test files for generating dynamic test names.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify usage of `fmt` import in `faultdisputegame_test.go`.

# Test: Search for `fmt.` usage. Expect: At least one occurrence.
rg --type go $'fmt\\.' op-challenger/game/fault/contracts/faultdisputegame_test.go

Length of output: 161


9-9: Ensure that the newly added math/rand import is utilized within the file. Unused imports should be removed to maintain code cleanliness.

Verification successful

The verification process has confirmed that the math/rand import is indeed utilized within the faultdisputegame_test.go file. The script output shows a line where a new random number generator is instantiated using rand.New(rand.NewSource(0)), which clearly indicates the use of the math/rand package.


Usage of math/rand in faultdisputegame_test.go Verified

The import of math/rand in the file faultdisputegame_test.go is properly utilized for creating a random number generator. This confirms that the import is necessary and correctly implemented.

  • Location: op-challenger/game/fault/contracts/faultdisputegame_test.go
    • Usage: rng := rand.New(rand.NewSource(0))
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify usage of `math/rand` import in `faultdisputegame_test.go`.

# Test: Search for `rand.` usage. Expect: At least one occurrence.
rg --type go $'rand\\.' op-challenger/game/fault/contracts/faultdisputegame_test.go

Length of output: 121


16-20: Confirm that all newly added imports from the github.com/ethereum-optimism/optimism/op-service package are utilized in the file. Remove any that are not used to keep the codebase lean and maintainable.

Verification successful

The imports from the github.com/ethereum-optimism/optimism/op-service package added to faultdisputegame_test.go are indeed utilized within the file. Here are the specific usages identified:

  • The eth namespace is used for creating instances like eth.OutputResponse, eth.Bytes32, and eth.L2BlockRef.
  • The testutils namespace is used with testutils.RandomHeader.
  • The txmgr namespace is used in expressions like txmgr.TxCandidate{}.

These findings confirm that the imports are necessary and appropriately used in the context of the file.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify usage of new imports from `github.com/ethereum-optimism/optimism/op-service` in `faultdisputegame_test.go`.

# Test: Search for usage of each import. Expect: At least one occurrence for each.
rg --type go $'eth\\.|testutils\\.|txmgr\\.' op-challenger/game/fault/contracts/faultdisputegame_test.go

Length of output: 427


25-25: Verify that the github.com/ethereum/go-ethereum/rlp import is used within the file. If it is not used, consider removing it to avoid clutter.

Verification successful

The verification process has confirmed that the import github.com/ethereum/go-ethereum/rlp is indeed utilized within the file faultdisputegame_test.go. The specific usage found involves encoding a header to bytes using the rlp.EncodeToBytes function. This confirms the necessity of the import for the functionality implemented in the test file.

  • Usage found: headerRlp, err := rlp.EncodeToBytes(challenge.Header)
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify usage of `github.com/ethereum/go-ethereum/rlp` import in `faultdisputegame_test.go`.

# Test: Search for `rlp.` usage. Expect: At least one occurrence.
rg --type go $'rlp\\.' op-challenger/game/fault/contracts/faultdisputegame_test.go

Length of output: 140


Line range hint 42-58: The update to the versLatest constant and the addition of a new version entry for vers0180 are consistent with the PR's objectives to handle multiple contract versions. Ensure that these version constants are correctly used throughout the test cases to reflect the intended functionality.


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.

Copy link
Contributor

@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: 0

Out of diff range and nitpick comments (1)
op-e2e/e2eutils/disputegame/output_game_helper.go (1)

445-456: Implementation of WaitForL2BlockNumberChallenged looks solid and aligns with the PR's objectives.

Consider logging more detailed information about the challenge status or any errors encountered during the waiting process to aid in debugging and monitoring.

@codecov
Copy link

codecov bot commented May 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.59%. Comparing base (93e9d15) to head (c7179bb).

Additional details and impacted files
@@             Coverage Diff              @@
##           develop   #10462       +/-   ##
============================================
+ Coverage    42.31%   81.59%   +39.28%     
============================================
  Files           73       10       -63     
  Lines         4838     1081     -3757     
  Branches       766        0      -766     
============================================
- Hits          2047      882     -1165     
+ Misses        2682      165     -2517     
+ Partials       109       34       -75     
Flag Coverage Δ
cannon-go-tests 81.59% <ø> (ø)
chain-mon-tests ?
common-ts-tests ?
contracts-ts-tests ?
core-utils-tests ?
sdk-tests ?

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

see 63 files with indirect coverage changes

@ajsutton ajsutton requested review from Inphi and removed request for tynes May 9, 2024 04:10
Copy link
Contributor

@Inphi Inphi left a comment

Choose a reason for hiding this comment

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

Superb!

@ajsutton ajsutton added this pull request to the merge queue May 9, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 9, 2024
@refcell refcell added this pull request to the merge queue May 9, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 9, 2024
@refcell refcell added this pull request to the merge queue May 9, 2024
Merged via the queue into develop with commit 1dd35b7 May 9, 2024
@refcell refcell deleted the aj/challenge-l2-block-number branch May 9, 2024 16:05
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.

3 participants