zingen

Struct Assembler

Source
pub struct Assembler {
    buffer: Buffer,
    gas: u128,
    pub mp: usize,
    pub sp: u8,
}
Expand description

Low level assembler implementation for EVM.

Fields§

§buffer: Buffer

Buffer of the assembler.

§gas: u128

Gas counter.

This is used to calculate the gas cost of the generated code.

TODO: use a more precise type, eq u256. (issue-20)

§mp: usize

Memory pointer for byte offset.

§sp: u8

Stack pointer, maximum 1024 items.

Implementations§

Source§

impl Assembler

Source

pub fn buffer(&self) -> &[u8]

Buffer of the assembler.

Source

pub fn buffer_mut(&mut self) -> &mut Buffer

Mutable buffer of the assembler.

Source

pub fn increment_gas(&mut self, gas: u128)

Increment the gas counter.

TODO: use number bigger than u256 for throwing proper errors. (#21)

Source

pub fn increment_sp(&mut self, items: u8) -> Result<()>

Increment stack pointer

Source

pub fn decrement_sp(&mut self, items: u8) -> Result<()>

Decrement stack pointer

Source

pub fn increment_mp(&mut self, offset: usize) -> Result<()>

Increment memory pointer

Source

pub fn decrement_mp(&mut self, offset: usize) -> Result<()>

Decrement memory pointer

Source

pub fn emit(&mut self, byte: u8)

Emit a byte.

Source

pub fn emitn(&mut self, bytes: &[u8])

Emit n bytes.

Source

pub fn emit_op(&mut self, opcode: OpCode) -> Result<()>

Emit a single opcode.

Mock the stack input and output for checking the stack usages.

Source§

impl Assembler

Basic instruction implementations

Source

pub fn _stop(&mut self) -> Result<()>

Emit STOP

Source

pub fn _add(&mut self) -> Result<()>

Emit ADD

Source

pub fn _mul(&mut self) -> Result<()>

Emit MUL

Source

pub fn _sub(&mut self) -> Result<()>

Emit SUB

Source

pub fn _div(&mut self) -> Result<()>

Emit DIV

Source

pub fn _sdiv(&mut self) -> Result<()>

Emit SDIV

Source

pub fn _mod(&mut self) -> Result<()>

Emit MOD

Source

pub fn _smod(&mut self) -> Result<()>

Emit SMOD

Source

pub fn _addmod(&mut self) -> Result<()>

Emit ADDMOD

Source

pub fn _mulmod(&mut self) -> Result<()>

Emit MULMOD

Source

pub fn _exp(&mut self) -> Result<()>

Emit EXP

Source

pub fn _signextend(&mut self) -> Result<()>

Emit SIGNEXTEND

Source

pub fn _lt(&mut self) -> Result<()>

Emit LT

Source

pub fn _gt(&mut self) -> Result<()>

Emit GT

Source

pub fn _slt(&mut self) -> Result<()>

Emit SLT

Source

pub fn _sgt(&mut self) -> Result<()>

Emit SGT

Source

pub fn _eq(&mut self) -> Result<()>

Emit EQ

Source

pub fn _iszero(&mut self) -> Result<()>

Emit ISZERO

Source

pub fn _and(&mut self) -> Result<()>

Emit AND

Source

pub fn _or(&mut self) -> Result<()>

Emit OR

Source

pub fn _xor(&mut self) -> Result<()>

Emit XOR

Source

pub fn _not(&mut self) -> Result<()>

Emit NOT

Source

pub fn _byte(&mut self) -> Result<()>

Emit BYTE

Source

pub fn _shl(&mut self) -> Result<()>

Emit SHL

Source

pub fn _shr(&mut self) -> Result<()>

Emit SHR

Source

pub fn _sar(&mut self) -> Result<()>

Emit SAR

Source

pub fn _keccak256(&mut self) -> Result<()>

Emit KECCAK256

Source

pub fn _address(&mut self) -> Result<()>

Emit ADDRESS

Source

pub fn _balance(&mut self) -> Result<()>

Emit BALANCE

Source

pub fn _origin(&mut self) -> Result<()>

Emit ORIGIN

Source

pub fn _caller(&mut self) -> Result<()>

Emit CALLER

Source

pub fn _callvalue(&mut self) -> Result<()>

Emit CALLVALUE

Source

pub fn _calldataload(&mut self) -> Result<()>

Emit CALLDATALOAD

Source

pub fn _calldatasize(&mut self) -> Result<()>

Emit CALLDATASIZE

Source

pub fn _calldatacopy(&mut self) -> Result<()>

Emit CALLDATACOPY

Source

pub fn _codesize(&mut self) -> Result<()>

Emit CODESIZE

Source

pub fn _codecopy(&mut self) -> Result<()>

Emit CODECOPY

Source

pub fn _gasprice(&mut self) -> Result<()>

Emit GASPRICE

Source

pub fn _extcodesize(&mut self) -> Result<()>

Emit EXTCODESIZE

Source

pub fn _extcodecopy(&mut self) -> Result<()>

Emit EXTCODECOPY

Source

pub fn _returndatasize(&mut self) -> Result<()>

Emit RETURNDATASIZE

Source

pub fn _returndatacopy(&mut self) -> Result<()>

Emit RETURNDATACOPY

Source

pub fn _blockhash(&mut self) -> Result<()>

Emit BLOCKHASH

Source

pub fn _coinbase(&mut self) -> Result<()>

Emit COINBASE

Source

pub fn _timestamp(&mut self) -> Result<()>

Emit TIMESTAMP

Source

pub fn _number(&mut self) -> Result<()>

Emit NUMBER

Source

pub fn _difficulty(&mut self) -> Result<()>

Emit DIFFICULTY

Source

pub fn _gaslimit(&mut self) -> Result<()>

Emit GASLIMIT

Source

pub fn _pop(&mut self) -> Result<()>

Emit POP

Source

pub fn _mload(&mut self) -> Result<()>

Emit MLOAD

Source

pub fn _mstore(&mut self) -> Result<()>

Emit MSTORE

Source

pub fn _mstore8(&mut self) -> Result<()>

Emit MSTORE8

Source

pub fn _sload(&mut self) -> Result<()>

Emit SLOAD

Source

pub fn _sstore(&mut self) -> Result<()>

Emit SSTORE

Source

pub fn _jump(&mut self) -> Result<()>

Emit JUMP

Source

pub fn _jumpi(&mut self) -> Result<()>

Emit JUMPI

Source

pub fn _pc(&mut self) -> Result<()>

Emit PC

Source

pub fn _msize(&mut self) -> Result<()>

Emit MSIZE

Source

pub fn _gas(&mut self) -> Result<()>

Emit GAS

Source

pub fn _jumpdest(&mut self) -> Result<()>

Emit JUMPDEST

Source

pub fn _push0(&mut self) -> Result<()>

Emit PUSH0

Source

pub fn _push1(&mut self) -> Result<()>

Emit PUSH1

Source

pub fn _push2(&mut self) -> Result<()>

Emit PUSH2

Source

pub fn _push3(&mut self) -> Result<()>

Emit PUSH3

Source

pub fn _push4(&mut self) -> Result<()>

Emit PUSH4

Source

pub fn _push5(&mut self) -> Result<()>

Emit PUSH5

Source

pub fn _push6(&mut self) -> Result<()>

Emit PUSH6

Source

pub fn _push7(&mut self) -> Result<()>

Emit PUSH7

Source

pub fn _push8(&mut self) -> Result<()>

Emit PUSH8

Source

pub fn _push9(&mut self) -> Result<()>

Emit PUSH9

Source

pub fn _push10(&mut self) -> Result<()>

Emit PUSH10

Source

pub fn _push11(&mut self) -> Result<()>

Emit PUSH11

Source

pub fn _push12(&mut self) -> Result<()>

Emit PUSH12

Source

pub fn _push13(&mut self) -> Result<()>

Emit PUSH13

Source

pub fn _push14(&mut self) -> Result<()>

Emit PUSH14

Source

pub fn _push15(&mut self) -> Result<()>

Emit PUSH15

Source

pub fn _push16(&mut self) -> Result<()>

Emit PUSH16

Source

pub fn _push17(&mut self) -> Result<()>

Emit PUSH17

Source

pub fn _push18(&mut self) -> Result<()>

Emit PUSH18

Source

pub fn _push19(&mut self) -> Result<()>

Emit PUSH19

Source

pub fn _push20(&mut self) -> Result<()>

Emit PUSH20

Source

pub fn _push21(&mut self) -> Result<()>

Emit PUSH21

Source

pub fn _push22(&mut self) -> Result<()>

Emit PUSH22

Source

pub fn _push23(&mut self) -> Result<()>

Emit PUSH23

Source

pub fn _push24(&mut self) -> Result<()>

Emit PUSH24

Source

pub fn _push25(&mut self) -> Result<()>

Emit PUSH25

Source

pub fn _push26(&mut self) -> Result<()>

Emit PUSH26

Source

pub fn _push27(&mut self) -> Result<()>

Emit PUSH27

Source

pub fn _push28(&mut self) -> Result<()>

Emit PUSH28

Source

pub fn _push29(&mut self) -> Result<()>

Emit PUSH29

Source

pub fn _push30(&mut self) -> Result<()>

Emit PUSH30

Source

pub fn _push31(&mut self) -> Result<()>

Emit PUSH31

Source

pub fn _push32(&mut self) -> Result<()>

Emit PUSH32

Source

pub fn _dup1(&mut self) -> Result<()>

Emit DUP1

Source

pub fn _dup2(&mut self) -> Result<()>

Emit DUP2

Source

pub fn _dup3(&mut self) -> Result<()>

Emit DUP3

Source

pub fn _dup4(&mut self) -> Result<()>

Emit DUP4

Source

pub fn _dup5(&mut self) -> Result<()>

Emit DUP5

Source

pub fn _dup6(&mut self) -> Result<()>

Emit DUP6

Source

pub fn _dup7(&mut self) -> Result<()>

Emit DUP7

Source

pub fn _dup8(&mut self) -> Result<()>

Emit DUP8

Source

pub fn _dup9(&mut self) -> Result<()>

Emit DUP9

Source

pub fn _dup10(&mut self) -> Result<()>

Emit DUP10

Source

pub fn _dup11(&mut self) -> Result<()>

Emit DUP11

Source

pub fn _dup12(&mut self) -> Result<()>

Emit DUP12

Source

pub fn _dup13(&mut self) -> Result<()>

Emit DUP13

Source

pub fn _dup14(&mut self) -> Result<()>

Emit DUP14

Source

pub fn _dup15(&mut self) -> Result<()>

Emit DUP15

Source

pub fn _dup16(&mut self) -> Result<()>

Emit DUP16

Source

pub fn _swap1(&mut self) -> Result<()>

Emit SWAP1

Source

pub fn _swap2(&mut self) -> Result<()>

Emit SWAP2

Source

pub fn _swap3(&mut self) -> Result<()>

Emit SWAP3

Source

pub fn _swap4(&mut self) -> Result<()>

Emit SWAP4

Source

pub fn _swap5(&mut self) -> Result<()>

Emit SWAP5

Source

pub fn _swap6(&mut self) -> Result<()>

Emit SWAP6

Source

pub fn _swap7(&mut self) -> Result<()>

Emit SWAP7

Source

pub fn _swap8(&mut self) -> Result<()>

Emit SWAP8

Source

pub fn _swap9(&mut self) -> Result<()>

Emit SWAP9

Source

pub fn _swap10(&mut self) -> Result<()>

Emit SWAP10

Source

pub fn _swap11(&mut self) -> Result<()>

Emit SWAP11

Source

pub fn _swap12(&mut self) -> Result<()>

Emit SWAP12

Source

pub fn _swap13(&mut self) -> Result<()>

Emit SWAP13

Source

pub fn _swap14(&mut self) -> Result<()>

Emit SWAP14

Source

pub fn _swap15(&mut self) -> Result<()>

Emit SWAP15

Source

pub fn _swap16(&mut self) -> Result<()>

Emit SWAP16

Source

pub fn _log0(&mut self) -> Result<()>

Emit LOG0

Source

pub fn _log1(&mut self) -> Result<()>

Emit LOG1

Source

pub fn _log2(&mut self) -> Result<()>

Emit LOG2

Source

pub fn _log3(&mut self) -> Result<()>

Emit LOG3

Source

pub fn _log4(&mut self) -> Result<()>

Emit LOG4

Source

pub fn _create(&mut self) -> Result<()>

Emit CREATE

Source

pub fn _call(&mut self) -> Result<()>

Emit CALL

Source

pub fn _callcode(&mut self) -> Result<()>

Emit CALLCODE

Source

pub fn _return(&mut self) -> Result<()>

Emit RETURN

Source

pub fn _delegatecall(&mut self) -> Result<()>

Emit DELEGATECALL

Source

pub fn _create2(&mut self) -> Result<()>

Emit CREATE2

Source

pub fn _staticcall(&mut self) -> Result<()>

Emit STATICCALL

Source

pub fn _revert(&mut self) -> Result<()>

Emit REVERT

Source

pub fn _invalid(&mut self) -> Result<()>

Emit INVALID

Source

pub fn _selfdestruct(&mut self) -> Result<()>

Emit SELFDESTRUCT

Trait Implementations§

Source§

impl Clone for Assembler

Source§

fn clone(&self) -> Assembler

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

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Assembler

Source§

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

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

impl Default for Assembler

Source§

fn default() -> Assembler

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> CloneToUninit for T
where T: Clone,

Source§

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> 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
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> 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