Use check_encode in consensus comparison fuzz target
What changed, and why it matters
This commit is a small internal cleanup of a fuzz test (a software self-test) in the rust-bitcoin project. It swaps one helper function for another so the test avoids an unnecessary memory allocation. There is no change to the library code that real users rely on, and nothing in the commit suggests a security vulnerability was fixed.
No security action needed; treat as routine test maintenance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change modifies fuzz/fuzz_targets/bitcoin/compare_consensus_encoding.rs only. It replaces a call to bitcoin_consensus_encoding::encode_to_vec (which allocates a Vec) with check_encode, which streams the new encoder output directly against the pre-serialized old-encoded byte slice. The old encode_to_vec path is left commented out for debugging. This is a refactoring of test infrastructure with no functional change to consensus encoding behavior.
Changed components
fuzz/fuzz_targets/bitcoin/compare_consensus_encoding.rsInspect captured patch +7 / −4
diff --git a/fuzz/fuzz_targets/bitcoin/compare_consensus_encoding.rs b/fuzz/fuzz_targets/bitcoin/compare_consensus_encoding.rs
index 625d1215..d74327f4 100644
--- a/fuzz/fuzz_targets/bitcoin/compare_consensus_encoding.rs
+++ b/fuzz/fuzz_targets/bitcoin/compare_consensus_encoding.rs
@@ -6,7 +6,7 @@
//! This fuzz target compares the consensus encoding produced by `bitcoin_consensus_encoding::encode_to_vec`
//! in master branch with `bitcoin::consensus::encode::serialize` from bitcoin 0.32 for all shared types.
-use bitcoin_consensus_encoding::{decode_from_slice, encode_to_vec, Decoder};
+use bitcoin_consensus_encoding::{check_encode, decode_from_slice, Decoder};
use libfuzzer_sys::fuzz_target;
#[cfg(not(fuzzing))]
@@ -82,10 +82,13 @@ macro_rules! compare_encoding {
match (old_result, new_result) {
(Ok(old_obj), Ok(new_obj)) => {
- // Encode with both the old and consensus_encoding implementations
+ // Encode with old bitcoin and then compare against new encoding
let old_encoded = old_bitcoin::consensus::encode::serialize(&old_obj);
- let new_encoded = encode_to_vec(&new_obj);
- assert_eq!(old_encoded, new_encoded);
+ // Uncomment the following two lines if you need to see the difference
+ // in serialisation.
+ // let new_encoded = bitcoin_consensus_encoding::encode_to_vec(&new_obj);
+ // assert_eq!(old_encoded, new_encoded);
+ check_encode(&new_obj, &old_encoded);
}
(Ok(old_obj), Err(ref err)) =>
if !is_known_decoder_divergence(err) {
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.