Skip to content

Commit

Permalink
use a hack to make fuzzer building actually work (#10173)
Browse files Browse the repository at this point in the history
See discussion at [1]. Here, the solution is what would be a bad
solution for bolero upstream (because it no longer works with
un-harnessed fuzzers), but is fine enough for our use case.

[1] camshaft/bolero#196
  • Loading branch information
Ekleog-NEAR authored Nov 15, 2023
1 parent 2b3ba91 commit e1cec99
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 34 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/master_fuzzer_binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ jobs:
with:
crate: cargo-bolero
# TODO: remove the below once https://github.com/camshaft/bolero/pull/195 is released on crates.io
git: https://github.com/camshaft/bolero
rev: 8c5a50a57b0e4c4cc8111cfd95670dc75cd2dea7
# and https://github.com/camshaft/bolero/pull/196 has a proper fix
git: https://github.com/Ekleog-NEAR/bolero
rev: 8f4e49d65c702a2f9858ed3c217b1cb52ce91243

- run: rustup target add --toolchain nightly wasm32-unknown-unknown

Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/ondemand_fuzzer_binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ jobs:
- uses: baptiste0928/cargo-install@21a18ba3bf4a184d1804e8b759930d3471b1c941
with:
crate: cargo-bolero
# TODO: remove the below once https://github.com/camshaft/bolero/pull/195 lands
git: https://github.com/camshaft/bolero
rev: 8c5a50a57b0e4c4cc8111cfd95670dc75cd2dea7
# TODO: remove the below once https://github.com/camshaft/bolero/pull/195 is released on crates.io
# and https://github.com/camshaft/bolero/pull/196 has a proper fix
git: https://github.com/Ekleog-NEAR/bolero
rev: 8f4e49d65c702a2f9858ed3c217b1cb52ce91243

- run: rustup target add --toolchain nightly wasm32-unknown-unknown

Expand Down
24 changes: 8 additions & 16 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ bencher = "0.1.5"
bitflags = "1.2"
blake2 = "0.9.1"
bn = { package = "zeropool-bn", version = "0.5.11" }
bolero = { version = "0.10.0", features = ["arbitrary"] }
bolero = { version = "0.10.0", git = "https://github.com/Ekleog-NEAR/bolero", rev = "8f4e49d65c702a2f9858ed3c217b1cb52ce91243", features = ["arbitrary"] }
borsh = { version = "1.0.0", features = ["derive", "rc"] }
bs58 = "0.4"
bytes = "1"
Expand Down
2 changes: 1 addition & 1 deletion runtime/near-vm-runner/src/prepare/prepare_v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ mod test {
use crate::logic::{Config, ContractPrepareVersion};

#[test]
fn v1_preparation_generates_valid_contract() {
fn v1_preparation_generates_valid_contract_fuzzer() {
let mut config = Config::test();
let prepare_version = ContractPrepareVersion::V1;
config.limit_config.contract_prepare_version = prepare_version;
Expand Down
4 changes: 2 additions & 2 deletions runtime/near-vm-runner/src/prepare/prepare_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ mod test {
use crate::VMKind;

#[test]
fn v2_preparation_wasmtime_generates_valid_contract() {
fn v2_preparation_wasmtime_generates_valid_contract_fuzzer() {
let mut config = Config::test();
let prepare_version = ContractPrepareVersion::V2;
config.limit_config.contract_prepare_version = prepare_version;
Expand All @@ -393,7 +393,7 @@ mod test {
}

#[test]
fn v2_preparation_near_vm_generates_valid_contract() {
fn v2_preparation_near_vm_generates_valid_contract_fuzzer() {
let mut config = Config::test();
let prepare_version = ContractPrepareVersion::V2;
config.limit_config.contract_prepare_version = prepare_version;
Expand Down
11 changes: 5 additions & 6 deletions runtime/near-vm-runner/src/tests/fuzzers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::runner::VMResult;
use crate::ContractCode;
use crate::VMKind;
use arbitrary::Arbitrary;
use bolero::check;
use core::fmt;
use near_primitives_core::runtime::fees::RuntimeFeesConfig;

Expand Down Expand Up @@ -145,8 +144,8 @@ fn run_fuzz(code: &ContractCode, vm_kind: VMKind) -> VMResult {
}

#[test]
fn current_vm_does_not_crash() {
check!().with_arbitrary::<ArbitraryModule>().for_each(|module: &ArbitraryModule| {
fn current_vm_does_not_crash_fuzzer() {
bolero::check!().with_arbitrary::<ArbitraryModule>().for_each(|module: &ArbitraryModule| {
let code = ContractCode::new(module.0.module.to_bytes(), None);
let config = Config::test();
let _result = run_fuzz(&code, config.vm_kind);
Expand All @@ -155,8 +154,8 @@ fn current_vm_does_not_crash() {

#[test]
#[cfg_attr(not(all(feature = "near_vm", target_arch = "x86_64")), ignore)]
fn near_vm_and_wasmtime_agree() {
check!().with_arbitrary::<ArbitraryModule>().for_each(|module: &ArbitraryModule| {
fn near_vm_and_wasmtime_agree_fuzzer() {
bolero::check!().with_arbitrary::<ArbitraryModule>().for_each(|module: &ArbitraryModule| {
let code = ContractCode::new(module.0.module.to_bytes(), None);
let near_vm = run_fuzz(&code, VMKind::NearVm).expect("fatal failure");
let wasmtime = run_fuzz(&code, VMKind::Wasmtime).expect("fatal failure");
Expand All @@ -166,7 +165,7 @@ fn near_vm_and_wasmtime_agree() {

#[test]
#[cfg(all(feature = "near_vm", target_arch = "x86_64"))]
fn near_vm_is_reproducible() {
fn near_vm_is_reproducible_fuzzer() {
use crate::near_vm_runner::NearVM;
use near_primitives::hash::CryptoHash;

Expand Down
1 change: 0 additions & 1 deletion runtime/near-vm/types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,3 @@ bolero.workspace = true

[[test]]
name = "partial-sum-map"
harness = false
3 changes: 2 additions & 1 deletion runtime/near-vm/types/tests/partial-sum-map/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use near_vm_types::partial_sum_map::{Error, PartialSumMap};

fn main() {
#[test]
fn partial_sum_map_fuzzer() {
bolero::check!().with_type::<(Vec<(u32, u32)>, Vec<u32>)>().for_each(|input| {
let adds = &input.0;
let tests = &input.1;
Expand Down
2 changes: 1 addition & 1 deletion test-utils/runtime-tester/src/fuzzing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ mod tests {
}

#[test]
fn fuzz_scenario() {
fn scenario_fuzzer() {
bolero::check!()
.with_iterations(100) // Limit to 100 iterations, the default of 1000 would be too slow
.with_arbitrary::<Scenario>()
Expand Down

0 comments on commit e1cec99

Please sign in to comment.