0xMiden / 0xMiden/compiler

Support `NoteAttachment` in the Rust SDK when creating notes

Aperta
#1,254 0 commenti 0 reazioni 1 assegnatario Rivendicata da @greenhat Vedi su GitHub
rust sdk
Lingua principale
Rust
Stelle
115
Fork
84
Merge medio
1g 8h
PR unite (30g)
15

Descrizione

Protocol v0.15 introduced [`NoteAttachment`](https://github.com/0xMiden/protocol/blob/next/crates/miden-protocol/src/note/attachment/mod.rs): public extensions to a note (up to 4 per note, each 1-256 words), identified by a 16-bit `NoteAttachmentScheme`. Standard schemes already exist (e.g. `NetworkAccountTarget`, pswap discovery), and the tx kernel exposes `output_note::add_attachment`, `add_word_attachment`, and `add_attachment_from_memory` (0xMiden/protocol#2249, #2795, #2871).

The SDK on `next` has raw bindings for these procs (`sdk/base-sys/src/bindings/output_note.rs`), but no first-class `NoteAttachment` support when creating notes from Rust:

- The scheme is a raw `Felt` and the content a raw `Word` / `&[Word]`. There are no `NoteAttachment` / `NoteAttachmentScheme` types mirroring the protocol, so invalid values (scheme 0 or > 65534, empty or > 256-word content, more than 4 attachments) only fail at runtime in the kernel.
- `output_note::create` takes no attachments; users must make separate untyped `add_*` calls per attachment against the returned `NoteIdx`.

### Proposal

Add typed `NoteAttachment` support to the SDK (`sdk/base-sys`, re-exported via `miden`):

1. `NoteAttachmentScheme` and `NoteAttachment` types in `bindings/types.rs`, mirroring the protocol types and enforcing their invariants at construction.
2. `output_note::add_attachment(note_idx, attachment: NoteAttachment)` that dispatches to the existing single-word / from-memory bindings, replacing the loose `(Felt, Word)` signatures.
3. Optionally, a way to pass attachments at note-creation time (e.g. `create_with_attachments(...)` or a builder), so a note and its attachments are set up in one step. This should also compose with the `#[note_constructor]` work (#786).

The read-side APIs (`find_attachment`, `write_attachment_to_memory`, etc. on `input_note` / `active_note`) would benefit from the same types as a follow-up.

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Start by reading the protocol's NoteAttachment module to understand the data structures and invariants. Examine the existing raw bindings in sdk/base-sys/src/bindings/output_note.rs and the kernel procedures they call. The task is to create new types in bindings/types.rs that enforce the scheme and content limits, then integrate them into a higher-level API for adding attachments, possibly via a builder pattern. Check how note constructors (#786) work to ensure compatibility.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
rust
Ambito
api, backend
Tipo di issue
Funzionalità
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Tranquilla
Chiarezza
Specificata chiaramente
Idoneità per principianti
55/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.