Repository navigation
fix(receive): stop scan_txouts at BIP-352 K_max - #1
Merged
Merged
Conversation
BIP-352 caps the number of outputs a single recipient group can receive in one transaction at K_max = 2323: the receiver stops scanning once k reaches K_max. scan_txouts had no such cutoff, so a transaction paying K_max + 1 outputs to one recipient had all of them reported and stored (the official vector "Receiving: exceeding K_max" expects 2323). Add the K_MAX constant and bound the matching loop with it. Unit tests cover the boundary (K_MAX + 1 outputs -> exactly k = 0..K_MAX found) and the ordinary case below the limit. SNB-540 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
setavenger
added a commit
to setavenger/blindbit-rs
that referenced
this pull request
Oct 1, 2026
…ents The live receive path is only BIP-352 conformant while the pinned bdk_sp stops scan_txouts at the same K_max this crate uses, so make a mismatch a build error: `const _: () = assert!(BIP352_K_MAX == bdk_sp::K_MAX as usize)`. The Cargo.toml comments said to move the pin once setavenger/bdk-sp#1 lands. That is not the plan: the fork PR is merged with a merge commit, so commit 94b72f6 stays in the fork's history and the `rev =` pin stays valid. Say that instead, and that friglet's bdk_sp rev must match blindbit-lib's. SNB-540 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Important
Merge with "Create a merge commit" (or fast-forward
integrationto94b72f6). Do not squash or rebase.setavenger/blindbit-rs#18 pins
bdk_spandindexertorev = "94b72f60b0015793e4db67355bdab8d240eecc00", this PR's head. Squash or rebase would give the change a new SHA; once this branch is deleted,94b72f6would no longer be reachable in this repo, and blindbit-rs builds would break when GitHub garbage-collects it. A merge commit keeps it inintegration's history, so the pin stays valid and needs no bump.Summary
BIP-352 caps a recipient group at
K_max = 2323outputs per transaction. The receiver's scanning loop says: "If k == K_max (=2323), stop scanning."receive::scan_txoutslooped until no further output matched, so withK_max + 1outputs to one recipient it reported all 2324. The official vector "Maximum per-group recipient limit K_max is exceeded (2324 matches): sending fails, receiver doesn't scan beyond limit" expectsn_outputs = 2323.pub const K_MAX: u32 = 2323(silentpayments/src/lib.rs).scan_txoutsmatching loop:while matched_tweaks < K_MAX. Every output withk < K_MAXis still found.k >= K_MAXis never reported, and the transaction is still processed.receive::scan::Scanner::scan_txouts,indexer(lib.rsviaScanner, andv2).send::create_silentpayment_scriptpubkeys) does not yet fail when a group exceedsK_max, which BIP-352 also requires. That is a separate change.Tracked as SNB-540 (BlindBit).
Differs from upstream
bitcoindevkit/bdk-sp fixed K_max separately in its bitcoindevkit#75 (
d257a22). Its version returnsErr(SpReceiveError::ScanLimitExceeded(2323))on the 2324th match. That throws away the 2323 outputs already found, andindexerv2 then skips the whole transaction without reporting anything. Upstream's vector test still passes because its receive harness accepts any error when a vector has nooutputskey, and it never checksn_outputs.This PR follows the BIP text and the vector: stop at
k == K_maxand keep the 2323 outputs found. A later sync with upstream (the fork is 54 commits behind) has no textual conflicts. It does have two semantic ones: upstream'sreceive::K_MAXcollides with this PR's crate-rootK_MAX(E0255), and upstream's error branch has to be dropped. These semantics should win there. Details are in SNB-540.Tests
receive::tests::scan_txouts::stops_at_k_max: a tx withK_MAX + 1outputs to one recipient. Exactlyk = 0..K_MAXare found. Outputs are ordered so the test is linear (under 1s in debug).receive::tests::scan_txouts::finds_all_outputs_below_k_max: the ordinary case.94b72f6:<= K_MAXfails withleft: 2324, right: 2323,< K_MAX - 1fails withleft: 2322, right: 2323, and no cap fails withleft: 2324, right: 2323.official_vectors_live_receive_step_enforces_k_maxasserts that all 2323 matches fork < 2323are stored and that thek = 2323candidate (labelled or not) is not.cargo test --no-fail-fast --all-features(default members, rustc 1.98.1) at94b72f6: all pass. That isbdk_sp104 unit + 52 functional + 2 integration,dleq26, and 8 doctests.cargo fmt --all -- --check: clean.cargo clippy --all-targets --all-features -- -Dwarningsfails only on the existingclippy::iter_kv_mapatsilentpayments/tests/functional_tests/bip352_vectors/send.rs:28, which also fails onmaster. This PR doesn't touch that file.CI
This fork has never run a workflow (0 runs, no checks on this PR). The Actions permission is "all actions allowed", but GitHub keeps a fork's inherited workflows off until the owner clicks "I understand my workflows, go ahead and enable them" on the fork's Actions tab. If they are enabled, expect:
CI / fmt-clippyto fail on the existing clippy lint above.Code Coverageto need Coveralls set up for the fork.Test mutantsto runcargo-mutantson the diff.🤖 Generated with Claude Code