-
Notifications
You must be signed in to change notification settings - Fork 124
Rename psm to guardian
#2666
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
Open
MCarlomagno
wants to merge
9
commits into
0xMiden:next
Choose a base branch
from
MCarlomagno:rename-psm-to-guardian
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Rename psm to guardian
#2666
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
bd75f28
chore: rename from PSM to Guardian
MCarlomagno bcc3a7c
Merge branch 'next' into rename-psm-to-guardian
MCarlomagno 73401f0
fix: prefer state guardian in comments
MCarlomagno 1b268fc
fix: rename guardian multisig to guarded multisig
MCarlomagno ff4420b
Merge remote-tracking branch 'origin/next' into rename-psm-to-guardian
MCarlomagno 3a82854
fix: restore changelog note and apply nightly formatting
MCarlomagno 8e9e966
fix: move guardian rename changelog notes to v0.15
MCarlomagno cac1568
style: clarify guardian masm comments
MCarlomagno ae3d1f0
fix: comment
MCarlomagno File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
162 changes: 162 additions & 0 deletions
162
crates/miden-standards/asm/standards/auth/guardian.masm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,162 @@ | ||
| # State Guardian account component. | ||
| # This component is composed into account auth flows especially for multisig and adds | ||
| # an extra signature check by a dedicated guardian signer. | ||
| # | ||
| # A state guardian can help coordinate state availability for private accounts. | ||
|
|
||
| use miden::protocol::auth::AUTH_UNAUTHORIZED_EVENT | ||
| use miden::protocol::native_account | ||
| use miden::standards::auth::tx_policy | ||
| use miden::standards::auth::signature | ||
|
|
||
| # IMPORTANT SECURITY NOTES | ||
| # -------------------------------------------------------------------------------- | ||
| # - By default, exactly one valid guardian signature is required. | ||
| # - If `update_guardian_public_key` is the only non-auth account procedure called in the current | ||
| # transaction, `verify_signature` skips the guardian signature check so key rotation can proceed | ||
| # without the old guardian signer. | ||
| # - `update_guardian_public_key` rotates the guardian public key and corresponding | ||
| # scheme id using the fixed map key `GUARDIAN_MAP_KEY`. | ||
|
|
||
|
|
||
| # CONSTANTS | ||
| # ================================================================================================= | ||
|
|
||
| # Storage Slots | ||
| # | ||
| # This authentication component uses named storage slots. | ||
| # - GUARDIAN_PUBLIC_KEYS_SLOT (map): | ||
| # GUARDIAN_MAP_KEY => GUARDIAN_PUBLIC_KEY | ||
| # where: GUARDIAN_MAP_KEY = [0, 0, 0, 0] | ||
| # | ||
| # - GUARDIAN_SCHEME_ID_SLOT (map): | ||
| # GUARDIAN_MAP_KEY => [scheme_id, 0, 0, 0] | ||
| # where: GUARDIAN_MAP_KEY = [0, 0, 0, 0] | ||
|
|
||
| # The slot in this component's storage layout where the guardian public key map is stored. | ||
| # Map entries: [GUARDIAN_MAP_KEY] => [GUARDIAN_PUBLIC_KEY] | ||
| const GUARDIAN_PUBLIC_KEYS_SLOT = word("miden::standards::auth::guardian::pub_key") | ||
|
|
||
| # The slot in this component's storage layout where the scheme id for the corresponding guardian | ||
| # public key map is stored. | ||
| # Map entries: [GUARDIAN_MAP_KEY] => [scheme_id, 0, 0, 0] | ||
| const GUARDIAN_SCHEME_ID_SLOT = word("miden::standards::auth::guardian::scheme") | ||
|
|
||
| # Single-entry storage map key where guardian signer data is stored. | ||
| const GUARDIAN_MAP_KEY = [0, 0, 0, 0] | ||
|
|
||
| # ERRORS | ||
| # ------------------------------------------------------------------------------------------------- | ||
| const ERR_INVALID_GUARDIAN_SIGNATURE = "invalid guardian signature" | ||
|
|
||
| # PUBLIC INTERFACE | ||
| # ================================================================================================ | ||
|
|
||
| #! Updates the guardian public key. | ||
| #! | ||
| #! Inputs: [new_guardian_scheme_id, NEW_GUARDIAN_PUBLIC_KEY] | ||
| #! Outputs: [] | ||
| #! | ||
| #! Notes: | ||
| #! - This procedure only updates the guardian public key and corresponding scheme id. | ||
| #! - `verify_signature` skips guardian verification only when this is the only non-auth account | ||
| #! procedure called in the transaction. | ||
| #! | ||
| #! Invocation: call | ||
| @locals(1) | ||
| pub proc update_guardian_public_key(new_guardian_scheme_id: felt, new_guardian_public_key: word) | ||
| # Validate supported signature scheme before committing it to storage. | ||
| dup exec.signature::assert_supported_scheme | ||
| # => [new_guardian_scheme_id, NEW_GUARDIAN_PUBLIC_KEY] | ||
|
|
||
| loc_store.0 | ||
| # => [NEW_GUARDIAN_PUBLIC_KEY] | ||
|
|
||
| push.GUARDIAN_MAP_KEY | ||
| # => [GUARDIAN_MAP_KEY, NEW_GUARDIAN_PUBLIC_KEY] | ||
|
|
||
| push.GUARDIAN_PUBLIC_KEYS_SLOT[0..2] | ||
| # => [guardian_pubkeys_slot_prefix, guardian_pubkeys_slot_suffix, | ||
| # GUARDIAN_MAP_KEY, NEW_GUARDIAN_PUBLIC_KEY] | ||
|
|
||
| exec.native_account::set_map_item | ||
| # => [OLD_GUARDIAN_PUBLIC_KEY] | ||
|
|
||
| dropw | ||
| # => [] | ||
|
|
||
| # Store new scheme id as [scheme_id, 0, 0, 0] in the single-entry map. | ||
| loc_load.0 | ||
| # => [scheme_id] | ||
|
|
||
| push.0.0.0 movup.3 | ||
| # => [NEW_GUARDIAN_SCHEME_ID_WORD] | ||
|
|
||
| push.GUARDIAN_MAP_KEY | ||
| # => [GUARDIAN_MAP_KEY, NEW_GUARDIAN_SCHEME_ID_WORD] | ||
|
|
||
| push.GUARDIAN_SCHEME_ID_SLOT[0..2] | ||
| # => [guardian_scheme_slot_prefix, guardian_scheme_slot_suffix, | ||
| # GUARDIAN_MAP_KEY, NEW_GUARDIAN_SCHEME_ID_WORD] | ||
|
|
||
| exec.native_account::set_map_item | ||
| # => [OLD_GUARDIAN_SCHEME_ID_WORD] | ||
|
|
||
| dropw | ||
| # => [] | ||
| end | ||
|
|
||
| #! Conditionally verifies a guardian signature. | ||
| #! | ||
| #! Inputs: [MSG] | ||
| #! Outputs: [] | ||
| #! | ||
| #! Panics if: | ||
| #! - `update_guardian_public_key` is called together with another non-auth account procedure. | ||
| #! - `update_guardian_public_key` was not called and a valid guardian signature is missing or | ||
| #! invalid. | ||
| #! | ||
| #! Invocation: exec | ||
| pub proc verify_signature(msg: word) | ||
| procref.update_guardian_public_key | ||
| # => [UPDATE_GUARDIAN_PUBLIC_KEY_ROOT, MSG] | ||
|
|
||
| exec.native_account::was_procedure_called | ||
| # => [was_update_guardian_public_key_called, MSG] | ||
|
|
||
| if.true | ||
| exec.tx_policy::assert_only_one_non_auth_procedure_called | ||
| # => [MSG] | ||
|
|
||
| exec.tx_policy::assert_no_input_or_output_notes | ||
| # => [MSG] | ||
|
|
||
| dropw | ||
| # => [] | ||
| else | ||
| push.1 | ||
| # => [1, MSG] | ||
|
|
||
| push.GUARDIAN_PUBLIC_KEYS_SLOT[0..2] | ||
| # => [guardian_pubkeys_slot_prefix, guardian_pubkeys_slot_suffix, 1, MSG] | ||
|
|
||
| push.GUARDIAN_SCHEME_ID_SLOT[0..2] | ||
| # => [guardian_scheme_slot_prefix, guardian_scheme_slot_suffix, | ||
| # guardian_pubkeys_slot_prefix, guardian_pubkeys_slot_suffix, 1, MSG] | ||
|
|
||
| exec.signature::verify_signatures | ||
| # => [num_verified_signatures, MSG] | ||
|
|
||
| neq.1 | ||
| # => [is_not_exactly_one, MSG] | ||
|
|
||
| if.true | ||
| emit.AUTH_UNAUTHORIZED_EVENT | ||
| push.0 assert.err=ERR_INVALID_GUARDIAN_SIGNATURE | ||
| end | ||
| # => [MSG] | ||
|
|
||
| dropw | ||
| # => [] | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.