Skip to content

feat(standards): add guardian component#3125

Open
onurinanc wants to merge 3 commits into
nextfrom
feat-guardian-component
Open

feat(standards): add guardian component#3125
onurinanc wants to merge 3 commits into
nextfrom
feat-guardian-component

Conversation

@onurinanc

Copy link
Copy Markdown
Collaborator

Closes: #3103

@partylikeits1983 partylikeits1983 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks great! One minor comment about if its possible to remove pub from certain procedures in the "internal procedures" section of the guardian masm file.

#! - is_sender_guardian is 1 if the note sender is the guardian, otherwise 0.
#!
#! Invocation: exec
pub proc is_sender_guardian

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just a question, could this be an internal procedure?

Also since this procedure is in the "internal procedures" section, maybe it makes sense to make it an internal procedure or move it lower in this file. This same comment applies to assert_sender_is_guardian procedure.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thank you for the catch! I think this procedure shouldn't be in the internal procedures part, instead it should be in the public procedures part. Then, the procedures exposed to the account component should be in the external procedures section.

@PhilippGackstatter PhilippGackstatter left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me. Left a few optional comments.

#! - the note sender is not the guardian.
#!
#! Invocation: exec
pub proc assert_sender_is_guardian

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: This procedure is also in the internal section -> move to "PUBLIC INTERFACE" section.

Comment on lines +166 to +169
# Detect explicit clear via the zero address. The zero address is not a valid account ID, so
# we must check for it before validating.
dup.1 eq.0 dup.1 eq.0 and
# => [is_zero_address, new_guardian_suffix, new_guardian_prefix, pad(14)]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: Should we add account_id::testz (does not consume the inputs) to replace this? I think we could use this procedure in other places now or in the future, so I think that makes sense.

Comment on lines +177 to +184
push.0.0
# => [0, 0, new_guardian_suffix, new_guardian_prefix, pad(14)]

movup.3 movup.3
# => [new_guardian_suffix, new_guardian_prefix, 0, 0, pad(14)]

exec.save_guardian_info
# => [pad(16)]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: Consider building the word in save_guardian_info.

Comment on lines +44 to +47
/// ```text
/// Word: [guardian_suffix, guardian_prefix, 0, 0]
/// word[0] word[1] word[2] word[3]
/// ```

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// ```text
/// Word: [guardian_suffix, guardian_prefix, 0, 0]
/// word[0] word[1] word[2] word[3]
/// ```
/// ```text
/// [guardian_suffix, guardian_prefix, 0, 0]
/// ```

Nit: I think this matches the layout we use in most places.

pub struct Guardian {
/// The current guardian. `None` when no guardian is assigned.
guardian: Option<AccountId>,
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think the name is fine in principle, but since it is technically distinct from the Miden Guardian, I wonder if we should choose a different name. Then again, this guardian will probably be the same entity as the Miden Guardian most of the time, so maybe that's okay?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

In my mind, Miden Guardian should use this component eventually for some use cases such as freezing procedures, but I'm not sure if it is planned to support this as a feature or not. I think @bobbinth was suggesting to change this name to something else.

Comment on lines +91 to +99
/// Reconstructs a [`Guardian`] from a raw storage word.
///
/// Format: `[guardian_suffix, guardian_prefix, 0, 0]`
pub fn try_from_word(word: Word) -> Result<Self, GuardianError> {
let guardian = account_id_from_felt_pair(word[0], word[1])
.map_err(GuardianError::InvalidGuardianId)?;

Ok(Self { guardian })
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I wonder if we should use the same layout as AccountIdKey. It's not technically a key, but the main advantage is that we could reuse the logic of that type in a few places (except that we allow zero IDs here, which the key doesn't) and also layout consistency.

Comment on lines +125 to +128
/// Returns the current guardian, or `None` if no guardian is assigned.
pub fn guardian(&self) -> Option<AccountId> {
self.guardian
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: guardian.guradian() is a bit redundant. Maybe this could be just id or account_id?

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.

add Guardian component for emergency switch and AccessManager features

3 participants