Skip to main content

EvmBackend

Struct EvmBackend 

Source
pub struct EvmBackend { /* private fields */ }
Expand description

EVM bytecode code generation backend.

Converts an EvmContract into:

  • Raw binary bytecode (Vec<u8>)
  • Hex string representation
  • Human-readable assembly text

Implementations§

Source§

impl EvmBackend

Source

pub fn new() -> Self

Create a new EVM backend instance.

Source

pub fn compute_selector(signature: &str) -> [u8; 4]

Compute a 4-byte function selector from an ABI signature string.

This is a placeholder using a fast mixing hash (not real keccak256). In production this should use a proper keccak256 crate.

Source

pub fn emit_dispatcher(&self, contract: &EvmContract) -> Vec<EvmInstruction>

Emit the standard ABI dispatcher preamble.

This code:

  1. Loads the first 4 bytes of calldata (the function selector).
  2. Compares against each known selector.
  3. Jumps to the appropriate handler block.
  4. Falls through to REVERT if no selector matches.
Source

pub fn emit_sload(&self, slot: u64) -> Vec<EvmInstruction>

Emit instructions to load a storage variable onto the stack.

Source

pub fn emit_sstore(&self, slot: u64) -> Vec<EvmInstruction>

Emit instructions to store the top-of-stack value into a storage slot.

Assumes the value to store is already on the stack.

Source

pub fn emit_constructor_bytes(&self, contract: &EvmContract) -> Vec<u8>

Encode the constructor code portion of a contract to raw bytes.

Source

pub fn emit_runtime_bytes(&self, contract: &EvmContract) -> Vec<u8>

Encode the full runtime bytecode of a contract to raw bytes.

Layout: dispatcher preamble + function bodies (each starting with JUMPDEST).

Source

pub fn emit_init_code(&self, contract: &EvmContract) -> Vec<u8>

Encode the complete init code (constructor + runtime deployment stub).

The init code:

  1. Runs constructor logic.
  2. Returns a copy of the runtime bytecode so the EVM stores it.
Source

pub fn emit_hex(&self, contract: &EvmContract) -> String

Encode the runtime bytecode as a hex string (no 0x prefix).

Source

pub fn emit_hex_prefixed(&self, contract: &EvmContract) -> String

Encode the runtime bytecode as a hex string with 0x prefix.

Source

pub fn emit_init_hex(&self, contract: &EvmContract) -> String

Encode the full init code as a hex string with 0x prefix.

Source

pub fn emit_assembly(&self, contract: &EvmContract) -> String

Emit human-readable assembly text for an EvmContract.

Source

pub fn build_arithmetic_function( name: &str, signature: &str, selector: [u8; 4], op: EvmOpcode, ) -> EvmFunction

Build a simple two-argument arithmetic function (e.g. add(uint256,uint256)).

Loads arg0 from calldata[4], arg1 from calldata[36], applies op, stores result in memory[0..32], and returns 32 bytes.

Trait Implementations§

Source§

impl Debug for EvmBackend

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for EvmBackend

Source§

fn default() -> EvmBackend

Returns the “default value” for a type. 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
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.