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

Walnut: Enable multi-class verification via single API request #2456

Merged
merged 3 commits into from
Sep 23, 2024

Conversation

barabanovro
Copy link
Contributor

@barabanovro barabanovro commented Sep 20, 2024

Description

This PR optimizes the Walnut verification process, enabling verification through a single API request.

Tests

  • Yes
  • No, because they aren't needed
  • No, because I need help

Added to documentation?

  • README.md
  • Dojo Book
  • No documentation needed

Checklist

  • I've formatted my code (scripts/prettier.sh, scripts/rust_fmt.sh, scripts/cairo_fmt.sh)
  • I've linted my code (scripts/clippy.sh, scripts/docs.sh)
  • I've commented my code
  • I've requested a review after addressing the comments

Summary by CodeRabbit

  • New Features
    • Enhanced verification process with improved data handling for class names and hashes.
  • Bug Fixes
    • Refactored verification function to streamline payload processing and result handling.
  • Chores
    • Updated dependencies and workspace configuration in the project setup.

Copy link

codecov bot commented Sep 20, 2024

Codecov Report

Attention: Patch coverage is 0% with 13 lines in your changes missing coverage. Please review.

Project coverage is 68.47%. Comparing base (60c1575) to head (476dfa0).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
crates/sozo/walnut/src/verification.rs 0.00% 13 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2456      +/-   ##
==========================================
+ Coverage   68.45%   68.47%   +0.01%     
==========================================
  Files         368      368              
  Lines       48176    48162      -14     
==========================================
  Hits        32979    32979              
+ Misses      15197    15183      -14     

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

@barabanovro barabanovro marked this pull request as ready for review September 20, 2024 11:21
Copy link

coderabbitai bot commented Sep 20, 2024

Walkthrough

Ohayo, sensei! The recent changes involve updates to the Cargo.toml file, specifically the removal of the futures crate from the workspace configuration. Additionally, the verification.rs file has undergone significant refactoring, particularly the walnut_verify_migration_strategy function, which now features enhanced payload handling. The VerificationPayload structure has been modified to use vectors for class names and hashes, improving data management.

Changes

File Change Summary
crates/sozo/walnut/Cargo.toml Removed workspace declaration for the futures crate.
crates/sozo/walnut/src/verification.rs Refactored walnut_verify_migration_strategy function; updated VerificationPayload structure to use vectors for class names and hashes; renamed verify_class to verify_classes.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant VerificationService
    participant PayloadHandler

    User->>VerificationService: Request verification
    VerificationService->>PayloadHandler: Handle payload
    PayloadHandler->>VerificationService: Return processed data
    VerificationService-->>User: Send verification result
Loading

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>, 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 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: 3

Outside diff range and nitpick comments (1)
crates/sozo/walnut/src/verification.rs (1)

Line range hint 113-125: Add unit tests for verify_classes function

Ohayo, sensei! The new verify_classes function is key to the multi-class verification feature. Adding unit tests will help ensure it correctly handles various scenarios, including success and error cases.

Tools
GitHub Check: codecov/patch

[warning] 113-113: crates/sozo/walnut/src/verification.rs#L113
Added line #L113 was not covered by tests

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 82a23a5 and a8e1048.

Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing (2)
  • crates/sozo/walnut/Cargo.toml (0 hunks)
  • crates/sozo/walnut/src/verification.rs (2 hunks)
Files not reviewed due to no reviewable changes (1)
  • crates/sozo/walnut/Cargo.toml
Additional context used
GitHub Check: codecov/patch
crates/sozo/walnut/src/verification.rs

[warning] 63-64: crates/sozo/walnut/src/verification.rs#L63-L64
Added lines #L63 - L64 were not covered by tests


[warning] 71-72: crates/sozo/walnut/src/verification.rs#L71-L72
Added lines #L71 - L72 were not covered by tests


[warning] 78-79: crates/sozo/walnut/src/verification.rs#L78-L79
Added lines #L78 - L79 were not covered by tests


[warning] 82-83: crates/sozo/walnut/src/verification.rs#L82-L83
Added lines #L82 - L83 were not covered by tests


[warning] 85-88: crates/sozo/walnut/src/verification.rs#L85-L88
Added lines #L85 - L88 were not covered by tests


[warning] 113-113: crates/sozo/walnut/src/verification.rs#L113
Added line #L113 was not covered by tests

Additional comments not posted (3)
crates/sozo/walnut/src/verification.rs (3)

71-72: Ensure correct pairing of class names and hashes

Ohayo, sensei! When pushing data into class_names and class_hashes, make sure each class name corresponds to the correct class hash. This will prevent any mismatches during the verification process.

Tools
GitHub Check: codecov/patch

[warning] 71-72: crates/sozo/walnut/src/verification.rs#L71-L72
Added lines #L71 - L72 were not covered by tests


78-79: Consistency in model class data

Ohayo, sensei! Similar to the contracts, verify that model class_names and class_hashes are accurately paired when added to their respective vectors.

Tools
GitHub Check: codecov/patch

[warning] 78-79: crates/sozo/walnut/src/verification.rs#L78-L79
Added lines #L78 - L79 were not covered by tests


82-83: Initialization of VerificationPayload is appropriate

Ohayo, sensei! Constructing the VerificationPayload with vectors for class_names and class_hashes aligns with the updated verification approach.

Tools
GitHub Check: codecov/patch

[warning] 82-83: crates/sozo/walnut/src/verification.rs#L82-L83
Added lines #L82 - L83 were not covered by tests

Comment on lines +63 to +64
let mut class_names = Vec::new();
let mut class_hashes = Vec::new();
Copy link

Choose a reason for hiding this comment

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

Add unit tests for the initialization of class vectors

Ohayo, sensei! The new vectors class_names and class_hashes are essential for the multi-class verification process. Please consider adding tests to ensure they are initialized and populated correctly.

Tools
GitHub Check: codecov/patch

[warning] 63-64: crates/sozo/walnut/src/verification.rs#L63-L64
Added lines #L63 - L64 were not covered by tests

Comment on lines +102 to +105
/// The names of the classes we want to verify together with the selector.
pub class_names: Vec<String>,
/// The hashes of the Sierra classes.
pub class_hashes: Vec<String>,
Copy link

Choose a reason for hiding this comment

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

Update documentation for VerificationPayload structure

Ohayo, sensei! The VerificationPayload now uses vectors for class_names and class_hashes. Please update any associated documentation or comments to reflect these changes for clarity.

Comment on lines +85 to +88
// Send verification request
match verify_classes(verification_payload, &api_url, &api_key).await {
Ok(message) => ui.print(subtitle(message)),
Err(e) => ui.print(subtitle(e.to_string())),
Copy link

Choose a reason for hiding this comment

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

Propagate errors from the verification request

Ohayo, sensei! Currently, if verify_classes returns an error, it's printed but not propagated. Consider returning the error to allow upstream handling and maintain proper error flow.

Apply this diff to propagate the error:

-match verify_classes(verification_payload, &api_url, &api_key).await {
-    Ok(message) => ui.print(subtitle(message)),
-    Err(e) => ui.print(subtitle(e.to_string())),
-}
+let message = verify_classes(verification_payload, &api_url, &api_key).await?;
+ui.print(subtitle(message));
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Send verification request
match verify_classes(verification_payload, &api_url, &api_key).await {
Ok(message) => ui.print(subtitle(message)),
Err(e) => ui.print(subtitle(e.to_string())),
// Send verification request
let message = verify_classes(verification_payload, &api_url, &api_key).await?;
ui.print(subtitle(message));
Tools
GitHub Check: codecov/patch

[warning] 85-88: crates/sozo/walnut/src/verification.rs#L85-L88
Added lines #L85 - L88 were not covered by tests

@kariy kariy changed the title Enable multi-class verification via single API request Walnut: Enable multi-class verification via single API request Sep 23, 2024
@kariy
Copy link
Member

kariy commented Sep 23, 2024

@barabanovro pls rebase on main

@barabanovro
Copy link
Contributor Author

@kariy Done!

@kariy kariy merged commit b598b07 into dojoengine:main Sep 23, 2024
14 of 15 checks passed
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