referrerpolicy=no-referrer-when-downgrade

VmBinaryModule

Struct VmBinaryModule 

Source
pub struct VmBinaryModule {
    pub code: Vec<u8>,
    pub hash: H256,
}
Expand description

A vm binary module ready to be put on chain.

Fields§

§code: Vec<u8>§hash: H256

Implementations§

Source§

impl VmBinaryModule

Source

pub fn dummy() -> Self

Return a contract code that does nothing.

Source§

impl VmBinaryModule

Source

pub fn evm_init_code_for_runtime_size(size: u32) -> Self

Source

pub fn evm_noop(size: u32) -> Self

An evm contract that executes size JUMPDEST instructions.

Source§

impl VmBinaryModule

Source

pub const BRANCH_BLOCKS: u32 = 16_000

The number of branches in Self::with_branch_blocks.

All blocks the contract enters must fit into the interpreter cache at the same time, or the interpreter would reset the cache and compile blocks again. The cache holds INTERPRETER_CACHE_BYTES / 24 entries and keeps room for one block of BASIC_BLOCK_SIZE instructions. A block of one instruction takes two entries: its gas charge and the instruction. 16000 such blocks and the final block of two instructions take 32003 entries, below the 42689 usable.

The cache entries are kept in vectors that double their capacity as they grow, up to the cache limit. 32003 entries stay below a capacity of 32768. Above it the vectors would be reallocated once more, which adds a copy of the whole cache to the largest values of b and skews the linear fit.

Source

pub const LOAD_CHAIN_SLOTS: u32 = 1024

The number of slots in the chain of addresses of Self::with_load_chain.

With slots Self::LOAD_CHAIN_SLOT_BYTES apart, the chain stays in the L2 but not in the L1 data cache of the reference hardware: Intel Ice Lake (48 KiB L1D of 12 ways, 1.25 MiB L2 of 20 ways) and AMD Zen 3 (32 KiB L1D of 8 ways, 512 KiB L2 of 8 ways), all with 64 byte lines, 64 L1D sets and 1024 L2 sets. A load touches one line, or two in the benchmark variant where every load spans two lines. With slots two lines apart, the 1024 lines (64 KiB) of the other variants map to every other set and the 2048 lines (128 KiB) of the spanning variant to every set. Either way each L1D set in use receives 32 lines against at most 12 ways, and each L2 set 2 lines, a quarter of the Zen 3 ways. The L2 is physically indexed, so 2 lines per set is an average that depends on where the 32 4 KiB pages of the chain land. Every load also takes a DTLB lookup; the 32 pages fit the 64 entry L1 DTLB of both.

Source

pub const LOAD_CHAIN_SLOT_BYTES: u32 = 128

The distance between two slots of Self::with_load_chain in bytes.

Two 64 byte cache lines; see Self::LOAD_CHAIN_SLOTS.

Source

pub const MAX_CODE_BYTES: u32

The largest code section Self::with_code_bytes builds.

The interpreter keeps a map with one entry per byte of the code section. It counts towards [limits::code::PURGABLE_MEMORY_LIMIT] next to the interpreter cache, which a contract of this size fills. That allows at most 512 KiB of code. One page is left as a margin for the code that Self::with_code_bytes adds.

Source

pub fn dummy_unique(replace_with: u32) -> Self

Same as Self::dummy but uses replace_with to make the code unique.

Source

pub fn sized(size: u32) -> Self

Same as as with_num_instructions but based on the blob size.

This is needed when we weigh a blob without knowing how much instructions it contains.

Source

pub fn with_num_instructions(num_instructions: u32) -> Self

A contract code of specified number of instructions that uses all its bytes for instructions but will return immediately.

All the basic blocks are maximum sized (only the first is important though). This is to account for the fact that the interpreter will compile one basic block at a time even when no code is executed. Hence this contract will trigger the compilation of a maximum sized basic block and then return with its first instruction.

All the code will be put into the “call” export. Hence this code can be safely used for the instantiate_with_code benchmark where no compilation of any block should be measured.

Source

pub fn with_branch_blocks(b: u32) -> Self

A contract whose call export enters b basic blocks of one instruction and returns.

The code holds Self::BRANCH_BLOCKS branches, one ecalli SENTINEL and one ret. Each branch ends a basic block, so each forms a block of its own, and it is always taken to the next block. The ecalli SENTINEL comes after b of them: the call compiles and runs b blocks of one branch each, then compiles the block of the ecalli SENTINEL and the instruction after it, and stops at the ecalli SENTINEL. The code holds the same instructions for every b, so its size does not depend on b.

The branch is a branch_eq of two registers. Of the instructions that end a basic block and continue at another one, a register branch is the slowest to compile and run per block, so the slope is an upper bound for the other terminators.

b is within 0..=BRANCH_BLOCKS.

Source

pub fn with_entry_block(n: u32) -> Self

A contract whose call export compiles an entry block of n instructions and returns.

The entry block starts with an ecalli SENTINEL, which ends the execution but not the basic block, so the interpreter compiles the whole block before running it. n - 2 fillers and a fallthrough follow. The remaining BASIC_BLOCK_SIZE - n fillers and a ret form a second block, which is never entered. The code holds the same instructions for every n, so its size does not depend on n.

The filler is a store_imm_indirect_u64 with two 4 byte immediates. It never executes. Of the instructions that do not end a basic block, the store_imm_indirect kinds are the slowest to compile per instruction, with short immediates as well, so the slope is an upper bound for the others.

n is within 2..=BASIC_BLOCK_SIZE.

Source

pub fn with_load_chain() -> Self

A contract whose call export runs a1 iterations of LOAD_CHAIN_GAS - 3 dependent loads.

An iteration is the branch jump @done if t0 == a1, then one basic block of loads a0 = u64 [a0], t0 = t0 + 1 and jump @loop. Each load reads the address of the next one, so it cannot start before the previous load has finished. The contract declares Self::LOAD_CHAIN_SLOTS slots of Self::LOAD_CHAIN_SLOT_BYTES as read-write data. The caller writes the chain of addresses into it and sets a0 to the first address.

Source

pub fn with_indirect_jump_cycle() -> Self

A contract whose call export runs a1 laps of a random cycle of indirect jumps.

The cycle has INDIRECT_JUMP_GAS - 3 basic blocks of one instruction each. Every block is a load_imm_and_jump_indirect that jumps to the address in a0 and loads the address of the block after the next one into a0. A lap starts and ends at a block with the branch jump @done if t0 == a1, followed by t0 = t0 + 1 and the jump into the cycle. The order of the blocks in the cycle is a fixed random permutation, so consecutive jumps go to unrelated code addresses.

Before the first lap, a warm-up loop enters every cycle block once in code order, with a0 holding the loop’s own address so that the block jumps back to it. The interpreter compiles a block when execution first enters it and appends its handlers to its cache, so the cache holds the cycle blocks in code order. A lap visits them in the random order of the cycle, so its reads of handlers and arguments are as scattered as its reads of the jump table and the code map. The warm-up runs once per call whatever a1 is.

The number of blocks keeps the interpreter data a lap reads in the L2 but not in the L1 data cache of the reference hardware (see Self::LOAD_CHAIN_SLOTS). A jump into a block reads the block’s 2 byte jump table entry, its 4 byte entry in the code map, and the 8 byte handler and 16 byte arguments of its two compiled instructions: the gas charge and the jump. The code map has one entry per code byte and a block is 5 bytes of code, so the entries of consecutive blocks are 20 bytes apart and a lap reads every cache line of the map: 20 bytes per block. Every block thus adds 2 + 20 + 2 * 24 = 70 bytes to the data of a lap. The code itself is read only when a block is compiled. The INDIRECT_JUMP_GAS - 3 = 3000 blocks take 205 KiB, 4.3 times the Ice Lake L1D: each of the 64 L1D sets receives about 51 lines against at most 12 ways. Each of the 1024 L2 sets receives 3.2 lines, 40% of the Zen 3 ways. The L2 is physically indexed, so 3.2 lines per set is an average that depends on where the pages land. The data spans four arrays of 4 KiB pages, jump table 2 to 3, code map 15 to 16, handlers 12 to 13 and arguments 24 to 25, so 53 to 57 pages plus the interpreter’s own state. They fit the fully associative 64 entry L1 DTLB of Zen 3. The 64 entry L1 DTLB of Ice Lake is 4-way set associative, so some of them may miss it and hit the second level TLB.

Source

pub fn with_code_bytes(code_bytes: u32) -> Self

A contract with a code section of about code_bytes bytes whose call export returns at once.

The call export is a basic block of ecalli SENTINEL and fallthrough, which stops the call. Blocks of a0 = a1 + a2, 3 bytes each, fill the rest of the code section and never run. Only the size of the code section depends on code_bytes.

Source

pub fn noop() -> Self

A contract code that calls the “noop” host function in a loop depending in the input.

Trait Implementations§

Source§

impl Clone for VmBinaryModule

Source§

fn clone(&self) -> VmBinaryModule

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
§

impl<T> CheckedConversion for T

§

fn checked_from<T>(t: T) -> Option<Self>
where Self: TryFrom<T>,

Convert from a value of T into an equivalent instance of Option<Self>. Read more
§

fn checked_into<T>(self) -> Option<T>
where Self: TryInto<T>,

Consume self to return Some equivalent value of Option<T>. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> Conv for T

§

fn conv<T>(self) -> T
where Self: Into<T>,

Converts self into T using Into<T>. Read more
§

impl<T, U> DefensiveTruncateInto<U> for T
where U: DefensiveTruncateFrom<T>,

§

fn defensive_truncate_into(self) -> U

Defensively truncate a value and convert it into its bounded form.
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

§

impl<T> FmtForward for T

§

fn fmt_binary(self) -> FmtBinary<Self>
where Self: Binary,

Causes self to use its Binary implementation when Debug-formatted.
§

fn fmt_display(self) -> FmtDisplay<Self>
where Self: Display,

Causes self to use its Display implementation when Debug-formatted.
§

fn fmt_lower_exp(self) -> FmtLowerExp<Self>
where Self: LowerExp,

Causes self to use its LowerExp implementation when Debug-formatted.
§

fn fmt_lower_hex(self) -> FmtLowerHex<Self>
where Self: LowerHex,

Causes self to use its LowerHex implementation when Debug-formatted.
§

fn fmt_octal(self) -> FmtOctal<Self>
where Self: Octal,

Causes self to use its Octal implementation when Debug-formatted.
§

fn fmt_pointer(self) -> FmtPointer<Self>
where Self: Pointer,

Causes self to use its Pointer implementation when Debug-formatted.
§

fn fmt_upper_exp(self) -> FmtUpperExp<Self>
where Self: UpperExp,

Causes self to use its UpperExp implementation when Debug-formatted.
§

fn fmt_upper_hex(self) -> FmtUpperHex<Self>
where Self: UpperHex,

Causes self to use its UpperHex implementation when Debug-formatted.
§

fn fmt_list(self) -> FmtList<Self>
where &'a Self: for<'a> IntoIterator,

Formats each item in a sequence. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

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

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T, U> IntoKey<U> for T
where U: FromKey<T>,

§

fn into_key(self) -> U

§

impl<Src, Dest> IntoTuple<Dest> for Src
where Dest: FromTuple<Src>,

§

fn into_tuple(self) -> Dest

§

impl<T> IsType<T> for T

§

fn from_ref(t: &T) -> &T

Cast reference.
§

fn into_ref(&self) -> &T

Cast reference.
§

fn from_mut(t: &mut T) -> &mut T

Cast mutable reference.
§

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

Cast mutable reference.
§

impl<T, Outer> IsWrappedBy<Outer> for T
where Outer: AsRef<T> + AsMut<T> + From<T>, T: From<Outer>,

§

fn from_ref(outer: &Outer) -> &T

Get a reference to the inner from the outer.

§

fn from_mut(outer: &mut Outer) -> &mut T

Get a mutable reference to the inner from the outer.

§

impl<T> Pipe for T
where T: ?Sized,

§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
where Self: Sized,

Pipes by value. This is generally the method you want to use. Read more
§

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R
where R: 'a,

Borrows self and passes that borrow into the pipe function. Read more
§

fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R
where R: 'a,

Mutably borrows self and passes that borrow into the pipe function. Read more
§

fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
where Self: Borrow<B>, B: 'a + ?Sized, R: 'a,

Borrows self, then passes self.borrow() into the pipe function. Read more
§

fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
where Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
§

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
where Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

Borrows self, then passes self.as_ref() into the pipe function.
§

fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
where Self: AsMut<U>, U: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.as_mut() into the pipe function.
§

fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
where Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
§

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R, ) -> R
where Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T> SaturatedConversion for T

§

fn saturated_from<T>(t: T) -> Self
where Self: UniqueSaturatedFrom<T>,

Convert from a value of T into an equivalent instance of Self. Read more
§

fn saturated_into<T>(self) -> T
where Self: UniqueSaturatedInto<T>,

Consume self to return an equivalent value of T. Read more
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
§

impl<T> Tap for T

§

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more
§

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more
§

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Immutable access to the Borrow<B> of a value. Read more
§

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Mutable access to the BorrowMut<B> of a value. Read more
§

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Immutable access to the AsRef<R> view of a value. Read more
§

fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Mutable access to the AsMut<R> view of a value. Read more
§

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Immutable access to the Deref::Target of a value. Read more
§

fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Mutable access to the Deref::Target of a value. Read more
§

fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self

Calls .tap() only in debug builds, and is erased in release builds.
§

fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self

Calls .tap_mut() only in debug builds, and is erased in release builds.
§

fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Calls .tap_borrow() only in debug builds, and is erased in release builds.
§

fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds.
§

fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Calls .tap_ref() only in debug builds, and is erased in release builds.
§

fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Calls .tap_ref_mut() only in debug builds, and is erased in release builds.
§

fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Calls .tap_deref() only in debug builds, and is erased in release builds.
§

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T> TryConv for T

§

fn try_conv<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Attempts to convert self into T using TryInto<T>. Read more
Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
§

impl<T, U> TryIntoKey<U> for T
where U: TryFromKey<T>,

§

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

§

fn try_into_key(self) -> Result<U, <U as TryFromKey<T>>::Error>

§

impl<S, T> UncheckedInto<T> for S
where T: UncheckedFrom<S>,

§

fn unchecked_into(self) -> T

The counterpart to unchecked_from.
§

impl<T, S> UniqueSaturatedInto<T> for S
where T: Bounded, S: TryInto<T>,

§

fn unique_saturated_into(self) -> T

Consume self to return an equivalent value of T.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> JsonSchemaMaybe for T

§

impl<T> MaybeRefUnwindSafe for T
where T: RefUnwindSafe,

§

impl<T> MaybeSend for T
where T: Send,

§

impl<T> MaybeSendSync for T