fuzz: Fix `hashes_json` roundtrip check
What changed, and why it matters
This commit fixes a fuzz test (an automated correctness test) in the rust-bitcoin project. The test previously compared raw input bytes to re-serialized JSON bytes, which can fail for harmless reasons like whitespace or key ordering. The fix compares the parsed Rust data structures instead, which is the correct way to verify round-trip behavior. This is a test-only change and does not affect any production code or user-facing behavior.
No action required. This is a benign test-quality improvement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change is confined to fuzz/fuzz_targets/hashes/json.rs. It adds Debug and PartialEq derives to two test structs (Hmacs and Main) and changes the roundtrip assertion from comparing raw byte slices (data == serialized JSON) to comparing deserialized values (reparsed == original). This eliminates false positives caused by JSON formatting differences while preserving the actual roundtrip invariant. No library code, serialization logic, or cryptographic code is modified.
Changed components
fuzz/fuzz_targets/hashes/json.rsInspect captured patch +4 / −3
diff --git a/fuzz/fuzz_targets/hashes/json.rs b/fuzz/fuzz_targets/hashes/json.rs
index 954a02c2..81cc61d2 100644
--- a/fuzz/fuzz_targets/hashes/json.rs
+++ b/fuzz/fuzz_targets/hashes/json.rs
@@ -5,13 +5,13 @@ use bitcoin::hashes::{ripemd160, sha1, sha256d, sha512, Hmac};
use libfuzzer_sys::fuzz_target;
use serde::{Deserialize, Serialize};
-#[derive(Deserialize, Serialize)]
+#[derive(Debug, PartialEq, Deserialize, Serialize)]
struct Hmacs {
sha1: Hmac<sha1::Hash>,
sha512: Hmac<sha512::Hash>,
}
-#[derive(Deserialize, Serialize)]
+#[derive(Debug, PartialEq, Deserialize, Serialize)]
struct Main {
hmacs: Hmacs,
ripemd: ripemd160::Hash,
@@ -24,7 +24,8 @@ fn main() {}
fn do_test(data: &[u8]) {
if let Ok(m) = serde_json::from_slice::<Main>(data) {
let vec = serde_json::to_vec(&m).unwrap();
- assert_eq!(data, &vec[..]);
+ let reparsed = serde_json::from_slice::<Main>(&vec).unwrap();
+ assert_eq!(reparsed, m);
}
}
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.