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

Plasma: Abstract CommitmentData to Interface #10458

Merged
merged 8 commits into from
May 10, 2024
Merged

Conversation

axelKingsley
Copy link
Contributor

@axelKingsley axelKingsley commented May 8, 2024

What

Abstracts Keccak and Generic Commitment types to a CommitmentData, and wires it throughout the project

Why

op-node must support different modes of operation for Generic and Keccak commitments, which are signaled by a type byte at the front of the data.

How

Now, in all places where a commitment is decoded, the package function DecodeCommitmentData is used. This handles the type check, does some basic validation, and then calls down to the implementation-specific decoder.

And, in all places where a commitment is encoded, NewCommitmentData is used. This function takes the CommitmentType to decide which concrete type to use.

The CommitmentData interface replaces all reference to concrete types in existing Plasma/DA behaviors.

Outside of these activities, all access to the CommitmentData happens through interface-defined functions which Keccak and Generic already supported -- Encode, Verify, TxData

Omitting

Not featured in this PR is any feature-flagging from the node for the expected Commitment Type. @trianglesphere has a plan in mind to group the config details, so that will be wired in then. The DA Client similarly is set to only produce Keccak commitments.

Testing

Tests were written for the CommitmentData interface to confirm it creates the right type of commitment and handles errors as expected.

DA server tests are fixed to type-assert Keccak type Commitments, as the server components are designed to only use those. When flags are wired into the Next and SetInput functions, the test can be multiplied by both Commitment Types. The Mock DA Server is already set to handle that with this PR, you can just overload the Commitment Type the mock uses.

This is a generic commitment to be used by the op-node & op-batcher.
op-plasma/daclient.go Outdated Show resolved Hide resolved
Copy link

semgrep-app bot commented May 8, 2024

Semgrep found 1 writable-filesystem-service finding:

  • ops-bedrock/docker-compose.yml

Service 'op_stack_go_builder' is running with a writable root filesystem. This may allow malicious applications to download and run additional payloads, or modify container files. If an application inside a container has to save something temporarily consider using a tmpfs. Add 'read_only: true' to this service to prevent this.

Ignore this finding from writable-filesystem-service.

Semgrep found 1 no-new-privileges finding:

  • ops-bedrock/docker-compose.yml

Service 'op_stack_go_builder' allows for privilege escalation via setuid or setgid binaries. Add 'no-new-privileges:true' in 'security_opt' to prevent this.

Ignore this finding from no-new-privileges.

@axelKingsley axelKingsley changed the base branch from develop to jg/generic_comm May 8, 2024 21:02
@axelKingsley axelKingsley marked this pull request as ready for review May 10, 2024 17:42
@axelKingsley axelKingsley changed the base branch from jg/generic_comm to develop May 10, 2024 18:03
Copy link
Contributor

coderabbitai bot commented May 10, 2024

Walkthrough

Walkthrough

The recent updates across various files involve transitioning from using Keccak256Commitment to a more flexible CommitmentData interface for handling plasma commitments. This change enhances the system's capability to manage diverse commitment types and streamlines input and output processes within the plasma framework, reflecting a significant architectural refinement.

Changes

Files Summary
op-e2e/actions/l2_batcher.go Modified PlasmaInputSetter interface to return plasma.CommitmentData instead of plasma.Keccak256Commitment.
op-e2e/actions/plasma_test.go Updated function calls to GetInput by using plasma.Keccak256Commitment with modified arguments.
op-node/rollup/derive/data_source.go Changed parameter type in GetInput method of PlasmaInputFetcher interface from plasma.Keccak256Commitment to plasma.CommitmentData.
op-node/rollup/derive/plasma_data_source.go Updated comm field type in PlasmaDataSource struct to plasma.CommitmentData and adjusted commitment data decoding.
op-plasma/commitment.go, op-plasma/commitment_test.go Introduced CommitmentData interface, updated commitment types, and methods for handling commitment data with corresponding test suite.
op-plasma/daclient.go, op-plasma/daclient_test.go Updated DAClient functions to use CommitmentData and adjusted test cases for setting and getting commitments.
op-plasma/damgr.go Updated DAStorage interface and DA struct to use CommitmentData instead of Keccak256Commitment.
op-plasma/damock.go Added CommitmentType field, updated method parameters, and return types to utilize CommitmentData in various structs.

Recent Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 28f1c5a and 4755abb.
Files selected for processing (2)
  • op-node/rollup/derive/plasma_data_source_test.go (2 hunks)
  • op-plasma/commitment_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • op-node/rollup/derive/plasma_data_source_test.go
  • op-plasma/commitment_test.go

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

@trianglesphere trianglesphere left a comment

Choose a reason for hiding this comment

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

The design looks really good. I just found some small things

op-node/rollup/derive/plasma_data_source.go Outdated Show resolved Hide resolved
op-node/rollup/derive/plasma_data_source.go Outdated Show resolved Hide resolved
op-node/rollup/derive/plasma_data_source.go Outdated Show resolved Hide resolved
op-node/rollup/derive/plasma_data_source_test.go Outdated Show resolved Hide resolved
op-plasma/commitment.go Outdated Show resolved Hide resolved
op-plasma/commitment.go Outdated Show resolved Hide resolved
op-plasma/commitment.go Outdated Show resolved Hide resolved
op-plasma/commitment.go Outdated Show resolved Hide resolved
op-plasma/commitment.go Show resolved Hide resolved
op-plasma/daclient.go Outdated Show resolved Hide resolved
@axelKingsley axelKingsley added this pull request to the merge queue May 10, 2024
Merged via the queue into develop with commit 1a20fd9 May 10, 2024
70 checks passed
@axelKingsley axelKingsley deleted the axel/useGenericComm branch May 10, 2024 22:04
carterqw2 pushed a commit to celo-org/optimism that referenced this pull request May 29, 2024
* op-node: Generic Commitment

This is a generic commitment to be used by the op-node & op-batcher.

* abstract commitments to CommitmentData interface

* correct byte-stripping ; add tests ; finish wiring

* make GenericCommitment always verify

* correct action tests

* PR comments

* fix unit test

* remove fmt.Println

---------

Co-authored-by: Joshua Gutow <jgutow@oplabs.co>
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.

None yet

2 participants