Skip to content

fix(standards): rework SWAP to support public payback notes#2949

Open
JereSalo wants to merge 13 commits into
nextfrom
jere/swap-v2
Open

fix(standards): rework SWAP to support public payback notes#2949
JereSalo wants to merge 13 commits into
nextfrom
jere/swap-v2

Conversation

@JereSalo
Copy link
Copy Markdown
Collaborator

@JereSalo JereSalo commented May 18, 2026

Public payback wasn't possible on SWAP notes: the on-chain script lacked the data needed to construct the payback recipient. This PR embeds the creator account ID in SWAP storage so the consumer can derive the payback P2ID recipient at consume time.

Related Issues:
0xMiden/miden-client#1739 - after this PR we'll be able to tackle this on the client side.
#2950 - Partially solves this issue just for SWAP and for the target_account_id scenario, which we don't send if the payback is private to preserve privacy of the target account (that in the future may be different from the creator account, that's why it makes sense not to reveal that info). We don't change the serial_num logic here nor we solve it for the PSWAP.

JereSalo added 2 commits May 18, 2026 10:45
Public payback notes were unrecoverable from on-chain data: the
previous SWAP precomputed the payback recipient off-line and embedded
only the resulting hash, so the consuming script had no preimage to
register with the advice provider.

Build the payback P2ID recipient at consume time from data available
in SWAP storage so the on-chain script can call p2id::new (which also
registers the recipient preimage in the advice map):

- Embed the creator account ID in storage (hybrid embed, mirroring
  PSWAP) so the consumer reads it directly instead of going through
  active_note::get_sender.
- Derive the payback serial as swap_serial[0] + 1.
- Derive the payback tag from the creator account ID prefix via
  note_tag::create_account_target.

Storage shrinks from 14 to 11 items: the precomputed recipient and tag
are no longer stored. The Rust constructor sets creator_id = sender by
convention.
@JereSalo JereSalo added no changelog This PR does not require an entry in the `CHANGELOG.md` file pr-from-maintainers PRs that come from internal contributors or integration partners. They should be given priority labels May 18, 2026
JereSalo added 4 commits May 18, 2026 15:15
# Conflicts:
#	crates/miden-standards/src/note/swap.rs
Branch SWAP MASM on payback note type so private paybacks store an opaque
precomputed recipient digest (and tag) instead of the creator id. Public
paybacks keep the creator id in plaintext since the consumer needs it to
reconstruct the recipient via p2id::new. The unified 16-felt storage asserts
zero on the slots unused by each branch, making the privacy guarantee
structural rather than convention-based.
Comment thread crates/miden-standards/asm/standards/notes/swap.masm Outdated
@JereSalo JereSalo marked this pull request as ready for review May 20, 2026 21:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no changelog This PR does not require an entry in the `CHANGELOG.md` file pr-from-maintainers PRs that come from internal contributors or integration partners. They should be given priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants