Repository navigation
fix(send): enforce BIP352 K_MAX per-scan-key recipient limit - #80
debojyoti10CC wants to merge 4 commits into
Conversation
|
Tested c7dca79 on macOS arm64, cargo 1.100.0. The checklist says the reproducing tests haven’t been run yet. I ran them: the unit tests for exactly K_MAX and K_MAX + 1 pass. cargo test: 204 passed, 0 failed, 3 ignored (9 test binaries). I think the cause is the test harness, not the new check. Vector 27 has one recipient entry with "count": 2324. The recipient deserializer in serialization.rs doesn’t read count, so the test passes one recipient and the new check never runs. The unit tests cover the boundary, but the official vector doesn’t yet. Two suggestions:
I can test a branch with the deserializer change if that helps. |
|
Thanks for testing this and for tracking down the vector issue, that's a great catch. I pushed 310a5c5: the test deserializer now expands each recipient by its |
BIP352 requires senders to fail if a group of recipients sharing the same B_scan has more than K_MAX members. Only the receive side checked this. create_silentpayment_scriptpubkeys now returns a Result and fails with SpSendError::GroupLimitExceeded. Breaking: public return type changed. Fixes bitcoindevkit#79
The test deserializer ignored the recipient "count" field, so vector 27 (one recipient with count 2324) only passed a single recipient and never reached the K_MAX check. Expand each recipient by its count, un-ignore the test, and assert the exact GroupLimitExceeded(K_MAX) error.
310a5c5 to
6539394
Compare
|
Re-ran on 6539394 (macOS arm64, cargo 1.100.0). The diff from 310a5c5 is empty, so this is the same code with new signatures.
|
|
Thanks for re-running it, @AdityaKaushal17, and for the thorough check across the full suite. Really appreciate the help getting the vector test working. With the official K_MAX vector passing and the full suite green, everything looks good from my side. This should be ready for review whenever a maintainer has time. |
|
Thanks @AdityaKaushal17 for re-running everything on macOS and confirming the vector passes. Much appreciated. |
|
|
||
| // BIP352: fail if a group (same B_scan) has more than K_MAX recipients | ||
| if k >= K_MAX { | ||
| return Err(SpSendError::GroupLimitExceeded(K_MAX)); |
There was a problem hiding this comment.
Why composing this as a parameterize error when it's going to be always used with K_MAX, the max group size?
| fn default_recipient_count() -> usize { | ||
| 1 | ||
| } |
There was a problem hiding this comment.
Default for serde has to be a function?
The error is only ever raised for K_MAX, so carry no payload and print the constant in Display. In the test deserializer, read the recipient count as Option<usize> instead of a serde default function.
|
Thanks for the review, @nymius! Both points made sense, so I pushed 0b7773c:
I can't build Rust locally right now, so CI will be the compile check. |
| count: usize, | ||
| } | ||
|
|
||
| fn default_recipient_count() -> usize { |
There was a problem hiding this comment.
I just checked with my clanker, and it seems this approach is sound, sorry, I did it after my original comment because I was expecting a different solution than yours. Let's roll back this.
Reviewer request on bitcoindevkit#80: a plain `count: Option<usize>` with unwrap_or was not wanted; the default-function approach is the sound one. Co-Authored-By: Claude Haiku 5.5 <[email protected]>
|
Thanks for checking the serde part again, @nymius. I've rolled that back in 38a9147: the test deserializer uses the default function again ( |
There was a problem hiding this comment.
The commit message is irrelevant for future readers, squash it in the most related commit.
Can you clarify me what "can't compile Rust here" means? What's here? You're programming in rust without a rust compiler? |
Description
BIP352 says a sender must fail if any group of recipients sharing one
B_scanhas more thanK_MAX(2323) members.create_silentpayment_scriptpubkeysnever checked this, so it happily derived outputs for arbitrarily large groups, even thoughscan_txoutson the receive side already rejects them (#79 asks for the sender-side check).The fix reuses
receive::K_MAX. The function now returnsResult<_, SpSendError>and returns the newSpSendError::GroupLimitExceeded(K_MAX)as soon as a (K_MAX + 1)-th recipient for the same scan key shows up. Thebip32,bip352and PSBT senders already returnedSpSendError, so they just propagate it.Notes to the reviewers
This is a breaking change:
create_silentpayment_scriptpubkeysis public and its return type changed fromHashMap<..>toResult<HashMap<..>, SpSendError>. I couldn't find a way to enforce the limit at the shared derivation point without it.SpSendErroralso gets a new variant.Tests: exactly
K_MAXrecipients for one scan key succeeds,K_MAX + 1returnsGroupLimitExceeded. Existing tests were updated for the new return type.I could not run the tests locally: Windows Application Control blocks cargo build scripts on my machine (os error 4551).
cargo fmt --checkpasses; tests and clippy still need a run in CI or elsewhere.Changelog notice
K_MAXper-scan-key recipient limit;create_silentpayment_scriptpubkeysnow returns aResult(breaking).Checklists
just p(fmt, clippy and test) before committing (only fmt)AI use: I used Claude Code to help write this change.
Fixes #79