-
Notifications
You must be signed in to change notification settings - Fork 95
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
Add grammar aware fuzzing #188
Conversation
fuzz/fuzz_targets/fuzzed_ops.rs
Outdated
@@ -0,0 +1,166 @@ | |||
use fuel_vm::prelude::{Opcode, RegisterId, Immediate12, Immediate18, Immediate24}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that deriving arbitrary::Arbitrary
in https://github.com/FuelLabs/fuel-asm/blob/master/src/opcode.rs would eliminate the need for this file
@vlopes11 when I run
|
Its because |
@mediremi its updated in |
Merge conflicts with master have been fixed 👍 Only remaining issue now is that sometimes the fuzzer will discover infinite loops and timeout (which we seem to be running into due to using a gas price of 0). What's the best way to update the Here's an example of an infinite loop found by the fuzzer: use fuel_vm::prelude::*;
/*
FuzzData {
program: [],
script_data: [
52,
90,
231,
181,
74,
66,
],
}
*/
#[test]
fn infinite_loop() {
let mut client = MemoryClient::default();
let gas_price = 0;
let gas_limit = 1_000_000;
let maturity = 0;
let height = 0;
let params = ConsensusParameters::DEFAULT;
let mut tx = Transaction::script(
gas_price,
gas_limit,
maturity,
vec![],
vec![
52,
90,
231,
181,
74,
66,
],
vec![],
vec![],
vec![],
)
.check(height, ¶ms)
.expect("failed to generate a checked tx");
client.transact(tx);
} |
Gas will be charged regardless of the price. The price will only interfere in the post-execution to deduct the consumed gas from the base asset. Even with a gas price of If could be that we have too much gas available, and the fuzzy thread is just timing out before the gas runs out. Every script is expected to end with a I'll take a look into the execution of the script you posted! |
Confirmed. The gas is being deducted correctly and we are basically executing One alternative is to always put a The gas-tuning is still a |
Since adding |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Thanks a lot for the contribution
Looks like I don't have permission to merge this PR so feel free to merge in your own time 👍 |
This looks great! This will be a helpful reference for us to start doing more advanced fuzzing use-cases. |
Add grammar aware fuzzing using cargo-fuzz and arbitrary.
Installing the fuzzer
rustup toolchain install nightly
cargo +nightly install cargo-fuzz
Running the fuzzer
make fuzz
(orcargo +nightly fuzz run grammar_aware
)Checking fuzzer's coverage
rustup component add llvm-tools-preview --toolchain nightly
cargo +nightly install rustfilt
cargo +nightly fuzz coverage grammar_aware
$(find $(rustc --print sysroot) -name llvm-cov) show -Xdemangler=rustfilt fuzz/target/x86_64-unknown-linux-gnu/release/grammar_aware -instr-profile=fuzz/coverage/<fuzz target>/coverage.profdata -show-line-counts-or-regions -show-instantiations