Skip to content

Commit

Permalink
WASM executor: add OutputExceedsBounds variant to Error (parityte…
Browse files Browse the repository at this point in the history
…ch#13841)

* WASM executor: add `OutputExceedsBounds` variant to `Error`

Previously this was a `WasmError`, which is intended for runtime construction errors. However this
led to confusion as output-exceeds-bounds occurs due to execution of `validate_block`.

* Fix warning
  • Loading branch information
mrcnski authored and nathanwhit committed Jul 19, 2023
1 parent b702a30 commit 4bf4307
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
5 changes: 4 additions & 1 deletion client/executor/common/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ pub enum Error {

#[error("Execution aborted due to trap: {0}")]
AbortedDueToTrap(MessageWithBacktrace),

#[error("Output exceeds bounds of wasm memory")]
OutputExceedsBounds,
}

impl wasmi::HostError for Error {}
Expand Down Expand Up @@ -153,7 +156,7 @@ pub enum WasmError {
Instantiation(String),

/// Other error happenend.
#[error("{0}")]
#[error("Other error happened while constructing the runtime: {0}")]
Other(String),
}

Expand Down
11 changes: 4 additions & 7 deletions client/executor/src/integration_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ mod linux;
use assert_matches::assert_matches;
use codec::{Decode, Encode};
use sc_executor_common::{
error::{Error, WasmError},
error::Error,
runtime_blob::RuntimeBlob,
wasm_runtime::{HeapAllocStrategy, WasmModule},
};
Expand Down Expand Up @@ -819,9 +819,8 @@ fn return_huge_len(wasm_method: WasmExecutionMethod) {
Error::Runtime => {
assert_matches!(wasm_method, WasmExecutionMethod::Interpreted);
},
Error::RuntimeConstruction(WasmError::Other(error)) => {
Error::OutputExceedsBounds => {
assert_matches!(wasm_method, WasmExecutionMethod::Compiled { .. });
assert_eq!(error, "output exceeds bounds of wasm memory");
},
error => panic!("unexpected error: {:?}", error),
}
Expand Down Expand Up @@ -849,9 +848,8 @@ fn return_max_memory_offset_plus_one(wasm_method: WasmExecutionMethod) {
Error::Runtime => {
assert_matches!(wasm_method, WasmExecutionMethod::Interpreted);
},
Error::RuntimeConstruction(WasmError::Other(error)) => {
Error::OutputExceedsBounds => {
assert_matches!(wasm_method, WasmExecutionMethod::Compiled { .. });
assert_eq!(error, "output exceeds bounds of wasm memory");
},
error => panic!("unexpected error: {:?}", error),
}
Expand All @@ -866,9 +864,8 @@ fn return_overflow(wasm_method: WasmExecutionMethod) {
Error::Runtime => {
assert_matches!(wasm_method, WasmExecutionMethod::Interpreted);
},
Error::RuntimeConstruction(WasmError::Other(error)) => {
Error::OutputExceedsBounds => {
assert_matches!(wasm_method, WasmExecutionMethod::Compiled { .. });
assert_eq!(error, "output exceeds bounds of wasm memory");
},
error => panic!("unexpected error: {:?}", error),
}
Expand Down
4 changes: 2 additions & 2 deletions client/executor/wasmtime/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::{

use sc_allocator::{AllocationStats, FreeingBumpHeapAllocator};
use sc_executor_common::{
error::{Result, WasmError},
error::{Error, Result, WasmError},
runtime_blob::{
self, DataSegmentsSnapshot, ExposedMutableGlobalsSet, GlobalsSnapshot, RuntimeBlob,
},
Expand Down Expand Up @@ -776,7 +776,7 @@ fn extract_output_data(
// Get the size of the WASM memory in bytes.
let memory_size = ctx.as_context().data().memory().data_size(ctx);
if checked_range(output_ptr as usize, output_len as usize, memory_size).is_none() {
Err(WasmError::Other("output exceeds bounds of wasm memory".into()))?
Err(Error::OutputExceedsBounds)?
}
let mut output = vec![0; output_len as usize];

Expand Down

0 comments on commit 4bf4307

Please sign in to comment.