Skip to content

feat(runtime): memos declare their format in the shielded pool, enforced from an admin-scheduled block (spec 23, v0.9.0) - #193

Merged
nol4lej merged 2 commits into
mainfrom
feat/tagged-memo-format
Nov 17, 2026
Merged

nol4lej merged 2 commits into
mainfrom
feat/tagged-memo-format

Conversation

@nol4lej

@nol4lej nol4lej commented Nov 17, 2026

Copy link
Copy Markdown
Member

Summary

Memos in the shielded pool can now be required to declare how their owner finds them, so wallets can stop trial-decrypting notes that cannot be theirs. Nonce byte 1 of a memo is its format: 0x01 TAGGED (found by lookup of a tag the owner knows in advance) or 0x02 HANDSHAKE (found by trial ECDH, as every memo before). An admin schedules the block the rule starts at; from then on a memo without a declared format is refused. Nothing changes until the rule is scheduled.

Runtime spec 23 (tx 8 unchanged), v0.9.0, pallet-shielded-pool 0.28.0. No storage migration: the new values start empty.

Added

  • schedule_tagged_memos(from) (call index 21, AdminOrigin): sets TaggedMemosFrom and emits TaggedMemosScheduled.
    • from must be a future block (TaggedMemosStartInPast).
    • The start can be moved earlier or later, or pushed far ahead to cancel it, until its block is reached. From then on it is fixed (TaggedMemosAlreadyActive), even before the leaf is recorded.
    • No upper bound: a far start binds nothing. Weight: 2 reads, 1 write (SCHEDULE_READS).
  • TaggedMemosFromLeaf: recorded once, in the on_initialize of the first block at or past TaggedMemosFrom, as the next leaf index; never changed after. Every leaf from it on was inserted under the rule. Emits TaggedMemosActivated.
  • MemoFormat and EncryptedMemo::format(): the format a full 180-byte memo declares, None for any other byte or a memo that is not full size.
  • Pool code MEMO_FORMAT_OUTDATED (Custom(15)): an unsigned spend carrying an undeclared memo is refused at admission. The check runs after fee, root and nullifiers and before the proof.

Changed

  • One check for every stored memo: shield (shield_batch included), private transfer, unshield change and bound-spend change go through operations::memo_format::ensure_storable. It checks sizes first (InvalidMemoSize), then the format while the rule is in force (MemoFormatOutdated), before the proof is verified.
    • Before, size and format were separate calls, and a short memo whose second byte happened to be 0x01/0x02 counted as declared.
    • Minted notes store no memo.
    • Public (zero-ephPk) and dummy memos get no exemption: the dummy now carries the TAGGED byte, and the old all-zero dummy is refused.
  • on_initialize reads one or two more storage values per block (three reads and two writes in the block that records the leaf), charged on top of the prune batch.

Not in this PR

The benchmarked weights of shield, shield_batch, private transfer, unshield and bound spend do not count the 1–2 extra reads of the format check. That is small next to proof verification, and the next benchmark run will pick it up; adding it by hand would count it twice.

Testing

  • cargo test -p pallet-shielded-pool: 434 passed, 0 failed; cargo clippy -p pallet-shielded-pool --all-targets: no warnings.
  • Scheduling: a start in the past or the current block is refused; scheduling again; a far start moved back; the start is fixed once its block is reached, even before the hook; refused calls emit nothing.
  • Cutover: a two-output transfer at from−1, from and from+1. The leaf is recorded in on_initialize before any extrinsic, so no call straddles it.
  • Paths: bound-spend change at dispatch and admission; a spend admitted at from−1 is refused at pre_dispatch in the start block; one undeclared memo refuses a whole shield_batch; unshield change; the format checked after nullifiers.
  • Memos: public and dummy memos, short memos, all 256 byte values; constants pinned; pool codes unique.
  • Devstack end to end: after activation a legacy shield is refused; app shield is 0x01; transfer payment is 0x02 and change 0x01; full scans find the same notes with tagged leaves skipped.
  • Shared signed-text vectors regenerated for spec 23 (ed25519_text_vectors.json, mirrored in ts-protocol).

@nol4lej
nol4lej merged commit 62e0726 into main Nov 17, 2026
7 checks passed
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.

1 participant