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

Upgrade contract to Cairo 2.7 #549

Merged
merged 14 commits into from
Aug 21, 2024
Merged

Upgrade contract to Cairo 2.7 #549

merged 14 commits into from
Aug 21, 2024

Conversation

piniom
Copy link
Collaborator

@piniom piniom commented Aug 8, 2024

Changes also made here: cartridge-gg/argent-contracts-starknet#2

Summary by CodeRabbit

  • New Features

    • Enhanced event handling with a more flexible Event enum, introducing the new Upgraded variant.
    • Updated WebauthnSignature struct for streamlined serialization processes.
  • Improvements

    • Added an abigen! macro for improved interaction with smart contract events, enhancing usability and maintainability.

These changes significantly enhance the efficiency and clarity of the account SDK, benefiting developers working with event handling and smart contracts.

Copy link

vercel bot commented Aug 8, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
cartridge-starknet-react-next ✅ Ready (Inspect) Visit Preview Aug 21, 2024 4:22pm
docs ✅ Ready (Inspect) Visit Preview Aug 21, 2024 4:22pm
keychain ✅ Ready (Inspect) Visit Preview Aug 21, 2024 4:22pm
ui ✅ Ready (Inspect) Visit Preview Aug 21, 2024 4:22pm
ui-next ✅ Ready (Inspect) Visit Preview Aug 21, 2024 4:22pm

Copy link

coderabbitai bot commented Aug 21, 2024

Walkthrough

The updates primarily focus on refining event handling and serialization processes in the account_sdk. Key changes include the simplification of the WebauthnSignature struct by removing the sha256_implementation field, leading to cleaner serialization logic. Additionally, the Event enum now consolidates multiple event variants into a more flexible structure, enhancing maintainability. The controller module has been expanded with a new abigen! macro for improved contract interactions, enriching the overall functionality of the module.

Changes

Files Change Summary
packages/account_sdk/src/abigen/controller.rs - WebauthnSignature struct: Removed sha256_implementation field; updated serialization logic.
- Event enum: Simplified by removing ReentrancyGuardEvent and UpgradeEvent; added general Upgraded variant.
packages/account_sdk/src/abigen/mod.rs - Expanded controller module with abigen! macro for smart contract bindings; added type aliases and derived traits for enhanced functionality and usability.

Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c9785ab and a696cf8.

Files ignored due to path filters (4)
  • packages/account-wasm/pkg/account_wasm_bg.js is excluded by none and included by none
  • packages/account-wasm/pkg/account_wasm_bg.wasm is excluded by !**/*.wasm and included by none
  • packages/account-wasm/pkg/account_wasm_bg.wasm.d.ts is excluded by none and included by none
  • packages/keychain/src/utils/selectors.ts is excluded by none and included by none
Files selected for processing (1)
  • packages/account_sdk/src/abigen/controller.rs (15 hunks)
Additional comments not posted (1)
packages/account_sdk/src/abigen/controller.rs (1)

1550-1553: LGTM! Verify WebauthnSignature usage in the codebase.

The removal of the sha256_implementation field simplifies the struct and its serialization/deserialization logic.

Ensure that all instances of WebauthnSignature are updated to reflect this change.

Run the following script to verify the struct usage:

Verification successful

Verification Successful: WebauthnSignature Update Reflected Across Codebase

The removal of the sha256_implementation field from the WebauthnSignature struct has been correctly reflected throughout the codebase. All instances of WebauthnSignature have been updated accordingly, ensuring consistency and correctness. No further action is needed.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all instances of `WebauthnSignature` reflect the removal of `sha256_implementation`.

# Test: Search for the struct usage. Expect: No references to `sha256_implementation`.
rg --type rust -A 5 $'WebauthnSignature'

Length of output: 4354


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 Configuration 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

@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

Outside diff range, codebase verification and nitpick comments (1)
packages/account_sdk/src/abigen/mod.rs (1)

6-23: Missing Controller contract definition in JSON files.

The Controller contract definition is not found in the JSON files, which might lead to issues with the abigen! macro invocation. Verify the existence and correctness of the contract definition in the JSON files to ensure the macro functions as intended.

  • Ensure that the controller.contract_class.json file contains the correct Controller contract definition.
Analysis chain

Ensure correctness of abigen! macro invocation.

The abigen! macro is used to generate bindings for a smart contract. Verify that the contract name, JSON path, type aliases, and derived traits are correct and consistent with the rest of the codebase.

Run the following script to verify the correctness of the abigen! macro invocation:

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of the `abigen!` macro invocation.

# Test: Check if the specified JSON file exists. Expect: The file should exist.
fd 'controller.contract_class.json' --exec echo "JSON file exists: {}"

# Test: Search for the `Controller` contract definition. Expect: The contract should be defined.
rg --type json '"contract_name": "Controller"' -A 5

# Test: Verify the type aliases. Expect: The aliases should match the event definitions.
rg --type rust 'pub enum Event' -A 5

Length of output: 2194


Script:

#!/bin/bash
# Description: Further investigate the `Controller` contract definition.

# Test: Search for `Controller` contract definition in all JSON files.
rg '"Controller"' --type json -A 5

# Test: Search for `Controller` contract definition in all Rust files.
rg 'Controller' --type rust -A 5

Length of output: 24621

Comment on lines +1030 to +1036
ReentrancyGuardEvent(Event),
SessionEvent(SessionEvent),
ExternalOwnersEvent(ExternalOwnersEvent),
ExecuteFromOutsideEvents(OutsideExecutionEvent),
DelegateAccountEvents(DelegateAccountEvent),
SRC5Events(Src5ComponentEvent),
UpgradeableEvent(UpgradeEvent),
UpgradeableEvent(Event),
Copy link

Choose a reason for hiding this comment

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

Remove redundant ReentrancyGuardEvent and UpgradeableEvent variants.

The ReentrancyGuardEvent and UpgradeableEvent variants in the Event enum are redundant and should be removed to simplify the event handling logic.

Use this diff to remove the redundant variants:

 pub enum Event {
     TransactionExecuted(TransactionExecuted),
     MultipleOwnersEvent(MultipleOwnersEvent),
-    ReentrancyGuardEvent(Event),
     SessionEvent(SessionEvent),
     ExternalOwnersEvent(ExternalOwnersEvent),
     ExecuteFromOutsideEvents(OutsideExecutionEvent),
     DelegateAccountEvents(DelegateAccountEvent),
     SRC5Events(Src5ComponentEvent),
-    UpgradeableEvent(Event),
 }

Also applies to: 1050-1062, 1083-1119, 1149-1191

Comment on lines +1500 to +1503
return Ok(Event::UpgradeableEvent(Event::Upgraded(Upgraded { class_hash })));
}
Err(format!("Could not match any event from keys {:?}", event.keys))
}
Copy link

Choose a reason for hiding this comment

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

Consolidate event handling logic.

The try_from implementation for Event should consolidate event handling logic by removing redundant checks for ReentrancyGuardEvent and UpgradeableEvent.

Use this diff to simplify the try_from implementation:

 if selector
     == starknet::core::utils::get_selector_from_name("Upgraded")
         .unwrap_or_else(|_| panic!("Invalid selector for {}", "Upgraded"))
 {
     let mut key_offset = 0 + 1;
     let mut data_offset = 0;
     let class_hash = match cainome::cairo_serde::ClassHash::cairo_deserialize(
         &event.data,
         data_offset,
     ) {
         Ok(v) => v,
         Err(e) => {
             return Err(
                 format!(
                     "Could not deserialize field {} for {}: {:?}", "class_hash",
                     "Upgraded", e
                 ),
             );
         }
     };
     data_offset
         += cainome::cairo_serde::ClassHash::cairo_serialized_size(&class_hash);
     return Ok(Event::Upgraded(Upgraded { class_hash }));
 }

Committable suggestion was skipped due to low confidence.

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

Outside diff range, codebase verification and nitpick comments (1)
packages/account_sdk/src/abigen/controller.rs (1)

1030-1036: Incomplete Refactoring of Event Enum

The ReentrancyGuardEvent and UpgradeableEvent variants are still present in the Event enum in controller.rs, which contradicts the intended refactoring. These variants should be removed, and the Upgraded variant should be used consistently throughout the codebase.

  • File: packages/account_sdk/src/abigen/controller.rs
  • Lines: 1030-1036

Please ensure that all instances of the Event enum are updated to reflect these changes.

Analysis chain

LGTM! Verify Event enum usage in the codebase.

The removal of ReentrancyGuardEvent and UpgradeableEvent variants, and the addition of the Upgraded variant, simplifies the event handling logic.

Ensure that all instances of the Event enum are updated to reflect these changes.

Run the following script to verify the enum usage:

Also applies to: 1500-1503, 1551-1553

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all instances of `Event` reflect the removal of `ReentrancyGuardEvent` and `UpgradeableEvent`, and the addition of `Upgraded`.

# Test: Search for the enum usage. Expect: No references to `ReentrancyGuardEvent` and `UpgradeableEvent`, and correct usage of `Upgraded`.
rg --type rust -A 5 $'Event'

Length of output: 87361

@broody broody merged commit 3def9c0 into main Aug 21, 2024
13 checks passed
@broody broody deleted the cairo-2.7 branch August 21, 2024 17:41
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.

3 participants