Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optionaly show stats during fuzzing session #144

Merged
merged 5 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading