Struct evmil::bytecode::Assembly

source ·
pub struct Assembly { /* private fields */ }
Expand description

A structured representation of an EVM bytecode contract which is either a legacy contract, or an EVM Object Format (EOF) compatiable contract. Regardless of whether it is legacy or not, a contract is divided into one or more sections. A section is either a code section or a data section. For EOF contracts, the data section should also come last. However, for legacy contracts, they can be interleaved.

Implementations§

source§

impl Assembly

source

pub fn from_legacy_bytes(bytes: &[u8]) -> Assembly

source

pub fn from_eof_bytes(bytes: &[u8]) -> Result<Assembly, DecodingError>

A decoded EOF byte sequence (see EIP3540). This provides a gateway for disassembling EOF contracts into assembly language and back again.

§Examples
use evmil::bytecode::Assembly;
use evmil::util::FromHexString;

// EOF bytecode contract
let hex = "0xef00010100040200010001030000000000000000";
// Conversion into bytes
let bytes = hex.from_hex_string().unwrap();
// Decode EOF bytecode (assuming no errors)
let eof = Assembly::from_eof_bytes(&bytes).unwrap();
// Check that section contains one instruction
// assert_eq!(eof.sections.len(),1);
source

pub fn empty() -> Self

source

pub fn new(sections: Vec<StructuredSection>) -> Self

source

pub fn len(&self) -> usize

Return the number of sections in the code.

source

pub fn is_empty(&self) -> bool

Return true if the are no sections in this assembly.

source

pub fn iter(&self) -> Iter<'_, StructuredSection>

source

pub fn iter_mut(&mut self) -> IterMut<'_, StructuredSection>

source

pub fn add(&mut self, section: StructuredSection)

Add a new section to this bytecode container

source

pub fn from_str(input: &str) -> Result<Assembly, ParseError>

Parse some assembly language into an Assembly. This can fail for a variety of reasons, such as an unknown instruction is used or there is some unexpected junk in the file.

source§

impl Assembly

source

pub fn to_legacy_bytes(&self) -> Vec<u8>

source

pub fn to_eof_bytes(&self) -> Vec<u8>

Trait Implementations§

source§

impl Clone for Assembly

source§

fn clone(&self) -> Assembly

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 Assembly

source§

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

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

impl<'a> IntoIterator for &'a Assembly

§

type Item = &'a StructuredSection

The type of the elements being iterated over.
§

type IntoIter = Iter<'a, StructuredSection>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<'a> IntoIterator for &'a mut Assembly

§

type Item = &'a mut StructuredSection

The type of the elements being iterated over.
§

type IntoIter = IterMut<'a, StructuredSection>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl PartialEq for Assembly

source§

fn eq(&self, other: &Assembly) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl TryFrom<&[Term]> for Assembly

Translate a sequence of IL statements into EVM bytecode, or fail with an error.

§

type Error = CompilerError

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

fn try_from(terms: &[Term]) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<const N: usize> TryFrom<&[Term; N]> for Assembly

Translate a sequence of IL statements into EVM bytecode, or fail with an error.

§

type Error = CompilerError

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

fn try_from(terms: &[Term; N]) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl StructuralPartialEq for Assembly

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

§

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

§

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

§

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.