Repository navigation
fix: enforce BIP-352 K_max on the live receive path (SNB-540) - #18
Merged
Merged
Conversation
The live receive path (scan_transaction_short, then apply_block_relevant on the external indexer) relies on bdk_sp::receive::scan_txouts, which had no K_max cutoff: on the official "exceeding K_max" vector it stored 2324 outputs where BIP-352 caps a recipient group at 2323. The cutoff now lives in scan_txouts itself (setavenger/bdk-sp PR #1). Pin bdk_sp and indexer, in blindbit-lib and friglet, to that PR's commit; the pin must move to the fork's merged commit once the PR lands. Un-ignore official_vectors_live_receive_step_enforces_k_max and make it check exactness: every stored output is the match for a distinct k < 2323 and the k = 2323 candidate is never stored. Update the comments that said the live path has no K_max. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…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>
Un-ignoring the live K_max vector test added ~66s to the blindbit-lib test binary on CI (180.5s -> 246.9s), on top of two other tests that already scan the same 2324-output vector for ~3 minutes. Almost all of that time is libsecp256k1, which secp256k1-sys compiles at -O0 in a debug profile. Set `opt-level = 3` for secp256k1-sys in the dev profile (the test profile inherits it). Locally the live K_max test drops from 219s to 41s of CPU time; nothing else changes, and only one C library is rebuilt. Optimising the secp256k1 and bdk_sp Rust crates as well gained <5% more, so they are left alone. Debug builds of the daemon scan faster as a side effect. This keeps the K_max coverage in the main test job instead of moving it to a separate job or a release-mode run, both of which would add a second full compile per PR. SNB-540 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The secp256k1-sys `opt-level = 3` override speeds up every PR's test run, not just this one, so it now lands separately as #25 against integration. Revert it here, with the one test comment that referred to it, so this PR only carries the K_max change. Until #25 is in, this branch's CI pays the ~66s the un-ignored K_max test costs at -O0. SNB-540 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 1, 2026
Brings #18 up to date with master after the Friglet Deslop cleanup (#67-#76). Conflicts resolved as described in #75: - blindbit-lib/Cargo.toml, friglet/Cargo.toml: keep #18's bdk-sp rev pin and comments on top of the reduced manifest lines from SNB-670. - scanning.rs: BIP352_K_MAX loses its #[expect(dead_code)] (the compile-time assert against bdk_sp::K_MAX now uses it); its doc no longer mentions the removed scan_transaction_full, which stays deleted. - bip352_vectors.rs: the full-path K_max boundary test stays deleted; the live K_max test takes the label set and imports BIP352_K_MAX; its doc no longer links the deleted test. - Cargo.toml: the secp256k1-sys comment no longer says the live K_max test is ignored. 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.
Update 2026-10-30: merged with
masterafter the Friglet Deslopmasternow carries the Friglet Deslop cleanup (#67–#76), which conflicted with this PR in four files. Merge commit3ae8888resolves them as described in #75:blindbit-lib/Cargo.toml,friglet/Cargo.toml: this PR's bdk-sp rev pin and comments, on top of the shorter manifest lines from SNB-670.scanning.rs:BIP352_K_MAXdrops its#[expect(dead_code)](the compile-time assert now uses it), and its doc no longer refers toscan_transaction_full, which blindbit-lib: remove the unused full-transaction receive path (SNB-662) #75 removed. The edit inside that function is dropped with it.bip352_vectors.rs: the full-path K_max boundary test stays removed (blindbit-lib: remove the unused full-transaction receive path (SNB-662) #75). The live K_max test is un-ignored as before, now passes the label set, and its doc no longer links the removed test.Cargo.toml: the secp256k1-sys comment no longer says the live K_max test is ignored.Verified locally on
3ae8888(debug, private target dir):cargo test --workspace254 passed, 0 ignored (master: 253 + the ignored K_max test);cargo test -p blindbit-lib --features serde bip3528 passed in 30 s, includingofficial_vectors_live_receive_step_enforces_k_max;cargo check --workspace --all-targets --all-features0 warnings; clippy-D warningson friglet/friglet-ipc/friglet-tray clean.The original description follows. Where it mentions
scan_transaction_fullorofficial_vectors_enforce_k_max_at_the_blindbit_boundary, those are gone since #75.Problem
The live receive path is
scan_transaction_short→Scanner::apply_matched_block→apply_block_relevanton the external indexer →bdk_sp::receive::scan_txouts. That last function had no K_max cutoff. On the official "exceeding K_max" vector it stored 2324 outputs, but BIP-352 caps a recipient group at K_max = 2323.Fix
scan_txoutsin the fork (fix(receive): stop scan_txouts at BIP-352 K_max bdk-sp#1): aK_MAXconstant bounds the matching loop. Outputs withk >= 2323are never matched, and everyk < 2323is still found. Putting it there covers every caller: theindexercrate,Scanner::scan_txouts, and this repo's live path.bdk_spandindexerinblindbit-lib, andbdk_spinfriglet, are pinned withrev = "94b72f60…". That is fix(receive): stop scan_txouts at BIP-352 K_max bdk-sp#1's head commit. The pin is permanent, not a stopgap: bdk-sp#1 must land with a merge commit (not squash or rebase), so94b72f6stays in the fork's history and no pin bump is needed. The Cargo.toml comments now say this. TheCargo.lockdiff is only those twosourcelines.const _: () = assert!(BIP352_K_MAX == bdk_sp::K_MAX as usize)(blindbit-lib/src/scanner/scanning.rs), fails the build if the pinned bdk_sp ever disagrees with the BIP-352 value this crate uses. I checked it goes red: with the local constant set to 2324, the build fails withevaluation panicked: bdk_sp::K_MAX differs from BIP-352 K_max.official_vectors_live_receive_step_enforces_k_maxis no longer ignored. It now checks the exact set, not just the count: each stored tweak matches a distinctk < 2323, and neither the unlabelled nor the labelledk = 2323candidate is stored.scan_transaction_full'struncate(BIP352_K_MAX)is unchanged.CI cost
Un-ignoring the test makes the blindbit-lib test binary slower on CI, because libsecp256k1 runs at
-O0in debug builds. That is fixed separately, for every PR, by #25 ([profile.dev.package.secp256k1-sys] opt-level = 3). I chose that over moving this test to a separate job or a release-mode run, both of which add a second compile per PR. #25 and this PR merge cleanly in either order; I checked locally.Test workspacestep4ea2e06, K_max test ignored (run)f4c8030, test un-ignored (run)5e9f4c7(current head, without #25; warm cache) (run)c3c5cf9+ #25's change (run)c3c5cf9carried #25's change before it was split out (reverted in5e9f4c7).Verification
5e9f4c7: green. blindbit-lib reportsofficial_vectors_live_receive_step_enforces_k_max ... okand15 passed; 0 failed; 0 ignored; finished in 214.53s. With build: optimise libsecp256k1 in dev/test builds (BIP-352 vector tests 247s -> 28s on CI) #25's change (c3c5cf9) it was also green, in 27.77 s.5e9f4c7, private target dir:cargo test -p blindbit-lib --libgives15 passed; 0 failed; 0 ignored; finished in 25.22s. That machine's local cargo config optimises libsecp256k1 the way build: optimise libsecp256k1 in dev/test builds (BIP-352 vector tests 247s -> 28s on CI) #25 does. With the opt-level forced to 0, the K_max test alone takes 99.4 s of CPU time; at opt-level 3 it takes 18.9 s.5e9f4c7in a private target dir: I patched a local copy of the fork at94b72f6via--config patch...and ran the acceptance test. Unmodified, it passes. With three wrong cutoffs:left: 2324, right: 2323left: 2322, right: 2323left: 2324, right: 2323cargo test --workspaceandcargo clippy --no-deps -p friglet -p friglet-ipc -p friglet-tray --all-targets -- -D warnings: CI green on5e9f4c7.