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

Improve Fuzzing runs #402

Merged
merged 3 commits into from
Jan 14, 2025
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
49 changes: 49 additions & 0 deletions .github/workflows/evm-weekly-fuzzer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: EVM Template Fuzzer (Weekly run)

on:
schedule:
# Runs at 00:00 UTC every Sunday
- cron: '0 0 * * 0'
workflow_dispatch:

jobs:
generic-template-fuzzer:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable

- name: Add target
run: rustup target add wasm32-unknown-unknown

- name: Add dependencies
run: cargo install ziggy cargo-afl honggfuzz grcov

- name: Build AFL config
run: cargo afl config --build
working-directory: evm-template/template-fuzzer

- name: Run Ziggy Fuzzing
run: |
AFL_I_DONT_CARE_ABOUT_MISSING_CRASHES=1 timeout 5h cargo ziggy fuzz -t 20 || true
working-directory: evm-template/template-fuzzer

- name: Generate Ziggy Fuzzing Coverage Result
run: |
CARGO_HOME=.cargo cargo ziggy cover
working-directory: evm-template/template-fuzzer

- name: Zip Artifacts
run: zip artifacts.zip evm-template/template-fuzzer/output/* -r

- name: Save Artifacts
uses: actions/upload-artifact@v4
with:
name: fuzzing-artifacts
path: artifacts.zip
5 changes: 5 additions & 0 deletions .github/workflows/generic-weekly-fuzzer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ jobs:
run: |
AFL_I_DONT_CARE_ABOUT_MISSING_CRASHES=1 timeout 5h cargo ziggy fuzz -t 20 || true
working-directory: generic-template/template-fuzzer

- name: Generate Ziggy Fuzzing Coverage Result
run: |
CARGO_HOME=.cargo cargo ziggy cover
working-directory: generic-template/template-fuzzer

- name: Zip Artifacts
run: zip artifacts.zip generic-template/template-fuzzer/output/* -r
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@ docs/build
**/zombienet-linux-x64
**/bin-*

coverage
coverage

# fuzzing output
**/template-fuzzer/output
22 changes: 22 additions & 0 deletions evm-template/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 evm-template/template-fuzzer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
quinn-proto = { version = "0.9.6", features = [ "arbitrary" ] }
ziggy = { workspace = true }

evm-runtime-template = { path = "../runtime" }
Expand Down
21 changes: 9 additions & 12 deletions evm-template/template-fuzzer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ fn process_input(accounts: &[AccountId], genesis: &Storage, data: &[u8]) {
continue;
}
if lapse > 0 {
finalize_block(elapsed);
println!("\n time spent: {elapsed:?}");
assert!(elapsed.as_secs() <= 2, "block execution took too much time");

block += u32::from(lapse) * 393; // 393 * 256 = 100608 which nearly corresponds to a week
weight = 0.into();
Expand All @@ -126,14 +127,15 @@ fn process_input(accounts: &[AccountId], genesis: &Storage, data: &[u8]) {
println!(" call: {extrinsic:?}");

let now = Instant::now(); // We get the current time for timing purposes.

#[allow(unused_variables)]
let res = extrinsic.dispatch(RuntimeOrigin::signed(origin));
elapsed += now.elapsed();

println!(" result: {res:?}");
}

finalize_block(elapsed);
Executive::finalize_block();

check_invariants(block, initial_total_issuance);
});
Expand All @@ -142,11 +144,14 @@ fn process_input(accounts: &[AccountId], genesis: &Storage, data: &[u8]) {
fn initialize_block(block: u32) {
println!("\ninitializing block {}", block);

let current_timestamp = u64::from(block) * SLOT_DURATION;
let current_timestamp = u64::from(block) * SLOT_DURATION * 2;

let prev_header = match block {
1 => None,
_ => Some(Executive::finalize_block()),
_ => {
println!(" finalizing block");
Some(Executive::finalize_block())
}
};

let parent_header = &Header::new(
Expand Down Expand Up @@ -280,14 +285,6 @@ fn recursive_call_filter(call: &RuntimeCall, origin: usize) -> bool {
}
}

fn finalize_block(elapsed: Duration) {
println!("\n time spent: {elapsed:?}");
assert!(elapsed.as_secs() <= 2, "block execution took too much time");

println!(" finalizing block");
Executive::finalize_block();
}

fn check_invariants(block: u32, initial_total_issuance: Balance) {
let mut counted_free = 0;
let mut counted_reserved = 0;
Expand Down
22 changes: 22 additions & 0 deletions generic-template/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 generic-template/template-fuzzer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
quinn-proto = { version = "0.9.6", features = [ "arbitrary" ] }
ziggy = { workspace = true }

generic-runtime-template = { path = "../runtime" }
Expand Down
15 changes: 4 additions & 11 deletions generic-template/template-fuzzer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ fn process_input(accounts: &[AccountId], genesis: &Storage, data: &[u8]) {
}

if lapse > 0 {
finalize_block(elapsed);
println!("\n time spent: {elapsed:?}");
assert!(elapsed.as_secs() <= 2, "block execution took too much time");

block += u32::from(lapse) * 393; // 393 * 256 = 100608 which nearly corresponds to a week
weight = 0.into();
Expand Down Expand Up @@ -131,7 +132,7 @@ fn process_input(accounts: &[AccountId], genesis: &Storage, data: &[u8]) {
println!(" result: {res:?}");
}

finalize_block(elapsed);
Executive::finalize_block();

check_invariants(block, initial_total_issuance);
});
Expand All @@ -140,7 +141,7 @@ fn process_input(accounts: &[AccountId], genesis: &Storage, data: &[u8]) {
fn initialize_block(block: u32) {
println!("\ninitializing block {}", block);

let current_timestamp = u64::from(block) * SLOT_DURATION;
let current_timestamp = u64::from(block) * SLOT_DURATION * 2;

let prev_header = match block {
1 => None,
Expand Down Expand Up @@ -207,14 +208,6 @@ fn initialize_block(block: u32) {
// Calls that need to be called before each block starts (init_calls) go here
}

fn finalize_block(elapsed: Duration) {
println!("\n time spent: {elapsed:?}");
assert!(elapsed.as_secs() <= 2, "block execution took too much time");

println!(" finalizing block");
Executive::finalize_block();
}

fn check_invariants(block: u32, initial_total_issuance: Balance) {
let mut counted_free = 0;
let mut counted_reserved = 0;
Expand Down
Loading