Smart Contract Diff Audit L-12: Send Notes Script Generation Performs Unbounded Work Before the Output Note Limit Is Enforced
- Langage dominant
- Rust
- Étoiles
- 132
- Forks
- 167
- Merge moyen
- 1 j 23 h
- PR mergées (30 j)
- 110
Description
[`SendNotesTransactionScript::build`](https://github.com/0xMiden/protocol/blob/8411bf093bde25285708faac152b6d7269009617/crates/miden-standards/src/tx_script/send_notes_script.rs#L83-L122) accepts a slice of partial notes and never inspects its length. For each note it appends a fixed block of assembly to a single generated procedure, plus a further block per asset (see [`move_asset_to_note_body`](https://github.com/0xMiden/protocol/blob/8411bf093bde25285708faac152b6d7269009617/crates/miden-standards/src/tx_script/send_notes_script.rs#L155-L197)), and inserts one advice map entry per note attachment, before handing the assembled source to [`compile_tx_script`](https://github.com/0xMiden/protocol/blob/8411bf093bde25285708faac152b6d7269009617/crates/miden-standards/src/code_builder/mod.rs#L527-L563). Generation time, generated source size, and advice map size therefore grow with the number of notes the caller supplies. The remaining inputs to generation are already bounded, since per-note attachment and asset counts are enforced by [`NoteAttachments::new`](https://github.com/0xMiden/protocol/blob/8411bf093bde25285708faac152b6d7269009617/crates/miden-protocol/src/note/attachment/mod.rs#L502-L514) and [`NoteAssets::new`](https://github.com/0xMiden/protocol/blob/8411bf093bde25285708faac152b6d7269009617/crates/miden-protocol/src/note/assets.rs#L49-L52), which leaves the note count as the only unbounded dimension.
The transaction kernel caps the notes a single transaction may create at [`MAX_OUTPUT_NOTES_PER_TX`](https://github.com/0xMiden/protocol/blob/8411bf093bde25285708faac152b6d7269009617/crates/miden-protocol/src/constants.rs#L23-L24) and enforces that cap with [`ERR_TX_NUMBER_OF_OUTPUT_NOTES_EXCEEDS_LIMIT`](https://github.com/0xMiden/protocol/blob/8411bf093bde25285708faac152b6d7269009617/crates/miden-protocol/asm/kernels/transaction-core/src/output_note.masm#L570-L571) on every note creation, so a script generated for a longer note list can never execute successfully. Because the builder applies no length check of its own, a caller that passes such a list pays for full source generation, assembly, and partial transaction execution before learning that the request was impossible. In a host application that builds these scripts from a note list supplied by another party, the same missing bound may allow that party to impose generation and assembly cost proportional to the list it submits.
Consider rejecting note lists longer than `MAX_OUTPUT_NOTES_PER_TX` at the start of script generation and returning a dedicated error, so that a request the kernel is guaranteed to reject fails before any source generation or assembly work is performed.
---
_Copied verbatim from finding [L-12](https://audits.openzeppelin.com/miden/miden-01-07-smart-contract-diff-audit-nfts/issues/send-notes-script-generation-performs-unbounded-work-before-the-output-note-limit-is-enforced-72e3ab31) (low severity) of the OpenZeppelin [smart contract diff audit (NFTs)](https://audits.openzeppelin.com/miden/miden-01-07-smart-contract-diff-audit-nfts). The audit was performed against commit `8411bf093bde25285708faac152b6d7269009617`._
Guide de contribution
Ouvrir le guide de contribution
Évaluation
Cette issue n'a pas encore été évaluée.