Skip to content

Commit

Permalink
✨ feat/added optional fuzzing statistics (#144)
Browse files Browse the repository at this point in the history
* Optionaly show stats during fuzzing session

* 🐛 (store failed txs): Store failex txs

* 🩹 Simplified stats logging

* 📝 Added fuzzing stats to docs

* ✨ Added failed invariants check stats

---------

Co-authored-by: Ikrk <ikrk@centrum.cz>
  • Loading branch information
lukacan and Ikrk committed Jun 7, 2024
1 parent 36664f1 commit 8e0d235
Show file tree
Hide file tree
Showing 22 changed files with 660 additions and 96 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
incremented upon a breaking change and the patch version will be incremented for features.

## [dev] - Unreleased
- feat/fuzzer-stats-logging, an optional statistics output for fuzzing session ([#144](https://github.com/Ackee-Blockchain/trident/pull/144))

## [0.6.0] - 2024-05-20
### Added
Expand Down
55 changes: 54 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,4 @@ solana-bpf-loader-program = "1.16"
solana-program = "1.16"
solana-sdk-macro = "1.16"
solana-system-program = "1.16"
prettytable = "0.10.0"
52 changes: 36 additions & 16 deletions crates/client/derive/fuzz_test_executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,27 +47,47 @@ pub fn fuzz_test_executor(input: TokenStream) -> TokenStream {
match duplicate_tx {
Some(_) => eprintln!("\x1b[1;93mWarning\x1b[0m: Skipping duplicate instruction `{}`", self.to_context_string()),
None => {
#[cfg(fuzzing_with_stats)]
let mut stats_logger = FuzzingStatistics::new();
#[cfg(fuzzing_with_stats)]
stats_logger.increase_invoked(self.to_context_string());

let tx_result = client.process_transaction(transaction)
.map_err(|e| e.with_origin(Origin::Instruction(self.to_context_string())));

match tx_result {
Ok(_) => {
snaphot.capture_after(client).unwrap();
let (acc_before, acc_after) = snaphot.get_snapshot()
.map_err(|e| e.with_origin(Origin::Instruction(self.to_context_string())))
.expect("Snapshot deserialization expect"); // we want to panic if we cannot unwrap to cause a crash
Ok(_) => {
#[cfg(fuzzing_with_stats)]
stats_logger.increase_successful(self.to_context_string());

snaphot.capture_after(client).unwrap();
let (acc_before, acc_after) = snaphot.get_snapshot()
.map_err(|e| e.with_origin(Origin::Instruction(self.to_context_string())))
.expect("Snapshot deserialization expect"); // we want to panic if we cannot unwrap to cause a crash

if let Err(e) = ix.check(acc_before, acc_after, data).map_err(|e| e.with_origin(Origin::Instruction(self.to_context_string()))) {
#[cfg(fuzzing_with_stats)]
{
stats_logger.increase_failed_check(self.to_context_string());
stats_logger.output_serialized();
}
eprintln!(
"\x1b[31mCRASH DETECTED!\x1b[0m Custom check after the {} instruction did not pass!",
self.to_context_string());
panic!("{}", e)
}
#[cfg(fuzzing_with_stats)]
stats_logger.output_serialized();

if let Err(e) = ix.check(acc_before, acc_after, data).map_err(|e| e.with_origin(Origin::Instruction(self.to_context_string()))) {
eprintln!(
"\x1b[31mCRASH DETECTED!\x1b[0m Custom check after the {} instruction did not pass!",
self.to_context_string());
panic!("{}", e)
},
Err(e) => {
#[cfg(fuzzing_with_stats)]
{
stats_logger.increase_failed(self.to_context_string());
stats_logger.output_serialized();
}
let mut raw_accounts = snaphot.get_raw_pre_ix_accounts();
ix.tx_error_handler(e, data, &mut raw_accounts)?
}
},
Err(e) => {
let mut raw_accounts = snaphot.get_raw_pre_ix_accounts();
ix.tx_error_handler(e, data, &mut raw_accounts)?
}
}
}
}
Expand Down
Loading

0 comments on commit 8e0d235

Please sign in to comment.