Skip to content

fix(standards): price PSWAP fills against the note's initial offered asset - #3652

Merged
mmagician merged 8 commits into
mmagician-claude/docs-note-scripts-remaining-assetsfrom
mmagician-claude/fix-pswap-offered-amount-binding
Aug 21, 2026
Merged

fix(standards): price PSWAP fills against the note's initial offered asset#3652
mmagician merged 8 commits into
mmagician-claude/docs-note-scripts-remaining-assetsfrom
mmagician-claude/fix-pswap-offered-amount-binding

Conversation

@mmagician

@mmagician mmagician commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

The PSWAP note script priced a fill against the offered asset remaining in the note at consumption time, not the amount the creator funded, which was exploitable as described in #3601

Fix

Bind the offered amount to the note's initial assets.

claude added 2 commits August 20, 2026 15:43
…asset

The PSWAP note script priced a fill against the offered asset *remaining* in
the note at consumption time rather than the amount the creator funded. A
consumer whose own account exposes an indexed-removal procedure could, via an
earlier helper note in the same transaction, drain most of the offered asset
out of the PSWAP note into their own vault before the PSWAP script ran; the
single-asset assert still passed on the partially-removed slot, so the fill was
priced against the residue and the creator's remainder note absorbed the loss.

Bind the offered amount to the note's initial assets, which the prologue records
at note creation and which removals never affect. `load_offered_asset` now
fetches the note's initial assets, asserts exactly one, and asserts the single
remaining offered asset equals the single initial one word-for-word (asset ID
and value), aborting with the new ERR_PSWAP_OFFERED_ASSET_ALTERED otherwise. Any
pre-removal from a PSWAP note thus aborts the whole transaction. Both the fill
(execute_pswap) and reclaim (handle_reclaim) paths go through this procedure.

This changes the compiled PSWAP note-script MAST root and therefore PSWAP note
recipients/IDs.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Reduce the inline comments added with the offered-asset binding to match
the surrounding file, and drop the counterfactual/pre-fix narration from
the doc comments and the regression test.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Comment thread crates/miden-standards/asm/standards/notes/pswap.masm Outdated
Comment thread crates/miden-standards/asm/standards/notes/pswap.masm Outdated
Comment thread crates/miden-standards/asm/standards/notes/pswap.masm Outdated
Comment thread crates/miden-standards/src/note/pswap.rs Outdated
Comment thread crates/miden-testing/tests/scripts/pswap.rs Outdated
Comment thread crates/miden-testing/tests/scripts/pswap.rs Outdated
Comment thread crates/miden-testing/tests/scripts/pswap.rs Outdated
Comment thread CHANGELOG.md Outdated
mmagician and others added 2 commits August 20, 2026 22:15
Co-authored-by: Marti <marcin.gorny.94@protonmail.com>
Replace the bare locaddr.0 / locaddr.8 in load_offered_asset with named
OFFERED_REMAINING_ASSET_PTR / OFFERED_INITIAL_ASSET_PTR constants, matching
the per-proc local-offset convention used elsewhere in the file.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Comment thread crates/miden-standards/asm/standards/notes/pswap.masm Outdated
@mmagician
mmagician marked this pull request as ready for review August 20, 2026 20:32

@zeapoz zeapoz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

Comment thread crates/miden-standards/asm/standards/notes/pswap.masm Outdated
Comment thread crates/miden-testing/tests/scripts/pswap.rs Outdated

@PhilippGackstatter PhilippGackstatter left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

Comment thread crates/miden-standards/asm/standards/notes/pswap.masm
Comment thread crates/miden-standards/asm/standards/notes/pswap.masm Outdated
mmagician and others added 3 commits August 21, 2026 15:15
Co-authored-by: zeapoz <zeapo@pm.me>
Co-authored-by: Philipp Gackstatter <PhilippGackstatter@users.noreply.github.com>
…to mmagician-claude/fix-pswap-offered-amount-binding
@mmagician
mmagician added this pull request to the merge queue Aug 21, 2026
Merged via the queue into next with commit 0ae591a Aug 21, 2026
19 checks passed
@mmagician
mmagician deleted the mmagician-claude/fix-pswap-offered-amount-binding branch August 21, 2026 14:02
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.

4 participants