Skip to content
This repository was archived by the owner on Jun 16, 2020. It is now read-only.
Open
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
target
Cargo.lock
rusty-tags.*
tags
30 changes: 15 additions & 15 deletions src/limits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@
* limitations under the License.
*/

// The following limits are imposed by wasmparser on WebAssembly modules.
// The limits are agreed upon with other engines for consistency.
pub const MAX_WASM_TYPES: usize = 1_000_000;
pub const MAX_WASM_FUNCTIONS: usize = 1_000_000;
pub const _MAX_WASM_IMPORTS: usize = 100_000;
pub const _MAX_WASM_EXPORTS: usize = 100_000;
pub const MAX_WASM_GLOBALS: usize = 1_000_000;
pub const _MAX_WASM_DATA_SEGMENTS: usize = 100_000;
pub const MAX_WASM_MEMORY_PAGES: usize = 65536;
// The following limits are updated to fit the restrictions of a WASM smart
// contract, which should be much lower than for the usual WASM use-case.
pub const MAX_WASM_TYPES: usize = 10_000;
pub const MAX_WASM_FUNCTIONS: usize = 10_000;
pub const _MAX_WASM_IMPORTS: usize = 1000;
pub const _MAX_WASM_EXPORTS: usize = 1000;
pub const MAX_WASM_GLOBALS: usize = 4000; // max 32K
pub const _MAX_WASM_DATA_SEGMENTS: usize = 10_000;
pub const MAX_WASM_MEMORY_PAGES: usize = 1000; // max 64M memory
pub const MAX_WASM_STRING_SIZE: usize = 100_000;
pub const _MAX_WASM_MODULE_SIZE: usize = 1024 * 1024 * 1024; //= 1 GiB
pub const _MAX_WASM_MODULE_SIZE: usize = 1024 * 1024 * 32; // 32M
pub const MAX_WASM_FUNCTION_SIZE: usize = 128 * 1024;
pub const MAX_WASM_FUNCTION_LOCALS: usize = 50000;
pub const MAX_WASM_FUNCTION_PARAMS: usize = 1000;
pub const MAX_WASM_FUNCTION_RETURNS: usize = 1000;
pub const _MAX_WASM_TABLE_SIZE: usize = 10_000_000;
pub const MAX_WASM_TABLE_ENTRIES: usize = 10_000_000;
pub const MAX_WASM_FUNCTION_LOCALS: usize = 4000;
pub const MAX_WASM_FUNCTION_PARAMS: usize = 100;
pub const MAX_WASM_FUNCTION_RETURNS: usize = 100;
pub const _MAX_WASM_TABLE_SIZE: usize = 10_000;
pub const MAX_WASM_TABLE_ENTRIES: usize = 10_000;
pub const MAX_WASM_TABLES: usize = 1;
pub const MAX_WASM_MEMORIES: usize = 1;
64 changes: 32 additions & 32 deletions src/operators_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,18 +693,18 @@ impl OperatorValidator {
}

#[cfg(feature = "deterministic")]
fn check_non_deterministic_enabled(&self) -> OperatorValidatorResult<()> {
if !self.config.deterministic_only {
fn check_deterministic_only(&self) -> OperatorValidatorResult<()> {
if self.config.deterministic_only {
return Err(OperatorValidatorError::new(
"deterministic_only support is not enabled",
"only deterministic operations are allowed",
));
}
Ok(())
}

#[inline(always)]
#[cfg(not(feature = "deterministic"))]
fn check_non_deterministic_enabled(&self) -> OperatorValidatorResult<()> {
fn check_deterministic_only(&self) -> OperatorValidatorResult<()> {
Ok(())
}

Expand Down Expand Up @@ -1098,13 +1098,13 @@ impl OperatorValidator {
self.func_state.change_frame_with_type(1, Type::I64)?;
}
Operator::F32Load { memarg } => {
self.check_non_deterministic_enabled()?;
self.check_deterministic_only()?;
self.check_memarg(memarg, 2, resources)?;
self.check_operands_1(Type::I32)?;
self.func_state.change_frame_with_type(1, Type::F32)?;
}
Operator::F64Load { memarg } => {
self.check_non_deterministic_enabled()?;
self.check_deterministic_only()?;
self.check_memarg(memarg, 3, resources)?;
self.check_operands_1(Type::I32)?;
self.func_state.change_frame_with_type(1, Type::F64)?;
Expand Down Expand Up @@ -1170,13 +1170,13 @@ impl OperatorValidator {
self.func_state.change_frame(2)?;
}
Operator::F32Store { memarg } => {
self.check_non_deterministic_enabled()?;
self.check_deterministic_only()?;
self.check_memarg(memarg, 2, resources)?;
self.check_operands_2(Type::I32, Type::F32)?;
self.func_state.change_frame(2)?;
}
Operator::F64Store { memarg } => {
self.check_non_deterministic_enabled()?;
self.check_deterministic_only()?;
self.check_memarg(memarg, 3, resources)?;
self.check_operands_2(Type::I32, Type::F64)?;
self.func_state.change_frame(2)?;
Expand Down Expand Up @@ -1222,11 +1222,11 @@ impl OperatorValidator {
Operator::I32Const { .. } => self.func_state.change_frame_with_type(0, Type::I32)?,
Operator::I64Const { .. } => self.func_state.change_frame_with_type(0, Type::I64)?,
Operator::F32Const { .. } => {
self.check_non_deterministic_enabled()?;
self.check_deterministic_only()?;
self.func_state.change_frame_with_type(0, Type::F32)?;
}
Operator::F64Const { .. } => {
self.check_non_deterministic_enabled()?;
self.check_deterministic_only()?;
self.func_state.change_frame_with_type(0, Type::F64)?;
}
Operator::I32Eqz => {
Expand Down Expand Up @@ -1269,7 +1269,7 @@ impl OperatorValidator {
| Operator::F32Gt
| Operator::F32Le
| Operator::F32Ge => {
self.check_non_deterministic_enabled()?;
self.check_deterministic_only()?;
self.check_operands_2(Type::F32, Type::F32)?;
self.func_state.change_frame_with_type(2, Type::I32)?;
}
Expand All @@ -1279,7 +1279,7 @@ impl OperatorValidator {
| Operator::F64Gt
| Operator::F64Le
| Operator::F64Ge => {
self.check_non_deterministic_enabled()?;
self.check_deterministic_only()?;
self.check_operands_2(Type::F64, Type::F64)?;
self.func_state.change_frame_with_type(2, Type::I32)?;
}
Expand Down Expand Up @@ -1334,7 +1334,7 @@ impl OperatorValidator {
| Operator::F32Trunc
| Operator::F32Nearest
| Operator::F32Sqrt => {
self.check_non_deterministic_enabled()?;
self.check_deterministic_only()?;
self.check_operands_1(Type::F32)?;
self.func_state.change_frame_with_type(1, Type::F32)?;
}
Expand All @@ -1345,7 +1345,7 @@ impl OperatorValidator {
| Operator::F32Min
| Operator::F32Max
| Operator::F32Copysign => {
self.check_non_deterministic_enabled()?;
self.check_deterministic_only()?;
self.check_operands_2(Type::F32, Type::F32)?;
self.func_state.change_frame_with_type(2, Type::F32)?;
}
Expand All @@ -1356,7 +1356,7 @@ impl OperatorValidator {
| Operator::F64Trunc
| Operator::F64Nearest
| Operator::F64Sqrt => {
self.check_non_deterministic_enabled()?;
self.check_deterministic_only()?;
self.check_operands_1(Type::F64)?;
self.func_state.change_frame_with_type(1, Type::F64)?;
}
Expand All @@ -1367,7 +1367,7 @@ impl OperatorValidator {
| Operator::F64Min
| Operator::F64Max
| Operator::F64Copysign => {
self.check_non_deterministic_enabled()?;
self.check_deterministic_only()?;
self.check_operands_2(Type::F64, Type::F64)?;
self.func_state.change_frame_with_type(2, Type::F64)?;
}
Expand Down Expand Up @@ -1396,32 +1396,32 @@ impl OperatorValidator {
self.func_state.change_frame_with_type(1, Type::I64)?;
}
Operator::F32ConvertI32S | Operator::F32ConvertI32U => {
self.check_non_deterministic_enabled()?;
self.check_deterministic_only()?;
self.check_operands_1(Type::I32)?;
self.func_state.change_frame_with_type(1, Type::F32)?;
}
Operator::F32ConvertI64S | Operator::F32ConvertI64U => {
self.check_non_deterministic_enabled()?;
self.check_deterministic_only()?;
self.check_operands_1(Type::I64)?;
self.func_state.change_frame_with_type(1, Type::F32)?;
}
Operator::F32DemoteF64 => {
self.check_non_deterministic_enabled()?;
self.check_deterministic_only()?;
self.check_operands_1(Type::F64)?;
self.func_state.change_frame_with_type(1, Type::F32)?;
}
Operator::F64ConvertI32S | Operator::F64ConvertI32U => {
self.check_non_deterministic_enabled()?;
self.check_deterministic_only()?;
self.check_operands_1(Type::I32)?;
self.func_state.change_frame_with_type(1, Type::F64)?;
}
Operator::F64ConvertI64S | Operator::F64ConvertI64U => {
self.check_non_deterministic_enabled()?;
self.check_deterministic_only()?;
self.check_operands_1(Type::I64)?;
self.func_state.change_frame_with_type(1, Type::F64)?;
}
Operator::F64PromoteF32 => {
self.check_non_deterministic_enabled()?;
self.check_deterministic_only()?;
self.check_operands_1(Type::F32)?;
self.func_state.change_frame_with_type(1, Type::F64)?;
}
Expand All @@ -1434,12 +1434,12 @@ impl OperatorValidator {
self.func_state.change_frame_with_type(1, Type::I64)?;
}
Operator::F32ReinterpretI32 => {
self.check_non_deterministic_enabled()?;
self.check_deterministic_only()?;
self.check_operands_1(Type::I32)?;
self.func_state.change_frame_with_type(1, Type::F32)?;
}
Operator::F64ReinterpretI64 => {
self.check_non_deterministic_enabled()?;
self.check_deterministic_only()?;
self.check_operands_1(Type::I64)?;
self.func_state.change_frame_with_type(1, Type::F64)?;
}
Expand Down Expand Up @@ -1653,13 +1653,13 @@ impl OperatorValidator {
self.func_state.change_frame_with_type(1, Type::V128)?;
}
Operator::F32x4Splat => {
self.check_non_deterministic_enabled()?;
self.check_deterministic_only()?;
self.check_simd_enabled()?;
self.check_operands_1(Type::F32)?;
self.func_state.change_frame_with_type(1, Type::V128)?;
}
Operator::F64x2Splat => {
self.check_non_deterministic_enabled()?;
self.check_deterministic_only()?;
self.check_simd_enabled()?;
self.check_operands_1(Type::F64)?;
self.func_state.change_frame_with_type(1, Type::V128)?;
Expand Down Expand Up @@ -1713,28 +1713,28 @@ impl OperatorValidator {
self.func_state.change_frame_with_type(2, Type::V128)?;
}
Operator::F32x4ExtractLane { lane } => {
self.check_non_deterministic_enabled()?;
self.check_deterministic_only()?;
self.check_simd_enabled()?;
self.check_simd_lane_index(lane, 4)?;
self.check_operands_1(Type::V128)?;
self.func_state.change_frame_with_type(1, Type::F32)?;
}
Operator::F32x4ReplaceLane { lane } => {
self.check_non_deterministic_enabled()?;
self.check_deterministic_only()?;
self.check_simd_enabled()?;
self.check_simd_lane_index(lane, 4)?;
self.check_operands_2(Type::V128, Type::F32)?;
self.func_state.change_frame_with_type(2, Type::V128)?;
}
Operator::F64x2ExtractLane { lane } => {
self.check_non_deterministic_enabled()?;
self.check_deterministic_only()?;
self.check_simd_enabled()?;
self.check_simd_lane_index(lane, 2)?;
self.check_operands_1(Type::V128)?;
self.func_state.change_frame_with_type(1, Type::F64)?;
}
Operator::F64x2ReplaceLane { lane } => {
self.check_non_deterministic_enabled()?;
self.check_deterministic_only()?;
self.check_simd_enabled()?;
self.check_simd_lane_index(lane, 2)?;
self.check_operands_2(Type::V128, Type::F64)?;
Expand Down Expand Up @@ -1764,7 +1764,7 @@ impl OperatorValidator {
| Operator::F64x2Div
| Operator::F64x2Min
| Operator::F64x2Max => {
self.check_non_deterministic_enabled()?;
self.check_deterministic_only()?;
self.check_simd_enabled()?;
self.check_operands_2(Type::V128, Type::V128)?;
self.func_state.change_frame_with_type(2, Type::V128)?;
Expand Down Expand Up @@ -1855,7 +1855,7 @@ impl OperatorValidator {
| Operator::F32x4ConvertI32x4U
| Operator::F64x2ConvertI64x2S
| Operator::F64x2ConvertI64x2U => {
self.check_non_deterministic_enabled()?;
self.check_deterministic_only()?;
self.check_simd_enabled()?;
self.check_operands_1(Type::V128)?;
self.func_state.change_frame_with_type(1, Type::V128)?;
Expand Down