Skip to content

Commit 5735da9

Browse files
feat(fuzz): verify serialization stability in block_roundtrip
Improve the block_roundtrip fuzz target to test that serialization is deterministic by verifying that deserialize -> serialize -> deserialize -> serialize produces identical output.
1 parent cde2576 commit 5735da9

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

fuzz/fuzz_targets/block_roundtrip.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,17 @@ use bitcoinkernel::Block;
44
use libfuzzer_sys::fuzz_target;
55

66
fuzz_target!(|data: &[u8]| {
7-
if let Ok(block) = Block::try_from(data) {
8-
let block_serialized: Vec<u8> = block.try_into().unwrap();
9-
assert!(data.len() >= block_serialized.len());
10-
}
7+
let Ok(block) = Block::try_from(data) else {
8+
return;
9+
};
10+
11+
let serialized: Vec<u8> = block.try_into().unwrap();
12+
let roundtrip =
13+
Block::try_from(serialized.as_slice()).expect("Serialized block should deserialize");
14+
let reserialized: Vec<u8> = roundtrip.try_into().unwrap();
15+
16+
assert_eq!(
17+
serialized, reserialized,
18+
"Serialization must be stable across roundtrips"
19+
);
1120
});

0 commit comments

Comments
 (0)