Skip to content

fix(standards): reject zero-amount assets in swap and pswap notes - #3840

Open
Dusk1e wants to merge 1 commit into
0xMiden:nextfrom
Dusk1e:reject-zero-swap-assets
Open

Dusk1e wants to merge 1 commit into
0xMiden:nextfrom
Dusk1e:reject-zero-swap-assets

Conversation

@Dusk1e

@Dusk1e Dusk1e commented Sep 9, 2026

Copy link
Copy Markdown

Follow-up to rust-sdk#2459, where @igamigo noted these checks belong here as well.

Problem

SwapNote::new rejects a self-swap, and PswapNoteBuilder::build rejects a same-faucet pair, but neither looks at the amounts:

SwapNote::new(offered = 0, requested = <non-fungible>)      -> Ok
SwapNote::new(offered = <non-fungible>, requested = 0)      -> Ok
PswapNote::builder()...(offered = 0, requested = 100)       -> Ok
PswapNote::builder()...(offered = 100, requested = 0)       -> Ok

Both sides carry value. The note holds the offered asset, and filling it emits a payback carrying the requested one, so a zero requested asset leaves the payback empty and a zero offered asset leaves a note whose consumer pays and receives nothing.

Change

Reject a zero-amount asset on either side in both constructors, with NoteError::other alongside the existing checks.

For SWAP the assets are Asset, so the test goes through a small is_zero_fungible helper — a non-fungible asset always carries value. For PSWAP both sides are FungibleAsset and compare directly.

PswapNoteStorage::min_fill_step is left alone: it defaults to AssetAmount::ZERO on purpose, to disable the fill floor.

Test plan

cargo test -p miden-standards --lib -- builder_rejects_a_zero_asset

swap_note_builder_rejects_a_zero_asset and pswap_note_builder_rejects_a_zero_asset cover both sides of each constructor. Both fail on next — the first expect_err gets an Ok note back.

All 275 miden-standards lib tests pass, and the workspace builds.

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