[contracts] Remove stack height limiter wasm instrumentation (#12957)

* Remove stack height limiter from uploaded wasm

* fix benchmarks

* ".git/.scripts/bench-bot.sh" pallet dev pallet_contracts

Co-authored-by: command-bot <>
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
This commit is contained in:
Sasha Gryaznov
2022-12-22 19:22:57 +02:00
committed by GitHub
parent 4083b5358a
commit 29f8f037b7
5 changed files with 12 additions and 69 deletions
@@ -72,11 +72,6 @@ pub struct ModuleDefinition {
pub aux_body: Option<FuncBody>,
/// The amount of I64 arguments the aux function should have.
pub aux_arg_num: u32,
/// If set to true the stack height limiter is injected into the the module. This is
/// needed for instruction debugging because the cost of executing the stack height
/// instrumentation should be included in the costs for the individual instructions
/// that cause more metering code (only call).
pub inject_stack_metering: bool,
/// Create a table containing function pointers.
pub table: Option<TableSegment>,
/// Create a section named "dummy" of the specified size. This is useful in order to
@@ -238,13 +233,7 @@ impl<T: Config> From<ModuleDefinition> for WasmModule<T> {
)));
}
let mut code = contract.build();
if def.inject_stack_metering {
code = inject_stack_metering::<T>(code);
}
let code = code.into_bytes().unwrap();
let code = contract.build().into_bytes().unwrap();
let hash = T::Hashing::hash(&code);
Self { code: code.into(), hash, memory: def.memory }
}
@@ -252,15 +241,12 @@ impl<T: Config> From<ModuleDefinition> for WasmModule<T> {
impl<T: Config> WasmModule<T> {
/// Uses the supplied wasm module and instruments it when requested.
pub fn instrumented(code: &[u8], inject_gas: bool, inject_stack: bool) -> Self {
pub fn instrumented(code: &[u8], inject_gas: bool) -> Self {
let module = {
let mut module = Module::from_bytes(code).unwrap();
if inject_gas {
module = inject_gas_metering::<T>(module);
}
if inject_stack {
module = inject_stack_metering::<T>(module);
}
module
};
let limits = *module
@@ -530,11 +516,3 @@ fn inject_gas_metering<T: Config>(module: Module) -> Module {
let backend = gas_metering::host_function::Injector::new("seal0", "gas");
gas_metering::inject(module, backend, &gas_rules).unwrap()
}
fn inject_stack_metering<T: Config>(module: Module) -> Module {
if let Some(height) = T::Schedule::get().limits.stack_height {
wasm_instrument::inject_stack_limiter(module, height).unwrap()
} else {
module
}
}
@@ -2384,7 +2384,6 @@ benchmarks! {
call_body: Some(body::repeated(r * INSTR_BENCHMARK_BATCH_SIZE, &[
Instruction::Call(2), // call aux
])),
inject_stack_metering: true,
.. Default::default()
}));
}: {
@@ -2408,7 +2407,6 @@ benchmarks! {
RandomI32(0, num_elements as i32),
Regular(Instruction::CallIndirect(0, 0)), // we only have one sig: 0
])),
inject_stack_metering: true,
table: Some(TableSegment {
num_elements,
function_index: 2, // aux
@@ -2441,7 +2439,6 @@ benchmarks! {
RandomI32(0, num_elements as i32),
Regular(Instruction::CallIndirect(p.min(1), 0)), // aux signature: 1 or 0
])),
inject_stack_metering: true,
table: Some(TableSegment {
num_elements,
function_index: 2, // aux
@@ -2968,7 +2965,7 @@ benchmarks! {
new.encode()
};
let instance = Contract::<T>::new(
WasmModule::instrumented(code, gas_metering, true), data,
WasmModule::instrumented(code, gas_metering), data,
)?;
let data = {
let transfer: ([u8; 4], AccountIdOf<T>, BalanceOf<T>) = (
@@ -3015,7 +3012,7 @@ benchmarks! {
new.encode()
};
let instance = Contract::<T>::with_caller(
caller, WasmModule::instrumented(code, gas_metering, true), data,
caller, WasmModule::instrumented(code, gas_metering), data,
)?;
balance[0] = 1;
let data = {