Skip to content

Commit

Permalink
fix(runtime-fuzzer): update wasm-smith fork & disable all traps in wa…
Browse files Browse the repository at this point in the history
…sm (#3404)
  • Loading branch information
StackOverflowExcept1on authored Oct 21, 2023
1 parent b2a628e commit 84dd258
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 54 deletions.
37 changes: 19 additions & 18 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 @@ -240,7 +240,7 @@ runtime-primitives = { package = "gear-runtime-primitives", path = "runtime/prim
service = { package = "gear-service", path = "node/service", default-features = false }
testing = { package = "gear-node-testing", path = "node/testing" }
vara-runtime = { path = "runtime/vara", default-features = false }
wasm-smith = { version = "0.11.4", git = "https://github.com/gear-tech/wasm-tools.git", branch = "gear-stable" }
wasm-smith = { version = "0.12.21", git = "https://github.com/gear-tech/wasm-tools.git", branch = "gear-stable" }
validator-set = { package = 'substrate-validator-set', git = 'https://github.com/gear-tech/substrate-validator-set.git', branch = 'gear-polkadot-v0.9.41-canary-revert-oom-changes', default-features = false }

# Substrate deps
Expand Down
1 change: 0 additions & 1 deletion utils/node-loader/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ pub fn get_wasm_gen_config(
injection_types,
params_config,
initial_pages: initial_pages as u32,
unreachable_enabled: false,
..Default::default()
}
}
1 change: 0 additions & 1 deletion utils/runtime-fuzzer/src/gear_calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,6 @@ fn config(
existing_addresses,
log_info,
params_config,
unreachable_enabled: false,
initial_pages: initial_pages as u32,
..Default::default()
}
Expand Down
18 changes: 1 addition & 17 deletions utils/wasm-gen/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
//!
//! fn my_config<'a>(u: &'a mut Unstructured<'a>) -> Result<WasmModuleConfig> {
//! let selectable_params = SelectableParams {
//! call_indirect_enabled: false,
//! allowed_instructions: vec![
//! InstructionKind::Numeric,
//! InstructionKind::Reference,
Expand All @@ -41,7 +40,6 @@
//! max_instructions: 100_000,
//! min_funcs: NonZeroUsize::new(15).unwrap(),
//! max_funcs: NonZeroUsize::new(30).unwrap(),
//! unreachable_enabled: true,
//! };
//! let arbitrary = ArbitraryParams::arbitrary(u)?;
//! Ok((selectable_params, arbitrary).into())
Expand Down Expand Up @@ -142,9 +140,6 @@ pub struct StandardGearWasmConfigsBundle<T = [u8; 32]> {
pub existing_addresses: Option<NonEmpty<T>>,
/// Flag which signals whether recursions must be removed.
pub remove_recursion: bool,
/// Flag which signals whether `call_indirect` instruction must be used
/// during wasm generation.
pub call_indirect_enabled: bool,
/// Injection type for each syscall.
pub injection_types: SysCallsInjectionTypes,
/// Config of gear wasm call entry-points (exports).
Expand All @@ -155,9 +150,6 @@ pub struct StandardGearWasmConfigsBundle<T = [u8; 32]> {
pub stack_end_page: Option<u32>,
/// Syscalls params config
pub params_config: SysCallsParamsConfig,
/// Flag which signals whether `unreachable` instruction must be used
/// during wasm generation.
pub unreachable_enabled: bool,
}

impl<T> Default for StandardGearWasmConfigsBundle<T> {
Expand All @@ -166,13 +158,11 @@ impl<T> Default for StandardGearWasmConfigsBundle<T> {
log_info: Some("StandardGearWasmConfigsBundle".into()),
existing_addresses: None,
remove_recursion: false,
call_indirect_enabled: true,
injection_types: SysCallsInjectionTypes::all_once(),
entry_points_set: Default::default(),
initial_pages: DEFAULT_INITIAL_SIZE,
stack_end_page: None,
params_config: SysCallsParamsConfig::default(),
unreachable_enabled: true,
}
}
}
Expand All @@ -183,20 +173,14 @@ impl<T: Into<Hash>> ConfigsBundle for StandardGearWasmConfigsBundle<T> {
log_info,
existing_addresses,
remove_recursion,
call_indirect_enabled,
injection_types,
entry_points_set,
initial_pages,
stack_end_page,
params_config,
unreachable_enabled,
} = self;

let selectable_params = SelectableParams {
call_indirect_enabled,
unreachable_enabled,
..SelectableParams::default()
};
let selectable_params = SelectableParams::default();

let mut syscalls_config_builder = SysCallsConfigBuilder::new(injection_types);
if let Some(log_info) = log_info {
Expand Down
24 changes: 10 additions & 14 deletions utils/wasm-gen/src/config/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

//! Config entities related to generating plain wasm module using `wasm-smith`.
//!
//! We don't give access to wasm_smith::`SwarmConfig` direct;y, but with several adaptors,
//! We don't give access to [`wasm_smith::SwarmConfig`] directly, but with several adaptors,
//! because valid wasm module is not always valid gear module. So, some configurational variables
//! can be arbitrary, but some must be constantly set. That's implemented with [`ArbitraryParams`]
//! and [`ConstantParams`].
Expand All @@ -31,7 +31,7 @@ use wasm_smith::{InstructionKind::*, InstructionKinds, SwarmConfig};

/// Wasm module generation config.
///
/// This config wraps the `wasm_smith::SwarmConfig`. That's to make it
/// This config wraps the [`wasm_smith::SwarmConfig`]. That's to make it
/// easy creating a configuration, which is custom, from one side, and,
/// from another side, results in generating valid gear wasm modules.
#[derive(Debug, Clone)]
Expand All @@ -58,6 +58,7 @@ impl From<(SelectableParams, ArbitraryParams)> for WasmModuleConfig {
let ConstantParams {
allow_start_export,
bulk_memory_enabled,
disallow_traps,
exceptions_enabled,
max_exports,
max_imports,
Expand All @@ -69,6 +70,7 @@ impl From<(SelectableParams, ArbitraryParams)> for WasmModuleConfig {
min_imports,
multi_value_enabled,
reference_types_enabled,
tail_call_enabled,
relaxed_simd_enabled,
saturating_float_to_int_enabled,
sign_extension_enabled,
Expand All @@ -82,12 +84,10 @@ impl From<(SelectableParams, ArbitraryParams)> for WasmModuleConfig {
} = ConstantParams::default();

let SelectableParams {
call_indirect_enabled,
allowed_instructions,
max_instructions,
min_funcs,
max_funcs,
unreachable_enabled,
} = selectable_params;

let min_funcs = min_funcs.get();
Expand Down Expand Up @@ -129,6 +129,7 @@ impl From<(SelectableParams, ArbitraryParams)> for WasmModuleConfig {
available_imports,
bulk_memory_enabled,
canonicalize_nans,
disallow_traps,
exceptions_enabled,
export_everything,
max_aliases,
Expand Down Expand Up @@ -168,6 +169,7 @@ impl From<(SelectableParams, ArbitraryParams)> for WasmModuleConfig {
min_uleb_size,
multi_value_enabled,
reference_types_enabled,
tail_call_enabled,
relaxed_simd_enabled,
saturating_float_to_int_enabled,
sign_extension_enabled,
Expand All @@ -178,8 +180,6 @@ impl From<(SelectableParams, ArbitraryParams)> for WasmModuleConfig {
max_table_elements,
table_max_size_required,
memory_grow_enabled,
call_indirect_enabled,
unreachable_instruction_enabled: unreachable_enabled,
})
}
}
Expand Down Expand Up @@ -289,6 +289,7 @@ impl Arbitrary<'_> for ArbitraryParams {
pub struct ConstantParams {
allow_start_export: bool,
bulk_memory_enabled: bool,
disallow_traps: bool,
exceptions_enabled: bool,
max_data_segments: usize,
max_exports: usize,
Expand All @@ -303,6 +304,7 @@ pub struct ConstantParams {
min_imports: usize,
multi_value_enabled: bool,
reference_types_enabled: bool,
tail_call_enabled: bool,
relaxed_simd_enabled: bool,
saturating_float_to_int_enabled: bool,
sign_extension_enabled: bool,
Expand All @@ -319,13 +321,15 @@ impl Default for ConstantParams {
sign_extension_enabled: false,
saturating_float_to_int_enabled: false,
reference_types_enabled: false,
tail_call_enabled: false,
// This is related to reference_types_enabled.
max_tables: 1,
simd_enabled: false,
float_enabled: false,
relaxed_simd_enabled: false,
exceptions_enabled: false,
memory64_enabled: false,
disallow_traps: true,
allow_start_export: false,
multi_value_enabled: false,
memory_grow_enabled: false,
Expand All @@ -346,9 +350,6 @@ impl Default for ConstantParams {
/// Selectable wasm module generation params.
#[derive(Debug, Clone)]
pub struct SelectableParams {
/// Flag signalizing whether `call_indirect` instruction
/// must be used or not.
pub call_indirect_enabled: bool,
/// Set of [`InstructionKind`], that are allowed to
/// be generated by `wasm-gen`.
pub allowed_instructions: Vec<InstructionKind>,
Expand All @@ -361,22 +362,17 @@ pub struct SelectableParams {
/// Maximum amount of functions `wasm-gen` will insert
/// into generated wasm.
pub max_funcs: NonZeroUsize,
/// Flag signalizing whether `unreachable` instruction
/// must be used or not.
pub unreachable_enabled: bool,
}

impl Default for SelectableParams {
fn default() -> Self {
Self {
call_indirect_enabled: true,
allowed_instructions: vec![
Numeric, Reference, Parametric, Variable, Table, Memory, Control,
],
max_instructions: 500,
min_funcs: NonZeroUsize::new(3).expect("from non zero value; qed."),
max_funcs: NonZeroUsize::new(5).expect("from non zero value; qed."),
unreachable_enabled: true,
}
}
}
2 changes: 0 additions & 2 deletions utils/wasm-gen/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,12 +344,10 @@ fn execute_wasm_with_custom_configs(
.with_entry_points_config(EntryPointsSet::Init)
.build(),
SelectableParams {
call_indirect_enabled: false,
allowed_instructions: vec![],
max_instructions: 0,
min_funcs: NonZeroUsize::new(1).unwrap(),
max_funcs: NonZeroUsize::new(1).unwrap(),
unreachable_enabled: true,
},
);

Expand Down

0 comments on commit 84dd258

Please sign in to comment.