bip158: add invalid compact size error
What changed, and why it matters
This commit only adds a new error variant to the BIP158 block filter error type. It does not change any parsing logic, fix a bug, or alter behavior. It is a preparatory code change for a future commit and has no security impact on its own.
No action needed for this commit alone. Review the subsequent commit that uses the new error variant to assess any security relevance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff adds an InvalidCompactSize(consensus::Error) variant to the bip158::error::Error enum in bitcoin/src/bip158.rs, along with corresponding Display and source() implementations. No call sites are added or modified in this commit, so the variant is unused. The commit message explicitly states it will be used in a subsequent commit.
Changed components
bitcoin/src/bip158.rsInspect captured patch +5 / −0
diff --git a/bitcoin/src/bip158.rs b/bitcoin/src/bip158.rs
index 723f12cc..67ef3340 100644
--- a/bitcoin/src/bip158.rs
+++ b/bitcoin/src/bip158.rs
@@ -503,6 +503,7 @@ pub mod error {
use internals::write_err;
+ use crate::consensus;
use crate::transaction::OutPoint;
/// Errors for blockfilter.
@@ -511,6 +512,8 @@ pub mod error {
pub enum Error {
/// Missing UTXO, cannot calculate script filter.
UtxoMissing(OutPoint),
+ /// Invalid CompactSize encoded element count in the filter.
+ InvalidCompactSize(consensus::Error),
/// I/O error reading or writing binary serialization of the filter.
Io(io::Error),
}
@@ -523,6 +526,7 @@ pub mod error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::UtxoMissing(ref coin) => write!(f, "unresolved UTXO {}", coin),
+ Self::InvalidCompactSize(ref e) => write_err!(f, "invalid CompactSize"; e),
Self::Io(ref e) => write_err!(f, "I/O error"; e),
}
}
@@ -533,6 +537,7 @@ pub mod error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::UtxoMissing(_) => None,
+ Self::InvalidCompactSize(ref e) => Some(e),
Self::Io(ref e) => Some(e),
}
}
Why this scored 15/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.