Adjust PartialMerkleTree arbitrary to satisfy decode checks
What changed, and why it matters
This commit fixes a test-only code generator for a Bitcoin network data structure so that the generated examples respect the same padding rule used by the real decoder. It only affects fuzz/property tests and does not change production parsing or network behavior.
No production action required. If using property-based/fuzz tests with the arbitrary feature, ensure tests are rerun to confirm the generator now satisfies decoder checks.
Security signals we found
Invariant mismatch between decoder and arbitrary generator
Test-only arbitrary feature code change
No production parsing or consensus code modified
Evidence from the diff
The Arbitrary implementation for PartialMerkleTree in p2p/src/merkle_tree.rs previously produced a raw Vec
Changed components
p2p/src/merkle_tree.rsPartialMerkleTree Arbitrary implementationarbitrary featureInspect captured patch +5 / −1
diff --git a/p2p/src/merkle_tree.rs b/p2p/src/merkle_tree.rs
index 8f625f16..dc22f238 100644
--- a/p2p/src/merkle_tree.rs
+++ b/p2p/src/merkle_tree.rs
@@ -651,9 +651,13 @@ pub mod error {
#[cfg(feature = "arbitrary")]
impl<'a> Arbitrary<'a> for PartialMerkleTree {
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
+ let mut bits = Vec::<bool>::arbitrary(u)?;
+ while bits.len() % 8 != 0 {
+ bits.push(false);
+ }
Ok(Self {
num_transactions: u.arbitrary()?,
- bits: Vec::<bool>::arbitrary(u)?,
+ bits,
hashes: Vec::<TxMerkleNode>::arbitrary(u)?,
})
}
Why this scored 18/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.