lez-fuzzing/fuzz/fuzz_targets/fuzz_stateless_verification.rs

29 lines
990 B
Rust
Raw Normal View History

#![cfg_attr(feature = "fuzzer-libfuzzer", no_main)]
2026-04-13 16:03:20 +08:00
use arbitrary::Unstructured;
use common::transaction::LeeTransaction;
2026-04-13 16:03:20 +08:00
use fuzz_props::generators::arbitrary_transaction;
fuzz_props::fuzz_entry!(|data: &[u8]| {
2026-04-13 16:03:20 +08:00
let mut u = Unstructured::new(data);
// Path A: try to build a structured transaction from unstructured bytes
if let Ok(tx) = arbitrary_transaction(&mut u) {
let result = tx.clone().transaction_stateless_check();
// Idempotency: if check passes, re-checking the returned tx must also pass
if let Ok(checked_tx) = result {
let result2 = checked_tx.transaction_stateless_check();
assert!(
result2.is_ok(),
"stateless_check is not idempotent: second call failed"
);
}
}
// Path B: raw decode first, then check — must never panic
if let Ok(tx) = borsh::from_slice::<LeeTransaction>(data) {
2026-04-13 16:03:20 +08:00
let _ = tx.transaction_stateless_check();
}
});