bip158: Return no match for empty query
What changed, and why it matters
This commit fixes a logic bug in Bitcoin's BIP158 compact block filter code. Previously, if a user asked 'Is anything in this block relevant to me?' but provided an empty list of things to look for, the code incorrectly answered 'Yes, it matches.' This could make wallet or node software think every block was relevant, wasting resources, triggering unnecessary downloads, or causing denial-of-service-like behavior. The fix makes an empty query correctly return 'No match.'
Review all callers of GcsFilterReader::match_any() and related match methods to confirm they handle empty queries safely. Backport the one-line fix to maintained release branches. Add a regression test covering the empty-query case.
Security signals we found
Logic error causing false-positive match for empty query
Potential resource exhaustion / DoS vector if attacker can trigger empty-query checks against many blocks
BIP158 block-filter API misuse risk
Evidence from the diff
In bitcoin/src/bip158.rs, GcsFilterReader::match_any() returned Ok(true) when the mapped query set was empty. The patch changes that to Ok(false). An empty query set means no elements are being searched for, so no block should be reported as matching. The downstream effect depends on caller behavior: callers that treat a ‘true’ match as a signal to fetch or process a block could be driven into unnecessary work by intentionally or accidentally supplying an empty query.
Changed components
bitcoin/src/bip158.rsGcsFilterReader::match_any()Inspect captured patch +1 / −1
diff --git a/bitcoin/src/bip158.rs b/bitcoin/src/bip158.rs
index 69bd2e9b..530798ad 100644
--- a/bitcoin/src/bip158.rs
+++ b/bitcoin/src/bip158.rs
@@ -306,7 +306,7 @@ impl GcsFilterReader {
// sort
mapped.sort_unstable();
if mapped.is_empty() {
- return Ok(true);
+ return Ok(false);
}
if n_elements == 0 {
return Ok(false);
Why this scored 51/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.