-
Notifications
You must be signed in to change notification settings - Fork 173
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
Bump slot
( account_sdk
)
#2493
Conversation
WalkthroughOhayo, sensei! The recent changes focus on updates to the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Controller
participant PolicyManager
User->>Controller: Request to create session
Controller->>PolicyManager: Retrieve policies
PolicyManager-->>Controller: Return policies
Controller->>Controller: Compare new policies with existing
Controller->>Controller: Log session details
Controller-->>User: Session created successfully
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this 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 and nitpick comments (1)
bin/sozo/src/commands/options/account/controller.rs (1)
Line range hint
181-184
: Consider includingPublic
functions in policy generation.Currently, only functions with
StateMutability::External
are included in policies. IfPublic
functions should also be accessible, consider including them to expand the policy coverage.Apply this diff to include
Public
functions:fn policies_from_abis( policies: &mut Vec<PolicyMethod>, contract_tag: &str, contract_address: Felt, entries: &[AbiEntry], ) { for entry in entries { match entry { AbiEntry::Function(f) => { - if let StateMutability::External = f.state_mutability { + if matches!(f.state_mutability, StateMutability::External | StateMutability::Public) { let policy = PolicyMethod { target: contract_address, method: f.name.to_string(), }; trace!( tag = contract_tag, target = format!("{:#x}", policy.target), method = %policy.method, "Adding policy" ); policies.push(policy); } }
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
⛔ Files ignored due to path filters (1)
Cargo.lock
is excluded by!**/*.lock
📒 Files selected for processing (2)
- Cargo.toml (1 hunks)
- bin/sozo/src/commands/options/account/controller.rs (4 hunks)
✅ Files skipped from review due to trivial changes (1)
- Cargo.toml
🔇 Additional comments (3)
bin/sozo/src/commands/options/account/controller.rs (3)
11-11
: Ohayo, sensei! Correctly updated import statement.The import now uses
Policy
andProvedPolicy
, reflecting the change fromAllowedMethod
. This ensures compatibility with the new policy structure.
77-77
: Ohayo, sensei! Logging existing session details properly.The trace statement now correctly logs the
expires_at
and the number of policies in the existing session, aiding in debugging and transparency.
88-90
: Ohayo, sensei! Policies have changed, creating a new session.Good job updating the logging to reflect the counts of new and existing policies. This helps in tracking policy updates effectively.
.map(|p| Policy::new(p.target, get_selector_from_name(&p.method).unwrap())) | ||
.collect::<Vec<Policy>>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential panic due to unwrap()
in get_selector_from_name
.
Using unwrap()
can cause a panic if get_selector_from_name(&p.method)
fails to find a selector for a given method name.
Consider handling the potential error to prevent unexpected panics.
Apply this diff to handle the error gracefully:
let new_policies = new_policies
.iter()
- .map(|p| Policy::new(p.target, get_selector_from_name(&p.method).unwrap()))
+ .filter_map(|p| {
+ match get_selector_from_name(&p.method) {
+ Ok(selector) => Some(Policy::new(p.target, selector)),
+ Err(e) => {
+ // Log the error and skip this policy
+ warn!(method = %p.method, "Could not get selector: {}", e);
+ None
+ }
+ }
+ })
.collect::<Vec<Policy>>();
📝 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.
.map(|p| Policy::new(p.target, get_selector_from_name(&p.method).unwrap())) | |
.collect::<Vec<Policy>>(); | |
let new_policies = new_policies | |
.iter() | |
.filter_map(|p| { | |
match get_selector_from_name(&p.method) { | |
Ok(selector) => Some(Policy::new(p.target, selector)), | |
Err(e) => { | |
// Log the error and skip this policy | |
warn!(method = %p.method, "Could not get selector: {}", e); | |
None | |
} | |
} | |
}) | |
.collect::<Vec<Policy>>(); |
let new_policies_root = MerkleTree::compute_root(hashes[0], new_policies[0].proof.clone()); | ||
new_policies_root == session_info.session.authorization_root |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible index out-of-bounds panic when computing Merkle root.
Accessing hashes[0]
and new_policies[0]
without checking if the vectors are non-empty can lead to a panic if they are empty.
Ensure that the vectors are not empty before accessing the first element.
Apply this diff to add a safety check:
+ if hashes.is_empty() || new_policies.is_empty() {
+ warn!("No policies available to compute Merkle root.");
+ return false;
+ }
let new_policies_root = MerkleTree::compute_root(hashes[0], new_policies[0].proof.clone());
Committable suggestion was skipped due to low confidence.
update to adapt to the new changes from
account_sdk
Summary by CodeRabbit
AllowedMethod
toPolicy
, improving clarity and functionality.