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

source

pub fn instrument( &self, import_env: &str, wasm: &[u8] ) -> Result<Vec<u8>, InstrumentError>

Available on crate feature 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.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.