Skip to content

Commit b1e70d8

Browse files
authored
Merge pull request #852 from openmina/tx_fuzzer_fixes
transaction fuzzer: fix delayed hash calculation. Add seed cmdline ar…
2 parents e3a3406 + 793ece1 commit b1e70d8

File tree

2 files changed

+45
-9
lines changed

2 files changed

+45
-9
lines changed

tools/fuzzing/src/main.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -278,15 +278,25 @@ fn main() {
278278
.long("fuzzcase")
279279
.value_name("FILE"),
280280
)
281+
.arg(
282+
clap::Arg::new("seed")
283+
.short('s')
284+
.long("seed")
285+
.default_value("42")
286+
.value_parser(clap::value_parser!(u64)),
287+
)
281288
.get_matches();
282289

283290
let mut child = Command::new(
284-
&std::env::var("OCAML_TRANSACTION_FUZZER_PATH").unwrap_or_else(|_| {
285-
format!(
286-
"{}/mina/_build/default/src/app/transaction_fuzzer/transaction_fuzzer.exe",
287-
std::env::var("HOME").unwrap()
288-
)
289-
}),
291+
&std::env::var("OCAML_TRANSACTION_FUZZER_PATH").unwrap_or_else(
292+
#[coverage(off)]
293+
|_| {
294+
format!(
295+
"{}/mina/_build/default/src/app/transaction_fuzzer/transaction_fuzzer.exe",
296+
std::env::var("HOME").unwrap()
297+
)
298+
},
299+
),
290300
)
291301
.arg("execute")
292302
.stdin(Stdio::piped())
@@ -302,8 +312,12 @@ fn main() {
302312
println!("Reproducing fuzzcase from file: {}", fuzzcase);
303313
transaction_fuzzer::reproduce(stdin, stdout, fuzzcase);
304314
} else {
305-
println!("Running the fuzzer...");
306-
transaction_fuzzer::fuzz(stdin, stdout, true, 42, 1000);
315+
let Some(seed) = matches.get_one::<u64>("seed") else {
316+
unreachable!()
317+
};
318+
319+
println!("Running the fuzzer with seed {seed}...");
320+
transaction_fuzzer::fuzz(stdin, stdout, true, *seed, 1000);
307321
}
308322
}
309323
}

tools/fuzzing/src/transaction_fuzzer/context.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use crate::transaction_fuzzer::{
55
};
66
use ark_ff::fields::arithmetic::InvalidBigInt;
77
use ark_ff::Zero;
8-
use ledger::scan_state::currency::{Amount, Fee, Length, Magnitude, Nonce, Signed, Slot};
98
use ledger::scan_state::transaction_logic::protocol_state::{
109
protocol_state_view, EpochData, EpochLedger, ProtocolStateView,
1110
};
@@ -15,6 +14,10 @@ use ledger::scan_state::transaction_logic::transaction_applied::{
1514
use ledger::scan_state::transaction_logic::{
1615
apply_transactions, Transaction, TransactionStatus, UserCommand,
1716
};
17+
use ledger::scan_state::{
18+
currency::{Amount, Fee, Length, Magnitude, Nonce, Signed, Slot},
19+
transaction_logic::transaction_applied,
20+
};
1821
use ledger::sparse_ledger::LedgerIntf;
1922
use ledger::staged_ledger::staged_ledger::StagedLedger;
2023
use ledger::{dummy, Account, AccountId, Database, Mask, Timing, TokenId};
@@ -1103,6 +1106,25 @@ impl FuzzerCtx {
11031106
// For now we work with one transaction at a time
11041107
let applied = &applied[0];
11051108

1109+
match &applied.varying {
1110+
transaction_applied::Varying::Command(command_applied) => {
1111+
match command_applied {
1112+
transaction_applied::CommandApplied::SignedCommand(
1113+
_signed_command_applied,
1114+
) => {}
1115+
transaction_applied::CommandApplied::ZkappCommand(
1116+
zkapp_command_applied,
1117+
) => zkapp_command_applied
1118+
.command
1119+
.data
1120+
.account_updates
1121+
.accumulate_hashes(), // Needed because of delayed hashing
1122+
}
1123+
}
1124+
transaction_applied::Varying::FeeTransfer(_fee_transfer_applied) => {}
1125+
transaction_applied::Varying::Coinbase(_coinbase_applied) => {}
1126+
}
1127+
11061128
if expected_apply_result.apply_result.len() != 1 {
11071129
println!(
11081130
"!!! Apply failed in OCaml (error: {}) but it didn't in Rust: {:?}",

0 commit comments

Comments
 (0)