Skip to content

Commit 6cfeeea

Browse files
authored
Merge pull request #3717 from autonomys/staking_fuzzer
SRLabs: Introduce fuzzing harness for pallet-domains
2 parents 2c32e30 + 8238e3b commit 6cfeeea

File tree

24 files changed

+1400
-452
lines changed

24 files changed

+1400
-452
lines changed

.github/workflows/rust.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,32 @@ jobs:
376376
run: |
377377
scripts/runtime-benchmark.sh
378378
379+
staking-fuzzer-test:
380+
name: staking-fuzzer-test (Linux x86-64)
381+
# Fuzzing is most efficient on Linux, it doesn't matter if it fails on other OSes.
382+
# Our runs-on instances don't have the required packages
383+
runs-on: ubuntu-22.04
384+
# Don't use the full 6 hours if fuzzing hangs
385+
timeout-minutes: 120
386+
env:
387+
AFL_SKIP_CPUFREQ: 1
388+
AFL_I_DONT_CARE_ABOUT_MISSING_CRASHES: 1
389+
steps:
390+
- name: Checkout
391+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
392+
393+
- name: Apt update
394+
run: sudo apt-get update
395+
396+
- name: install dependencies
397+
run: sudo apt install -y protobuf-compiler binutils-dev coreutils
398+
399+
- name: install ziggy
400+
run: cargo install --force ziggy cargo-afl honggfuzz grcov
401+
402+
- name: test fuzzer
403+
run: scripts/run-fuzzer.sh
404+
379405
# This job checks all crates individually, including no_std and other featureless builds.
380406
# We need to check crates individually for missing features, because cargo does feature
381407
# unification, which hides missing features when crates are built together.
@@ -503,6 +529,7 @@ jobs:
503529
- check-runtime-benchmarks
504530
- cargo-check-individually
505531
- cargo-unused-deps
532+
- staking-fuzzer-test
506533
steps:
507534
- name: Check job statuses
508535
# Another hack is to actually check the status of the dependencies or else it'll fall through
@@ -515,3 +542,4 @@ jobs:
515542
[[ "${{ needs.check-runtime-benchmarks.result }}" == "success" ]] || exit 1
516543
[[ "${{ needs.cargo-check-individually.result }}" == "success" ]] || exit 1
517544
[[ "${{ needs.cargo-unused-deps.result }}" == "success" ]] || exit 1
545+
[[ "${{ needs.staking-fuzzer-test.result }}" == "success" ]] || exit 1

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
/.idea
22
/target
3+
/test/subspace-test-fuzzer/target
4+
/test/subspace-test-fuzzer/output

Cargo.lock

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ members = [
1717
"domains/test/utils",
1818
"shared/*",
1919
"test/subspace-test-client",
20+
"test/subspace-test-fuzzer",
2021
"test/subspace-test-runtime",
2122
"test/subspace-test-service",
2223
]
@@ -36,6 +37,7 @@ auto-id-domain-runtime = { version = "0.1.0", path = "domains/runtime/auto-id" }
3637
auto-id-domain-test-runtime = { version = "0.1.0", path = "domains/test/runtime/auto-id" }
3738
backoff = "0.4.0"
3839
base58 = "0.2.0"
40+
bincode = { version = "1.3.3" }
3941
bip39 = "2.0.0"
4042
bitvec = "1.0.1"
4143
blake2 = { version = "0.10.6", default-features = false }
@@ -300,6 +302,7 @@ unsigned-varint = "0.8.0"
300302
void = "1.0.2"
301303
x509-parser = "0.16.0"
302304
zeroize = "1.8.1"
305+
ziggy = { version = "1.3.4", default-features = false }
303306

304307
# The list of dependencies below (which can be both direct and indirect dependencies) are crates
305308
# that are suspected to be CPU-intensive, and that are unlikely to require debugging (as some of

crates/pallet-domains/Cargo.toml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ sp-version = { workspace = true, features = ["serde"] }
3636
subspace-core-primitives.workspace = true
3737
subspace-runtime-primitives.workspace = true
3838

39+
# fuzz feature optional dependencies
40+
bincode = { workspace = true, optional = true }
41+
domain-pallet-executive = { workspace = true, optional = true, default-features = true }
42+
pallet-timestamp = { workspace = true, optional = true, default-features = true }
43+
pallet-block-fees = { workspace = true, optional = true, default-features = true }
44+
serde = { workspace = true, optional = true, features = ["derive"] }
45+
sp-externalities = { workspace = true, optional = true, default-features = true }
46+
sp-keystore = { workspace = true, optional = true, default-features = true }
47+
sp-state-machine = { workspace = true, optional = true, default-features = true }
48+
3949
[dev-dependencies]
4050
domain-pallet-executive.workspace = true
4151
hex-literal.workspace = true
@@ -85,3 +95,16 @@ runtime-benchmarks = [
8595
"sp-runtime/runtime-benchmarks",
8696
"sp-subspace-mmr/runtime-benchmarks",
8797
]
98+
99+
fuzz = [
100+
"bincode",
101+
"domain-pallet-executive",
102+
"hex-literal",
103+
"pallet-timestamp",
104+
"pallet-block-fees",
105+
"serde",
106+
"sp-externalities",
107+
"sp-keystore",
108+
"sp-state-machine",
109+
"std",
110+
]

crates/pallet-domains/src/benchmarking.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1487,6 +1487,6 @@ mod benchmarks {
14871487
impl_benchmark_test_suite!(
14881488
Domains,
14891489
crate::tests::new_test_ext_with_extensions(),
1490-
crate::tests::Test
1490+
crate::mock::Test
14911491
);
14921492
}

crates/pallet-domains/src/block_tree.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -639,11 +639,11 @@ pub(crate) fn invalid_bundle_authors_for_receipt<T: Config>(
639639
#[cfg(test)]
640640
mod tests {
641641
use super::*;
642+
use crate::mock::{BlockTreePruningDepth, Domains, Test};
642643
use crate::tests::{
643-
BlockTreePruningDepth, Domains, Test, create_dummy_bundle_with_receipts,
644-
create_dummy_receipt, extend_block_tree, extend_block_tree_from_zero,
645-
get_block_tree_node_at, new_test_ext_with_extensions, register_genesis_domain,
646-
run_to_block,
644+
create_dummy_bundle_with_receipts, create_dummy_receipt, extend_block_tree,
645+
extend_block_tree_from_zero, get_block_tree_node_at, new_test_ext_with_extensions,
646+
register_genesis_domain, run_to_block,
647647
};
648648
use crate::{FrozenDomains, RawOrigin as DomainOrigin};
649649
use frame_support::dispatch::RawOrigin;

crates/pallet-domains/src/domain_registry.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,8 @@ pub(crate) fn do_update_domain_allow_list<T: Config>(
398398
#[cfg(test)]
399399
mod tests {
400400
use super::*;
401-
use crate::tests::{TEST_RUNTIME_APIS, Test, new_test_ext};
401+
use crate::mock::Test;
402+
use crate::tests::{TEST_RUNTIME_APIS, new_test_ext};
402403
use domain_runtime_primitives::{AccountId20, AccountId20Converter, DEFAULT_EVM_CHAIN_ID};
403404
use frame_support::traits::Currency;
404405
use frame_support::{assert_err, assert_ok};

crates/pallet-domains/src/fuzz.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
mod fuzz_utils;
2+
mod staking;
3+
4+
pub use staking::run_staking_fuzz;

0 commit comments

Comments
 (0)