Skip to content

Introduce P2ID note constructor in MASM #2280

@PhilippGackstatter

Description

@PhilippGackstatter

We should introduce note constructors for standard notes that make it easy to create them from MASM code.

The target use case here is when the note inputs are known. Meaning, that the way a SWAP note creates its payback note will not change through this, since it already only has the higher-level RECIPIENT.

As an example, for P2ID this could look like this in crates/miden-standards/asm/standards/notes/p2id.masm:

#! The existing main procedure, untouched.
pub proc main
    # ...
end

#! Inputs:  [target_id_prefix, target_id_suffix, tag, note_type, SERIAL_NUM]
#! Outputs: [note_idx]
pub proc new
    # Write note inputs to memory in the expected layout (see `miden_standards::note::utils::build_p2id_recipient`)
    # RECIPIENT = exec.miden::protocol::note::build_recipient(inputs, SERIAL_NUM, procref.main)
    # note_idx = exec.miden::protocol::output_note::create(tag, note_type, RECIPIENT)
end

The benefit here is that:

  • constructing the right note inputs layout would be handled by new
  • obtaining the note script root is also handled by new (via procref.main)

I think we should start by implementing this for the P2ID note, and then work on other standard notes, in case the approach changes.

Context: #2156 (comment)

Tasks:

  • Implement the above.
  • Test it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueGood for newcomersstandardsRelated to standard note scripts or account components

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions