Trait wasm_instrument::gas_metering::Rules
source · [−]pub trait Rules {
fn instruction_cost(&self, instruction: &Instruction) -> Option<u32>;
fn memory_grow_cost(&self) -> MemoryGrowCost;
}
Expand description
An interface that describes instruction costs.
Required Methods
sourcefn instruction_cost(&self, instruction: &Instruction) -> Option<u32>
fn instruction_cost(&self, instruction: &Instruction) -> Option<u32>
Returns the cost for the passed instruction
.
Returning None
makes the gas instrumention end with an error. This is meant
as a way to have a partial rule set where any instruction that is not specifed
is considered as forbidden.
sourcefn memory_grow_cost(&self) -> MemoryGrowCost
fn memory_grow_cost(&self) -> MemoryGrowCost
Returns the costs for growing the memory using the memory.grow
instruction.
Please note that these costs are in addition to the costs specified by instruction_cost
for the memory.grow
instruction. Those are meant as dynamic costs which take the
amount of pages that the memory is grown by into consideration. This is not possible
using instruction_cost
because those costs depend on the stack and must be injected as
code into the function calling memory.grow
. Therefore returning anything but
MemoryGrowCost::Free
introduces some overhead to the memory.grow
instruction.