Skip to content

fix(standards): derive the network account target of MINT and BURN notes - #3664

Open
onurinanc wants to merge 11 commits into
nextfrom
fix-network-notes
Open

fix(standards): derive the network account target of MINT and BURN notes#3664
onurinanc wants to merge 11 commits into
nextfrom
fix-network-notes

Conversation

@onurinanc

Copy link
Copy Markdown
Collaborator

Closes: #3663

@bobbinth bobbinth 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! Thank you! Not a full review, but I left a couple of questions inline.

return Self::ensure_presence(attachments, target_id);
}

Self::contains_target(attachments, target_id).map(|_| ())

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.

We need this line to check if a private account has malformed network target attachment, right? Or is there some other reason?

Regardless - we should add a brief comment explaining why this line is needed.

Comment on lines +93 to +96
NetworkAccountTarget::ensure_presence_if_public(&mut attachments, storage.faucet_id())
.map_err(|err| {
NoteError::other_with_source("failed to target the MINT note at its faucet", err)
})?;

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.

Why for MINT notes we use ensure_presence_if_public() but for BURN notes we use just ensure_presence()? Couldn't both of them be directed to non-network accounts?

@mmagician mmagician left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Overall LGTM

Comment thread crates/miden-standards/src/note/burn.rs Outdated
Comment on lines +56 to +57
/// The attachment is the canonical target encoding the network routes on; the consume-side bind is
/// the asset itself, which the faucet's `receive_and_burn` rejects if it did not issue it.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
/// The attachment is the canonical target encoding the network routes on; the consume-side bind is
/// the asset itself, which the faucet's `receive_and_burn` rejects if it did not issue it.

we can easily skip the extra detail without losing the important information

Comment thread crates/miden-standards/src/note/burn.rs Outdated
Comment on lines +81 to +82
/// - the attachments exceed their protocol limit (see [`NoteAttachments::new`]); the target
/// attachment occupies one of the available slots when the caller does not supply it.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
/// - the attachments exceed their protocol limit (see [`NoteAttachments::new`]); the target
/// attachment occupies one of the available slots when the caller does not supply it.
/// - the attachments exceed their protocol limit (see [`NoteAttachments::new`]).

Comment thread crates/miden-standards/src/note/mint.rs Outdated
Comment on lines +56 to +57
/// its storage, which is also what the note is tagged for. The attachment is the canonical target
/// encoding the network routes on; the consume-side bind is the stored `ASSET_ID`, which the

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

ditto; should be shortened

Comment thread crates/miden-standards/src/note/mint.rs Outdated
/// [`NoteAttachments::new`]).
/// Returns an error if:
/// - the attachments carry a `NetworkAccountTarget` for an account other than the faucet.
/// - the attachments exceed their protocol limit (see [`NoteAttachments::new`]); the target

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

ditto

Comment thread crates/miden-standards/src/note/mint.rs Outdated
Comment on lines +398 to +411

/// The builder attaches the network target for the minting faucet, so the note is a network
/// note without the caller having to add the attachment.
#[test]
fn builder_attaches_network_target() {
let mint_note = build_mint_note(faucet(), Vec::new()).unwrap();

assert_eq!(mint_note.attachments().num_attachments(), 1);

let network_note = AccountTargetNetworkNote::new(Note::from(mint_note)).unwrap();
assert_eq!(network_note.target_account_id(), faucet());
assert_eq!(network_note.execution_hint(), NoteExecutionHint::Always);
assert!(network_note.as_note().is_network_note());
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

AFAICS, the set of new tests added is the same for mint and burn - I'd aim to de-deduplicate code if possible

@mmagician mmagician left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM modulo verbose/unclear comments

Comment thread crates/miden-standards/src/note/burn.rs Outdated
Comment thread crates/miden-standards/src/note/mint.rs Outdated
Comment thread crates/miden-standards/src/note/network_account_target.rs Outdated

@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.

LGTM, aside from the one comment.

Comment on lines +104 to +108
// No target is derived, but a caller-supplied attachment of the scheme must still be
// validated, so the note cannot claim a network target it does not have. The returned flag
// is discarded because it is always false here: an attachment naming a non-public account
// never decodes into a `NetworkAccountTarget`, so a present target can only be an error.
Self::contains_target(attachments, target_id).map(|_| ())

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'm struggling to understand the comment, it's very claude-ish. I think the idea is to make sure there is no attachment that a user added that claims to be a NetworkAccountTarget but actually contains a private target_id. If so, I would suggest something like:

// Ensure that none of the user-provided attachments claims to be a
// `NetworkAccountTarget` with a private target.

Comment on lines +104 to +105
// Reject any attachment the caller added under the target scheme: naming another account
// is a mismatch, and naming this private one does not decode as a `NetworkAccountTarget`.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

TBH I still struggle to understand this comment.

I think what makes it worse is the name contains_target.
At first, I'd expect that a NetworkAccountTarget encoding a private account still "contains" this private account as target (even though the constructor won't allow such case).
A better fit might be validate_target: then describing that a network attachment with private account fails to "validate" reads much more intuitively.

So maybe we could rename contains_target -> validate_target?

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.

Management Notes Built For Network Execution Are Not Identifiable As Network Notes

4 participants