Skip to content

Commit

Permalink
fuzz: add txs_prepare_proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
tzemanovic committed Jul 16, 2024
1 parent aacd0c5 commit f6d4f32
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ bench:
fuzz-txs-mempool:
$(cargo) +$(nightly) fuzz run txs_mempool --dev

fuzz-txs-prepare-proposal:
$(cargo) +$(nightly) fuzz run txs_prepare_proposal --dev

build-doc:
$(cargo) doc --no-deps

Expand Down
9 changes: 9 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ lazy_static.workspace = true
libfuzzer-sys = "0.4"

[[bin]]
name = "txs_mempool"
path = "fuzz_targets/txs_mempool.rs"
test = false
doc = false
bench = false

[[bin]]
name = "txs_prepare_proposal"
path = "fuzz_targets/txs_prepare_proposal.rs"
test = false
doc = false
bench = false
33 changes: 33 additions & 0 deletions fuzz/fuzz_targets/txs_prepare_proposal.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#![no_main]

use lazy_static::lazy_static;
use libfuzzer_sys::fuzz_target;
use namada_node::facade::tendermint_proto::v0_37::abci::RequestPrepareProposal;
use namada_node::shell;
use namada_node::shell::test_utils::TestShell;
use namada_node::shims::abcipp_shim_types::shim::TxBytes;
use namada_tx::Tx;

lazy_static! {
static ref SHELL: TestShell = {
let (shell, _recv, _, _) = shell::test_utils::setup();
shell
};
}

fuzz_target!(|txs: Vec<Tx>| {
let mut txs_bytes: Vec<TxBytes> = Vec::with_capacity(txs.len());
for tx in txs {
if let Ok(tx_bytes) = tx.try_to_bytes() {
txs_bytes.push(tx_bytes.into());
} else {
return;
}
}

let req = RequestPrepareProposal {
txs: txs_bytes,
..Default::default()
};
SHELL.prepare_proposal(req);
});

0 comments on commit f6d4f32

Please sign in to comment.