Switch from pwasm-utils to wasm-instrument (#10680)

* Switch executor to wasm-instrument

* Switch pallet-contracts to wasm-instrument
This commit is contained in:
Alexander Theißen
2022-01-17 17:00:17 +02:00
committed by GitHub
parent d174ff8a61
commit 2a122c44b1
12 changed files with 47 additions and 48 deletions
@@ -28,7 +28,7 @@ macro_rules! convert_args {
macro_rules! gen_signature {
( ( $( $params: ty ),* ) ) => (
{
pwasm_utils::parity_wasm::elements::FunctionType::new(
wasm_instrument::parity_wasm::elements::FunctionType::new(
convert_args!($($params),*), vec![],
)
}
@@ -36,7 +36,7 @@ macro_rules! gen_signature {
( ( $( $params: ty ),* ) -> $returns: ty ) => (
{
pwasm_utils::parity_wasm::elements::FunctionType::new(
wasm_instrument::parity_wasm::elements::FunctionType::new(
convert_args!($($params),*),
vec![{use $crate::wasm::env_def::ConvertibleToWasm; <$returns>::VALUE_TYPE}],
)
@@ -220,7 +220,7 @@ macro_rules! define_env {
fn can_satisfy(
module: &[u8],
name: &[u8],
func_type: &pwasm_utils::parity_wasm::elements::FunctionType,
func_type: &wasm_instrument::parity_wasm::elements::FunctionType,
) -> bool
{
#[cfg(not(feature = "unstable-interface"))]
@@ -260,9 +260,9 @@ mod tests {
wasm::{runtime::TrapReason, tests::MockExt, Runtime},
Weight,
};
use pwasm_utils::parity_wasm::elements::{FunctionType, ValueType};
use sp_runtime::traits::Zero;
use sp_sandbox::{ReturnValue, Value};
use wasm_instrument::parity_wasm::elements::{FunctionType, ValueType};
struct TestRuntime {
value: u32,
@@ -18,8 +18,8 @@
use super::Runtime;
use crate::exec::Ext;
use pwasm_utils::parity_wasm::elements::{FunctionType, ValueType};
use sp_sandbox::Value;
use wasm_instrument::parity_wasm::elements::{FunctionType, ValueType};
#[macro_use]
pub mod macros;
@@ -26,9 +26,11 @@ use crate::{
AccountIdOf, Config, Schedule,
};
use codec::{Encode, MaxEncodedLen};
use pwasm_utils::parity_wasm::elements::{self, External, Internal, MemoryType, Type, ValueType};
use sp_runtime::traits::Hash;
use sp_std::prelude::*;
use wasm_instrument::parity_wasm::elements::{
self, External, Internal, MemoryType, Type, ValueType,
};
/// Imported memory must be located inside this module. The reason for hardcoding is that current
/// compiler toolchains might not support specifying other modules than "env" for memory imports.
@@ -182,17 +184,16 @@ impl<'a, T: Config> ContractModule<'a, T> {
fn inject_gas_metering(self) -> Result<Self, &'static str> {
let gas_rules = self.schedule.rules(&self.module);
let contract_module = pwasm_utils::inject_gas_counter(self.module, &gas_rules, "seal0")
.map_err(|_| "gas instrumentation failed")?;
let contract_module =
wasm_instrument::gas_metering::inject(self.module, &gas_rules, "seal0")
.map_err(|_| "gas instrumentation failed")?;
Ok(ContractModule { module: contract_module, schedule: self.schedule })
}
fn inject_stack_height_metering(self) -> Result<Self, &'static str> {
let contract_module = pwasm_utils::stack_height::inject_limiter(
self.module,
self.schedule.limits.stack_height,
)
.map_err(|_| "stack height instrumentation failed")?;
let contract_module =
wasm_instrument::inject_stack_limiter(self.module, self.schedule.limits.stack_height)
.map_err(|_| "stack height instrumentation failed")?;
Ok(ContractModule { module: contract_module, schedule: self.schedule })
}
@@ -29,12 +29,12 @@ use bitflags::bitflags;
use codec::{Decode, DecodeAll, Encode, MaxEncodedLen};
use frame_support::{dispatch::DispatchError, ensure, weights::Weight};
use pallet_contracts_primitives::{ExecReturnValue, ReturnFlags};
use pwasm_utils::parity_wasm::elements::ValueType;
use sp_core::{crypto::UncheckedFrom, Bytes};
use sp_io::hashing::{blake2_128, blake2_256, keccak_256, sha2_256};
use sp_runtime::traits::{Bounded, Zero};
use sp_sandbox::SandboxMemory;
use sp_std::prelude::*;
use wasm_instrument::parity_wasm::elements::ValueType;
/// Every error that can be returned to a contract when it calls any of the host functions.
///