// Copyright 2017 Parity Technologies (UK) Ltd.
// This file is part of Polkadot.
// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see .
//! WASM re-execution of a parachain candidate.
//! In the context of relay-chain candidate evaluation, there are some additional
//! steps to ensure that the provided input parameters are correct.
//! Assuming the parameters are correct, this module provides a wrapper around
//! a WASM VM for re-execution of a parachain candidate.
use codec::Slicable;
use wasmi::{self, Module, ModuleInstance, MemoryInstance, MemoryDescriptor, MemoryRef, ModuleImportResolver};
use wasmi::{memory_units, RuntimeValue};
use wasmi::Error as WasmError;
use super::{ValidationParams, ValidationResult};
use std::cell::RefCell;
error_chain! {
types { Error, ErrorKind, ResultExt; }
foreign_links {
Wasm(WasmError);
}
errors {
/// Call data too big. WASM32 only has a 32-bit address space.
ParamsTooLarge(len: usize) {
description("Validation parameters took up too much space to execute in WASM"),
display("Validation parameters took up {} bytes, max allowed by WASM is {}", len, i32::max_value()),
}
/// Bad return data or type.
BadReturn {
description("Validation function returned invalid data."),
display("Validation function returned invalid data."),
}
}
}
struct Resolver {
max_memory: u32, // in pages.
memory: RefCell