0xMiden / 0xMiden/compiler

Support `NoteAttachment` in the Rust SDK when creating notes

未關閉
#1,254 0 則留言 0 個 reaction 已指派 1 人 已被 @greenhat 認領 在 GitHub 檢視
rust sdk
主要語言
Rust
星號
115
分支
84
平均合併
1 天 8 小時
30 天內合併 PR
15

描述

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.

貢獻指南

開啟貢獻指南

研究方向

首先閱讀協議的 NoteAttachment 模組,以了解資料結構和不變性。檢查 sdk/base-sys/src/bindings/output_note.rs 中現有的原始綁定以及它們呼叫的核心程序。任務是在 bindings/types.rs 中建立新類型以強制執行方案和內容限制,然後將它們整合到用於新增附件的高階 API 中,可能透過建構器模式。檢查筆記建構函式 (#786) 的工作方式以確保相容性。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
rust
領域
api, backend
Issue 類型
功能
難度
3/5
預估耗時
1-2 天
活躍度
冷清
描述清晰度
描述清楚
新手友好度
55/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。