Struct finite_wasm::AnalysisOutcome
source · pub struct AnalysisOutcome {
pub function_frame_sizes: Vec<u64>,
pub function_operand_stack_sizes: Vec<u64>,
pub gas_offsets: Vec<Box<[usize]>>,
pub gas_costs: Vec<Box<[u64]>>,
pub gas_kinds: Vec<Box<[InstrumentationKind]>>,
}
Expand description
The results of parsing and analyzing the module.
This analysis collects information necessary to implement all of the transformations in one go, so that re-parsing the module multiple times is not necessary.
Fields§
§function_frame_sizes: Vec<u64>
The sizes of the stack frame for each function in the module, excluding imports.
This includes the things like the function label and the locals that are 0-initialized.
function_operand_stack_sizes: Vec<u64>
The maximum size of the operand stack for each function in the module, excluding imports.
Throughout the execution the sum of sizes of the operands on the function’s operand stack will differ, but will never exceed the number here.
gas_offsets: Vec<Box<[usize]>>
The table of offsets for gas instrumentation points.
This vector is indexed by entries in the code section (that is, it is indexed by the function index, excluding imports).
gas_costs: Vec<Box<[u64]>>
The table of gas costs for gas instrumentation points.
This vector is indexed by entries in the code section (that is, it is indexed by the function index, excluding imports).
gas_kinds: Vec<Box<[InstrumentationKind]>>
The table of instrumentation kinds for gas instrumentation points.
This vector is indexed by entries in the code section (that is, it is indexed by the function index, excluding imports).
Implementations§
source§impl AnalysisOutcome
impl AnalysisOutcome
sourcepub fn instrument(
&self,
import_env: &str,
wasm: &[u8]
) -> Result<Vec<u8>, InstrumentError>
Available on crate feature instrument
only.
pub fn instrument( &self, import_env: &str, wasm: &[u8] ) -> Result<Vec<u8>, InstrumentError>
instrument
only.Modify the provided wasm
module to enforce gas and stack limits.
The instrumentation approach provided by this crate has been largely tailored for this crate’s own testing needs and may not be applicable to every use-case. However the code is reasonably high quality that it might be useful for development purposes.
This function will modify the provided core wasm module to introduce three imports:
{env}.finite_wasm_gas
:(func (params u64))
{env}.finite_wasm_stack
:(func (params u64 u64))
{env}.finite_wasm_unstack
:(func (params u64 u64))
These functions must be provided by the embedder. The finite_wasm_gas
should reduce the
pool of remaining gas by the only argument supplied and trap the execution when the gas is
exhausted. When the gas is exhausted the reamining gas pool must be set to 0, as per the
specification.
The finite_wasm_stack
and finite_wasm_unstack
are called with two arguments. The first
argument is the size by which the operands stack increases, or decreases if the argument is
negative. Second is the size of the stack reserved or released by the function frame. These
host functions must keep track of the current total stack height and raise a trap if the
stack limit is exceeded.