Skip to content

perf(protocol): stop re-hashing input-note storage on read - #3659

Draft
mmagician wants to merge 1 commit into
nextfrom
mmagician-claude/skip-redundant-note-storage-rehash
Draft

perf(protocol): stop re-hashing input-note storage on read#3659
mmagician wants to merge 1 commit into
nextfrom
mmagician-claude/skip-redundant-note-storage-rehash

Conversation

@mmagician

@mmagician mmagician commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator

Stacked on #3641.

Addresses bobbinth's question on #3641 about recovering the hashing cost elsewhere.

#3641 makes the prologue verify every input note's storage against its authenticated commitment at load time. That makes the re-verification on every read redundant, so reads now copy the storage from the advice map without recomputing its commitment. Two facts make that safe:

  • the prologue verifies NOTE_STORAGE_COMMITMENT -> preimage for every input note, and
  • the advice map refuses to rebind a key to different values (AdviceProvider::insert_into_map raises MapKeyAlreadyPresent in miden-processor), so the preimage returned for a verified commitment cannot change mid-transaction.

protocol_utils::mem::write_elements_to_memory is the non-hashing counterpart of pipe_elements_preimage_to_memory: the same adv_pipe copy, without the Poseidon2 permutations.

active_note::write_storage_to_memory is removed rather than left unverified. It took a caller-supplied commitment, so dropping the hash in place would have turned a self-verifying public procedure into one that trusts any word handed to it. Both of its callers source the commitment from prologue-verified kernel memory, so they move to a new input_note::get_storage, which also resolves the TODO: Move this to miden::protocol::input_note on the standards wrapper.

The other candidate — having the prologue write the preimage into note memory so readers just copy it — is not viable: MAX_NOTE_STORAGE_ITEMS (1024) x MAX_INPUT_NOTES_PER_TX (1024) is up to ~1M elements of kernel memory, which is why the prologue writes to procedure locals and discards them.

🤖 Generated with Claude Code

https://claude.ai/code/session_015bLUPBgD8T6Edt2141yrvQ

@mmagician
mmagician marked this pull request as draft August 21, 2026 08:24
Base automatically changed from mmagician-claude/fix-l05-note-storage-count-verify to next August 21, 2026 08:26
The prologue now verifies every input note's storage against its
authenticated commitment at load time, so re-computing that commitment on
each read is redundant: the advice map rejects rebinding a key to
different values, so the preimage returned for the note's storage
commitment is the one the prologue verified.

Adds a non-hashing `protocol_utils::mem::write_elements_to_memory` and
moves the storage copy into `input_note_internal`, shared by
`input_note::get_storage`, `active_note::get_storage` and
`active_note::get_bounded_storage`.

The public `active_note::write_storage_to_memory` is removed rather than
left unverified: it took a caller-supplied commitment, so dropping the
hash in place would have turned a self-verifying public procedure into one
that trusts any word handed to it. Its non-hashing replacement lives in
`input_note_internal`, which is a private module, so every caller sources
the commitment from prologue-verified kernel memory.

The standards wrapper `note::input_note_get_storage` is replaced by the
new `input_note::get_storage`, resolving its TODO.
@mmagician
mmagician force-pushed the mmagician-claude/skip-redundant-note-storage-rehash branch from 4c24768 to 75e5df3 Compare August 21, 2026 13:55
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.

2 participants