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

feat(katana): settlement layer initialization flow improvement #2926

Merged
merged 1 commit into from
Jan 18, 2025

Conversation

kariy
Copy link
Member

@kariy kariy commented Jan 18, 2025

Currently we're hardcoding the program's config hash, which is terribly wrong as it needs to actually be computed according to the chain's configuration itself.

This PR also includes assertion checks at the end of deployment to make sure the contract has actually been initialized with the intended value (ie program hash, config hash, and fact registry address).

@kariy kariy changed the title feat(katana): compute config hash correctly feat(katana): settlement layer initialization flow improvement Jan 18, 2025
Copy link

coderabbitai bot commented Jan 18, 2025

Walkthrough

Ohayo, sensei! This pull request introduces significant changes to the Katana project's dependency management and contract deployment mechanism. The modifications span across multiple files, focusing on enhancing the settlement contract deployment process, adding new dependency management strategies, and improving contract class handling. The changes include updating Cargo.toml, introducing a new deployment module, and implementing more robust contract class conversion and initialization methods.

Changes

File Change Summary
bin/katana/Cargo.toml - Added katana-rpc-types, rand, and thiserror dependencies
- Removed serde_json dependency
- Added rstest to dev-dependencies
bin/katana/src/cli/init/deployment.rs - New module for settlement contract deployment
- Added deploy_settlement_contract function
- Introduced ContractInitError enum
- Added helper functions for contract declaration and configuration
bin/katana/src/cli/init/mod.rs - Added deployment module
- Removed previous contract initialization functions
- Updated deployment logic
crates/katana/primitives/src/class.rs - Added ContractClassFromStrError
- Implemented FromStr trait for ContractClass
crates/katana/rpc/rpc-types/src/class.rs - Added TryFrom implementations for contract class conversions

Sequence Diagram

sequenceDiagram
    participant Account
    participant DeploymentModule
    participant Blockchain
    
    Account->>DeploymentModule: deploy_settlement_contract()
    DeploymentModule->>Blockchain: Check contract class declaration
    alt Class not declared
        DeploymentModule->>Blockchain: Declare contract class
    end
    DeploymentModule->>Blockchain: Deploy contract
    DeploymentModule->>Blockchain: Initialize contract
    Blockchain-->>DeploymentModule: Return contract address
    DeploymentModule-->>Account: Return contract address
Loading

Possibly related PRs

Suggested reviewers

  • glihm

Ohayo and happy coding, sensei! 🍵🥷


🪧 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.
    • 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 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 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 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. (Beta)
  • @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.

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

@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

🧹 Nitpick comments (3)
bin/katana/src/cli/init/mod.rs (2)

162-163: Ohayo, sensei! Possible Typo in Comment: 'L1c' instead of 'L1'

In the comment, it mentions "The core settlement contract on L1c." Did you mean "L1" instead of "L1c"?


173-174: Ohayo, sensei! Address the TODO: Add validation for settlement contract

There's a TODO at lines 173~ and 174~ to add a check to ensure the provided contract is indeed a valid settlement contract. Implementing this validation will prevent potential misconfigurations.

Would you like me to help implement this check or open a new GitHub issue to track this task?

bin/katana/src/cli/init/deployment.rs (1)

140-141: Ohayo, sensei! Consider parameterizing the fee token address

The fee token address is currently hardcoded as 0x2e7442625bab778683501c0eadbc1ea17b3535da040a12ac7d281066e915eea. If the fee token may vary between deployments or environments, consider parameterizing this value to enhance flexibility and avoid hardcoding.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 74ccf13 and 6082e2b.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (5)
  • bin/katana/Cargo.toml (2 hunks)
  • bin/katana/src/cli/init/deployment.rs (1 hunks)
  • bin/katana/src/cli/init/mod.rs (2 hunks)
  • crates/katana/primitives/src/class.rs (2 hunks)
  • crates/katana/rpc/rpc-types/src/class.rs (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: fmt
🔇 Additional comments (7)
bin/katana/src/cli/init/deployment.rs (1)

110-114: Ohayo, sensei! Verify initialization of contract's constructor parameters

Currently, the constructor arguments state_root, block_number, and block_hash are set to Felt::ZERO. Please verify if these values are appropriate or if they should be initialized with actual blockchain state values to correctly represent the chain's initial state.

crates/katana/primitives/src/class.rs (1)

70-95: Ohayo, sensei! Implemented FromStr for ContractClass successfully

The implementation correctly allows parsing ContractClass from a string, handling both Sierra and Legacy contract classes. Error handling with ContractClassFromStrError is appropriate.

crates/katana/rpc/rpc-types/src/class.rs (2)

207-215: Implementation is consistent with Sierra class conversion, sensei!

The conversion follows the same pattern as the Sierra class implementation, maintaining consistency throughout the codebase.


187-195: Ohayo! Implementation looks good, sensei!

The conversion implementation follows the established pattern in the codebase. While using JSON as an intermediate step isn't the most performant approach, it's acceptable since these conversions are not meant for hot paths.

Let's verify if this conversion is used in any performance-critical paths:

✅ Verification successful

Ohayo! Implementation is safe and sound, sensei!

The conversion from RpcSierraContractClass to FlattenedSierraClass is only used in RPC type conversions and not in any performance-critical paths. The JSON serialization approach is appropriate for this use case.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for usage of this conversion in potentially hot paths
rg -A 5 "TryFrom<RpcSierraContractClass>\s+for\s+FlattenedSierraClass" 

Length of output: 605


Script:

#!/bin/bash
# Search for try_from/into usage with these types
rg -B 2 -A 2 "try_from\(<.*RpcSierraContractClass.*\)|\.into\(\)|FlattenedSierraClass::try_from"

# Search for RpcSierraContractClass usage
rg "RpcSierraContractClass" --type rust

# Search for files containing both types to find potential conversion spots
rg -l "RpcSierraContractClass.*FlattenedSierraClass|FlattenedSierraClass.*RpcSierraContractClass"

Length of output: 66590

bin/katana/Cargo.toml (3)

14-14: LGTM! katana-rpc-types dependency added correctly, sensei!

The addition of katana-rpc-types aligns with the new RPC type conversions implemented in class.rs.


37-37: LGTM! rstest added to dev-dependencies, sensei!

The addition of rstest for testing is appropriate.


25-25: Verify the necessity of new dependencies, sensei!

The addition of rand and thiserror dependencies:

  • thiserror is justified for error handling
  • rand seems unrelated to the PR's objective of computing config hash correctly

Let's check if rand is used in the changes:

Also applies to: 30-30

✅ Verification successful

Ohayo! The rand dependency is justified, sensei!

The PR uses rand to generate a salt value for the config hash computation, which is a standard security practice to ensure hash uniqueness and prevent collisions.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for rand usage in the codebase
rg -l "use.*rand::" 

Length of output: 518


Script:

#!/bin/bash
# Check PR changes for rand usage
git diff HEAD~1 | rg -i "rand"

Length of output: 124

Copy link

codecov bot commented Jan 18, 2025

Codecov Report

Attention: Patch coverage is 6.73575% with 180 lines in your changes missing coverage. Please review.

Project coverage is 55.81%. Comparing base (ec00eca) to head (6082e2b).
Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
bin/katana/src/cli/init/deployment.rs 7.60% 158 Missing ⚠️
crates/katana/rpc/rpc-types/src/class.rs 0.00% 10 Missing ⚠️
crates/katana/primitives/src/class.rs 0.00% 8 Missing ⚠️
bin/katana/src/cli/init/mod.rs 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2926      +/-   ##
==========================================
- Coverage   55.99%   55.81%   -0.19%     
==========================================
  Files         449      444       -5     
  Lines       58020    57308     -712     
==========================================
- Hits        32491    31988     -503     
+ Misses      25529    25320     -209     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kariy kariy merged commit 57cfe1e into main Jan 18, 2025
13 of 15 checks passed
@kariy kariy deleted the katana/config-hash branch January 18, 2025 21:29
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.

1 participant