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

fix: validate tx chain id #126

Merged
merged 3 commits into from
Jul 11, 2024
Merged

fix: validate tx chain id #126

merged 3 commits into from
Jul 11, 2024

Conversation

namn-grg
Copy link
Contributor

@namn-grg namn-grg commented Jul 9, 2024

fixes #124

Summary by CodeRabbit

  • New Features

    • Added asynchronous method to retrieve chain ID (get_chain_id).
    • Introduced validation for transaction chain ID in InclusionRequest.
    • Added chain ID field to ExecutionState with corresponding retrieval method.
  • Improvements

    • Enhanced error handling with new ChainIdMismatch variant in ValidationError.
  • Bug Fixes

    • Improved state management and validation for chain ID in ExecutionState.

These updates enhance the reliability and functionality of the system by improving chain ID management and validation processes.

Copy link
Contributor

coderabbitai bot commented Jul 9, 2024

Walkthrough

The changes enhance the bolt-sidecar module by ensuring the correct chain ID validation for Ethereum transactions. This includes adding methods to retrieve, validate, and compare chain IDs in various components, thus preventing transactions with incorrect IDs. The modifications add robustness to error handling and state management, specifically addressing a bug when an invalid chain ID is sent in a transaction.

Changes

File Path Change Summary
bolt-sidecar/src/client/rpc.rs Added get_chain_id method to RpcClient for retrieving chain ID asynchronously.
bolt-sidecar/src/primitives/commitment.rs Added validate_chain_id method to InclusionRequest to compare the transaction chain ID with a given chain ID.
bolt-sidecar/src/state/execution.rs Introduced ChainIdMismatch variant in ValidationError, added chain_id field to ExecutionState, and included methods for initializing and validating chain ID.
bolt-sidecar/src/state/fetcher.rs Added get_chain_id method to StateFetcher trait and implemented it in the StateClient struct.

Assessment against linked issues

Objective Addressed Explanation
Validate chain_id when committing in ExecutionState::try_commit (Issue #124)

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.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @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

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 6091199 and 9b6fd3f.

Files selected for processing (4)
  • bolt-sidecar/src/client/rpc.rs (1 hunks)
  • bolt-sidecar/src/primitives/commitment.rs (1 hunks)
  • bolt-sidecar/src/state/execution.rs (5 hunks)
  • bolt-sidecar/src/state/fetcher.rs (2 hunks)
Additional comments not posted (8)
bolt-sidecar/src/primitives/commitment.rs (1)

46-53: LGTM! Add tests for the new method.

The validate_chain_id method is correctly implemented.

However, ensure that unit tests are added to verify its functionality.

bolt-sidecar/src/state/fetcher.rs (2)

42-42: LGTM!

The get_chain_id method is correctly added to the StateFetcher trait.


183-185: LGTM! Add tests for the new method.

The get_chain_id method is correctly implemented in the StateClient struct.

However, ensure that unit tests are added to verify its functionality.

bolt-sidecar/src/client/rpc.rs (1)

36-39: LGTM! Add tests for the new method.

The get_chain_id method is correctly implemented in the RpcClient struct.

However, ensure that unit tests are added to verify its functionality.

bolt-sidecar/src/state/execution.rs (4)

40-42: LGTM!

The ChainIdMismatch error variant is correctly added to the ValidationError enum.


85-86: LGTM!

The chain_id field is correctly added to the ExecutionState struct.


117-120: LGTM!

The chain_id method is correctly implemented in the ExecutionState struct.


151-154: LGTM! Add tests for the new validation logic.

The chain ID validation logic is correctly implemented in the try_commit method.

However, ensure that unit tests are added to verify its functionality.

Comment on lines 99 to 104
slot: 0,
account_states: HashMap::new(),
block_templates: HashMap::new(),
chain_id: client.get_chain_id().await?,
client,
})
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another way to do this can be to pass the chain ID value from config as a parameter while initializing the execution state, which felt to me as a dirty/ un-clean way.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah this is cleaner, great job

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

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 9b6fd3f and fd82250.

Files selected for processing (1)
  • bolt-sidecar/src/state/execution.rs (5 hunks)
Additional comments not posted (5)
bolt-sidecar/src/state/execution.rs (5)

40-42: LGTM! ValidationError enum extended with ChainIdMismatch

The addition of ChainIdMismatch to ValidationError is appropriate for handling chain ID mismatches.


85-86: LGTM! ExecutionState struct extended with chain_id

The addition of the chain_id field to ExecutionState is appropriate for managing chain ID validation.


102-102: LGTM! ExecutionState::new method initializes chain_id

The initialization of the chain_id field in the new method is appropriate for ensuring that the chain_id is set when the ExecutionState is created.


117-119: LGTM! ExecutionState::chain_id method added

The addition of the chain_id method is appropriate for retrieving the chain_id field.


133-136: LGTM! ExecutionState::try_commit method validates chain_id

The addition of the chain ID validation in the try_commit method is appropriate for ensuring that transactions are processed with the correct chain ID.

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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between fd82250 and 3646323.

Files selected for processing (1)
  • bolt-sidecar/src/state/execution.rs (4 hunks)
Additional comments not posted (2)
bolt-sidecar/src/state/execution.rs (2)

40-42: Good addition of ChainIdMismatch variant.

The ChainIdMismatch variant is correctly added to the ValidationError enum with an appropriate error message.


85-86: Good addition of chain_id field.

The chain_id field is correctly added to the ExecutionState struct and initialized in the new method.

Also applies to: 102-102

bolt-sidecar/src/state/execution.rs Show resolved Hide resolved
Copy link
Contributor

@thedevbirb thedevbirb left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@merklefruit merklefruit left a comment

Choose a reason for hiding this comment

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

LGTM!

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.

bug(sidecar): validate chain_id when accepting a commitment request
3 participants