Skip to content

Commit a06d909

Browse files
authored
Merge pull request #940 from openmina/tx_fuzzer_updates
Tx fuzzer updates
2 parents 80af68b + 200bd7d commit a06d909

File tree

5 files changed

+53
-13
lines changed

5 files changed

+53
-13
lines changed

.github/workflows/ci.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,24 @@ jobs:
4343
cd ledger
4444
cargo test --release -- -Z unstable-options --report-time
4545
46+
tx-fuzzer-check:
47+
runs-on: ubuntu-20.04
48+
steps:
49+
- name: Git checkout
50+
uses: actions/checkout@v4
51+
- name: Setup build dependencies
52+
run: |
53+
sudo apt update
54+
sudo apt install -y protobuf-compiler
55+
- name: Setup Rust
56+
run: |
57+
rustup install nightly
58+
rustup override set nightly
59+
- name: Check for compilation errors in transaction fuzzer
60+
run: |
61+
cd tools/fuzzing
62+
cargo check
63+
4664
p2p-tests:
4765
runs-on: ubuntu-20.04
4866
steps:

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ledger/src/scan_state/transaction_logic.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ use std::fmt::Display;
44
use ark_ff::fields::arithmetic::InvalidBigInt;
55
use ark_ff::Zero;
66
use itertools::{FoldWhile, Itertools};
7-
use mina_hasher::Fp;
7+
use mina_hasher::{Fp, Hashable, ROInput};
88
use mina_p2p_messages::binprot;
99
use mina_p2p_messages::v2::{MinaBaseUserCommandStableV2, MinaTransactionTransactionStableV2};
1010
use mina_signer::CompressedPubKey;
11+
use mina_signer::NetworkId;
1112
use openmina_core::constants::ConstraintConstants;
1213
use openmina_macros::SerdeYojsonEnum;
1314
use poseidon::hash::params::{CODA_RECEIPT_UC, MINA_ZKAPP_MEMO};
@@ -4215,6 +4216,25 @@ pub mod zkapp_statement {
42154216
}
42164217
}
42174218

4219+
impl Hashable for TransactionCommitment {
4220+
type D = NetworkId;
4221+
4222+
fn to_roinput(&self) -> ROInput {
4223+
let mut roi = ROInput::new();
4224+
roi = roi.append_field(self.0);
4225+
roi
4226+
}
4227+
4228+
fn domain_string(network_id: NetworkId) -> Option<String> {
4229+
match network_id {
4230+
NetworkId::MAINNET => openmina_core::network::mainnet::SIGNATURE_PREFIX,
4231+
NetworkId::TESTNET => openmina_core::network::devnet::SIGNATURE_PREFIX,
4232+
}
4233+
.to_string()
4234+
.into()
4235+
}
4236+
}
4237+
42184238
#[derive(Clone, Debug)]
42194239
pub struct ZkappStatement {
42204240
pub account_update: TransactionCommitment,

tools/fuzzing/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ edition = "2021"
66

77
[dependencies]
88
ark-serialize = "0.4.2"
9+
poseidon = { workspace = true }
910
mina-hasher = { workspace = true }
1011
mina-signer = { workspace = true }
1112
mina-curves = { workspace = true }

tools/fuzzing/src/transaction_fuzzer/mutator.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use crate::transaction_fuzzer::generator::gen_curve_point;
99
use ark_ff::Zero;
1010
use ledger::{
1111
generators::zkapp_command_builder::get_transaction_commitments,
12-
hash_with_kimchi,
1312
scan_state::{
1413
currency::{Amount, Balance, Fee, MinMax, Nonce, Signed, Slot},
1514
transaction_logic::{
@@ -40,6 +39,7 @@ use mina_p2p_messages::{
4039
},
4140
};
4241
use mina_signer::{CompressedPubKey, NetworkId, Signature, Signer};
42+
use poseidon::hash::{hash_with_kimchi, params::MINA_ACCOUNT_UPDATE_CONS};
4343
use rand::{seq::SliceRandom, Rng};
4444

4545
#[coverage(off)]
@@ -321,15 +321,13 @@ impl MutatorFromAccount<Timing> for FuzzerCtx {
321321
_ => unimplemented!(),
322322
}
323323
}
324-
} else {
325-
if self.gen.rng.gen_bool(0.5) {
326-
*t = Timing::Timed {
327-
initial_minimum_balance: self.gen(),
328-
cliff_time: self.gen(),
329-
cliff_amount: self.gen(),
330-
vesting_period: self.gen(),
331-
vesting_increment: self.gen(),
332-
}
324+
} else if self.gen.rng.gen_bool(0.5) {
325+
*t = Timing::Timed {
326+
initial_minimum_balance: self.gen(),
327+
cliff_time: self.gen(),
328+
cliff_amount: self.gen(),
329+
vesting_period: self.gen(),
330+
vesting_increment: self.gen(),
333331
}
334332
}
335333
}
@@ -708,8 +706,10 @@ impl Mutator<zkapp_command::CallForest<AccountUpdate>> for FuzzerCtx {
708706
Fp::zero()
709707
};
710708

711-
t.0[i].stack_hash =
712-
MutableFp::new(hash_with_kimchi("MinaAcctUpdateCons", &[tree_digest, h_tl]));
709+
t.0[i].stack_hash = MutableFp::new(hash_with_kimchi(
710+
&MINA_ACCOUNT_UPDATE_CONS,
711+
&[tree_digest, h_tl],
712+
));
713713
}
714714
}
715715
}

0 commit comments

Comments
 (0)