lez-fuzzing/fuzz/fuzz_targets/fuzz_transaction_decoding.rs

27 lines
930 B
Rust
Raw Normal View History

#![cfg_attr(feature = "fuzzer-libfuzzer", no_main)]
2026-04-13 16:03:20 +08:00
use common::{
block::{Block, HashableBlockData},
transaction::LeeTransaction,
2026-04-13 16:03:20 +08:00
};
fuzz_props::fuzz_entry!(|data: &[u8]| {
// Attempt 1: decode as LeeTransaction and verify roundtrip
if let Ok(tx) = borsh::from_slice::<LeeTransaction>(data) {
2026-04-13 16:03:20 +08:00
let re_encoded = borsh::to_vec(&tx).expect("re-encode of valid tx must succeed");
let tx2 = borsh::from_slice::<LeeTransaction>(&re_encoded)
2026-04-13 16:03:20 +08:00
.expect("second decode of re-encoded tx must succeed");
assert_eq!(
2026-04-24 12:04:20 +08:00
re_encoded,
2026-04-13 16:03:20 +08:00
borsh::to_vec(&tx2).unwrap(),
"LeeTransaction roundtrip encoding divergence"
2026-04-13 16:03:20 +08:00
);
}
// Attempt 2: decode as Block — must never panic
let _ = borsh::from_slice::<Block>(data);
// Attempt 3: decode as HashableBlockData — must never panic
let _ = borsh::from_slice::<HashableBlockData>(data);
});