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(katana): include salt in genesis accounts #3031

Merged
merged 2 commits into from
Feb 14, 2025

Conversation

kariy
Copy link
Member

@kariy kariy commented Feb 14, 2025

Summary by CodeRabbit

  • New Features

    • Enabled dynamic salt support for account creation and deployment, offering more flexible configuration during setup.
    • Introduced optional salt attributes into the genesis configuration, ensuring consistent account initialization.
  • Refactor

    • Simplified the account creation process by decoupling account instantiation from address retrieval.
    • Streamlined deployment logic to clearly differentiate between account types for a more intuitive provisioning experience.

Copy link

codecov bot commented Feb 14, 2025

Codecov Report

Attention: Patch coverage is 97.12230% with 4 lines in your changes missing coverage. Please review.

Project coverage is 56.33%. Comparing base (7c86593) to head (d412c03).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
crates/katana/primitives/src/genesis/allocation.rs 86.20% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3031      +/-   ##
==========================================
- Coverage   56.33%   56.33%   -0.01%     
==========================================
  Files         437      437              
  Lines       58891    58997     +106     
==========================================
+ Hits        33179    33235      +56     
- Misses      25712    25762      +50     

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

Copy link

coderabbitai bot commented Feb 14, 2025

Ohayo, sensei! Below is the updated summary of the changes:

Walkthrough

This pull request refactors the account creation and deployment processes across multiple modules. The changes separate account instantiation from address retrieval, introduce a dynamic salt parameter, and add a new salt field to various genesis account structures. Method signatures for account creation, deployment, and JSON conversion have been simplified and updated to reflect these enhancements.

Changes

File(s) Change Summary
bin/katana/src/cli/init/slot.rs, crates/katana/storage/provider/src/test_utils.rs Refactored account creation by removing tuple destructuring and retrieving the address via an added address() method.
crates/katana/chain-spec/src/dev.rs, crates/katana/chain-spec/src/rollup/utils.rs Introduced dynamic salt parameter for account deployment; updated method signatures in GenesisTransactionsBuilder and enhanced allocation test setups.
crates/katana/primitives/src/genesis/allocation.rs, crates/katana/primitives/src/genesis/json.rs Updated GenesisAccount & DevGenesisAccount: simplified creation methods to return only self, added a new salt field and address() method, and revised JSON serialization/deserialization to include an optional salt.

Possibly related PRs

Suggested labels

katana

Suggested reviewers

  • glihm

🪧 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: 2

🧹 Nitpick comments (1)
crates/katana/primitives/src/genesis/allocation.rs (1)

199-200: Consider adding more context to the DEFAULT_SALT documentation sensei.

While the comment mentions "backward compatible reason", it would be helpful to explain why this specific value was chosen.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7c86593 and 11419e0.

📒 Files selected for processing (6)
  • bin/katana/src/cli/init/slot.rs (1 hunks)
  • crates/katana/chain-spec/src/dev.rs (2 hunks)
  • crates/katana/chain-spec/src/rollup/utils.rs (8 hunks)
  • crates/katana/primitives/src/genesis/allocation.rs (4 hunks)
  • crates/katana/primitives/src/genesis/json.rs (10 hunks)
  • crates/katana/storage/provider/src/test_utils.rs (1 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
crates/katana/chain-spec/src/rollup/utils.rs

[warning] 227-229: crates/katana/chain-spec/src/rollup/utils.rs#L227-L229
Added lines #L227 - L229 were not covered by tests


[warning] 307-308: crates/katana/chain-spec/src/rollup/utils.rs#L307-L308
Added lines #L307 - L308 were not covered by tests

crates/katana/primitives/src/genesis/allocation.rs

[warning] 210-213: crates/katana/primitives/src/genesis/allocation.rs#L210-L213
Added lines #L210 - L213 were not covered by tests

🔇 Additional comments (13)
crates/katana/storage/provider/src/test_utils.rs (1)

56-56: Ohayo! LGTM sensei!

The code has been updated to use the simplified API for account creation, which aligns well with the new design.

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

74-82: Ohayo! LGTM sensei!

The code has been updated to use the simplified API for account creation, separating account creation from address retrieval, which improves code clarity.

crates/katana/primitives/src/genesis/allocation.rs (2)

194-195: Ohayo! Nice addition of the salt field sensei!

The salt field is properly documented and will help in deterministic account deployment.


227-230: Ohayo! Clean implementation of address calculation sensei!

The address calculation is properly implemented using Starknet's get_contract_address function.

crates/katana/chain-spec/src/rollup/utils.rs (2)

132-151: Ohayo! Nice refactor of the deploy method sensei!

The addition of the salt parameter improves the flexibility of contract deployment.


303-316:

❓ Verification inconclusive

Please add test coverage for GenesisAccountAlloc::Account handling sensei.

The static analysis indicates that the Account variant handling is not covered by tests.


🏁 Script executed:

#!/bin/bash
# Description: Check test coverage for Account variant handling
rg -A 5 'GenesisAccountAlloc::Account.*deploy_predeployed_account' -g '*test*.rs'

Length of output: 83


Ohayo sensei – Please add tests for the Account variant handling

It looks like our initial check for the Account variant in the test files didn’t return any results. Could you please verify manually (or run additional checks) that tests covering the GenesisAccountAlloc::Account branch in crates/katana/chain-spec/src/rollup/utils.rs (lines 303-316) are indeed missing? If they are absent, please add the appropriate tests to cover its behavior, ensuring proper verification of both deployment and balance transfer logic.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 307-308: crates/katana/chain-spec/src/rollup/utils.rs#L307-L308
Added lines #L307 - L308 were not covered by tests

crates/katana/chain-spec/src/dev.rs (3)

310-310: Ohayo! Test updates look good, sensei!

The test has been properly updated to include the new salt field with the default value.

Also applies to: 333-333


793-793: Test data structures are properly updated, sensei!

All test cases have been consistently updated to include the salt field with the default value.

Also applies to: 804-804, 815-815, 828-828


959-959: Test assertions are properly updated, sensei!

The test case correctly verifies the default salt value in the assertions.

crates/katana/primitives/src/genesis/json.rs (4)

159-159: Ohayo! Struct definition looks good, sensei!

The salt field is properly defined as an optional field with the correct type.


379-413: Account creation logic is well implemented, sensei!

The code elegantly handles both cases with and without salt, maintaining consistency across account types.


494-494: JSON conversion is properly updated, sensei!

The salt field is correctly included in the JSON conversion logic.

Also applies to: 506-506


1020-1020: Test data is properly updated, sensei!

The test case correctly includes the new salt field and verifies its optional nature.

Comment on lines +210 to 214
pub fn new_with_balance(public_key: Felt, class_hash: ClassHash, balance: U256) -> Self {
let mut account = Self::new(public_key, class_hash);
account.balance = Some(balance);
account
}
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

❓ Verification inconclusive

Ohayo! Please add test coverage for new_with_balance sensei.

The static analysis indicates that this method is not covered by tests.


🏁 Script executed:

#!/bin/bash
# Description: Check test coverage for new_with_balance method
rg -A 5 'new_with_balance.*balance: U256' -g '*test*.rs'

Length of output: 58


Ohayo sensei! It looks like the new new_with_balance method (at crates/katana/primitives/src/genesis/allocation.rs, lines 210–214) isn’t covered by any tests yet. The grep search didn’t return any references in our test files, so please add proper test coverage to verify that:

  • A new instance correctly sets the balance.
  • The method integrates well with the rest of the account creation API.

Once tests are added, we can be confident that the functionality behaves as expected.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 210-213: crates/katana/primitives/src/genesis/allocation.rs#L210-L213
Added lines #L210 - L213 were not covered by tests

Comment on lines +227 to +229
fn deploy_predeployed_account(&self, salt: Felt, public_key: Felt) -> ContractAddress {
self.deploy(DEFAULT_ACCOUNT_CLASS_HASH, vec![public_key], salt)
}
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

❓ Verification inconclusive

Please add test coverage for deploy_predeployed_account sensei.

The static analysis indicates that this method is not covered by tests.


🏁 Script executed:

#!/bin/bash
# Description: Check test coverage for deploy_predeployed_account method
rg -A 5 'deploy_predeployed_account.*public_key: Felt' -g '*test*.rs'

Length of output: 71


Ohayo sensei! It appears that the deploy_predeployed_account method isn’t currently covered by any tests. Since our verification script didn’t turn up any references in the test files, please add the necessary test coverage to ensure this functionality behaves as expected.


🏁 Script executed:

#!/bin/bash
# Searching for any references to deploy_predeployed_account in test files
rg -n 'deploy_predeployed_account' -g '*test*.rs'

Length of output: 49


Ohayo sensei! It looks like the deploy_predeployed_account method isn’t covered by any tests yet. Could you add some test cases for this function? Ensuring proper test coverage here will help maintain robust functionality for our rollup deployment logic.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 227-229: crates/katana/chain-spec/src/rollup/utils.rs#L227-L229
Added lines #L227 - L229 were not covered by tests

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 (1)
crates/katana/primitives/src/genesis/allocation.rs (1)

199-200: Ohayo sensei! Please document the rationale behind the default salt value.

The hardcoded value "666" seems arbitrary. Consider adding a comment explaining why this specific value was chosen and its significance for backward compatibility.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 11419e0 and d412c03.

📒 Files selected for processing (2)
  • crates/katana/chain-spec/src/rollup/utils.rs (15 hunks)
  • crates/katana/primitives/src/genesis/allocation.rs (7 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
crates/katana/primitives/src/genesis/allocation.rs

[warning] 210-213: crates/katana/primitives/src/genesis/allocation.rs#L210-L213
Added lines #L210 - L213 were not covered by tests

🔇 Additional comments (7)
crates/katana/primitives/src/genesis/allocation.rs (3)

210-214: Ohayo sensei! Please add test coverage for new_with_balance.

The function lacks test coverage, which could lead to undetected issues.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 210-213: crates/katana/primitives/src/genesis/allocation.rs#L210-L213
Added lines #L210 - L213 were not covered by tests


228-230: LGTM!

The address calculation is correctly implemented using the standard pattern.


284-291: LGTM!

The account generation logic correctly handles both cases with and without balance.

crates/katana/chain-spec/src/rollup/utils.rs (4)

132-151: LGTM!

The contract deployment logic correctly uses the provided salt parameter.


189-225: LGTM!

The dev account deployment logic correctly uses the account's salt.


227-229: Ohayo sensei! Please add test coverage for deploy_predeployed_account.

The function lacks test coverage, which could lead to undetected issues.


291-318: LGTM!

The account building logic correctly handles both dev and regular accounts.

@kariy kariy merged commit b7a4414 into main Feb 14, 2025
15 checks passed
@kariy kariy deleted the katana/fix-paymaster-not-deployed branch February 14, 2025 16:27
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