mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 14:01:06 +00:00
[contracts] Add per local weight for function call (#12806)
* Add per local weight for function call * ".git/.scripts/bench-bot.sh" pallet dev pallet_contracts * Update frame/contracts/src/benchmarking/mod.rs Co-authored-by: Alexander Theißen <alex.theissen@me.com> * apply suggestions from code review * ".git/.scripts/bench-bot.sh" pallet dev pallet_contracts * Update frame/contracts/src/benchmarking/mod.rs Co-authored-by: Alexander Theißen <alex.theissen@me.com> * tune the benchmark * ".git/.scripts/bench-bot.sh" pallet dev pallet_contracts * fix benches * ".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:
@@ -118,6 +118,12 @@ pub struct Limits {
|
||||
/// the linear memory limit `memory_pages` applies to them.
|
||||
pub globals: u32,
|
||||
|
||||
/// Maximum number of locals a function can have.
|
||||
///
|
||||
/// As wasm engine initializes each of the local, we need to limit their number to confine
|
||||
/// execution costs.
|
||||
pub locals: u32,
|
||||
|
||||
/// Maximum numbers of parameters a function can have.
|
||||
///
|
||||
/// Those need to be limited to prevent a potentially exploitable interaction with
|
||||
@@ -212,6 +218,7 @@ pub struct InstructionWeights<T: Config> {
|
||||
pub call: u32,
|
||||
pub call_indirect: u32,
|
||||
pub call_indirect_per_param: u32,
|
||||
pub call_per_local: u32,
|
||||
pub local_get: u32,
|
||||
pub local_set: u32,
|
||||
pub local_tee: u32,
|
||||
@@ -522,6 +529,7 @@ impl Default for Limits {
|
||||
// No stack limit required because we use a runtime resident execution engine.
|
||||
stack_height: None,
|
||||
globals: 256,
|
||||
locals: 1024,
|
||||
parameters: 128,
|
||||
memory_pages: 16,
|
||||
// 4k function pointers (This is in count not bytes).
|
||||
@@ -552,6 +560,7 @@ impl<T: Config> Default for InstructionWeights<T> {
|
||||
call: cost_instr!(instr_call, 2),
|
||||
call_indirect: cost_instr!(instr_call_indirect, 3),
|
||||
call_indirect_per_param: cost_instr!(instr_call_indirect_per_param, 1),
|
||||
call_per_local: cost_instr!(instr_call_per_local, 1),
|
||||
local_get: cost_instr!(instr_local_get, 1),
|
||||
local_set: cost_instr!(instr_local_set, 1),
|
||||
local_tee: cost_instr!(instr_local_tee, 2),
|
||||
@@ -792,6 +801,10 @@ impl<'a, T: Config> gas_metering::Rules for ScheduleRules<'a, T> {
|
||||
// The cost for growing is therefore already included in the instruction cost.
|
||||
gas_metering::MemoryGrowCost::Free
|
||||
}
|
||||
|
||||
fn call_per_local_cost(&self) -> u32 {
|
||||
self.schedule.instruction_weights.call_per_local
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user