Struct Bytecode
pub struct Bytecode(/* private fields */);Expand description
Ethereum EVM bytecode.
Implementations§
§impl Bytecode
impl Bytecode
pub fn new_legacy(raw: Bytes) -> Bytecode
pub fn new_legacy(raw: Bytes) -> Bytecode
Creates a new legacy Bytecode with padding and deferred jump analysis.
Appends 33 zero bytes unless the input already ends with 33 zeros. Empty code retains its single STOP representation.
pub fn new_raw(bytecode: Bytes) -> Bytecode
pub fn new_raw(bytecode: Bytes) -> Bytecode
Creates a new raw Bytecode.
§Panics
Panics if bytecode is in incorrect format. If you want to handle errors use
Self::new_raw_checked.
pub fn new_eip7702(address: Address) -> Bytecode
pub fn new_eip7702(address: Address) -> Bytecode
Creates a new EIP-7702 Bytecode from [Address].
pub fn new_raw_checked(bytes: Bytes) -> Result<Bytecode, BytecodeDecodeError>
pub fn new_raw_checked(bytes: Bytes) -> Result<Bytecode, BytecodeDecodeError>
Creates a new raw Bytecode.
Returns an error on incorrect bytecode format.
pub fn from_stored(bytes: Bytes) -> Bytecode
pub fn from_stored(bytes: Bytes) -> Bytecode
Creates a new Bytecode from code read from state.
Valid EIP-7702 delegation designators become EIP-7702 bytecode and anything else is legacy
code. Unlike Self::new_raw_checked, code starting with the EIP-7702 magic that is not a
valid designator is accepted as legacy, since it may have been deployed before EIP-3541.
pub fn new_eip7702_raw(bytes: Bytes) -> Result<Bytecode, Eip7702DecodeError>
pub fn new_eip7702_raw(bytes: Bytes) -> Result<Bytecode, Eip7702DecodeError>
Creates a new EIP-7702 Bytecode from raw bytes.
Returns an error if the bytes are not valid EIP-7702 bytecode.
pub unsafe fn new_analyzed(
bytecode: Bytes,
original_len: usize,
jump_table: JumpTable,
) -> Bytecode
pub unsafe fn new_analyzed( bytecode: Bytes, original_len: usize, jump_table: JumpTable, ) -> Bytecode
Create new checked bytecode from pre-analyzed components.
§Safety
bytecode must satisfy the same padding invariants produced by
pad_legacy. In particular, execution must never cause the
interpreter to read past the backing allocation when decoding opcode
immediates (PUSH1-PUSH32 via read_slice, and DUPN/SWAPN/
EXCHANGE via read_u8).
Bytecode::new_legacy handles this automatically.
This constructor is only for restoring trusted, previously analyzed
bytecode where the padding was already applied.
Violating this causes undefined behavior during execution due to out-of-bounds reads from raw pointers.
§Panics
- If
original_lenis greater thanbytecode.len() - If jump table length is less than
original_len - If bytecode is empty
pub fn kind(&self) -> BytecodeKind
pub fn kind(&self) -> BytecodeKind
Returns the kind of bytecode.
pub fn is_eip7702(&self) -> bool
pub fn is_eip7702(&self) -> bool
Returns true if bytecode is EIP-7702.
pub fn eip7702_address(&self) -> Option<Address>
pub fn eip7702_address(&self) -> Option<Address>
Returns the EIP-7702 delegated address if this is EIP-7702 bytecode.
pub fn legacy_jump_table(&self) -> Option<&JumpTable>
pub fn legacy_jump_table(&self) -> Option<&JumpTable>
Returns the legacy jump table, initializing it on first access.
pub fn hash_slow(&self) -> FixedBytes<32>
pub fn hash_slow(&self) -> FixedBytes<32>
Calculates or returns cached hash of the bytecode.
pub fn seed_hash(&self, hash: FixedBytes<32>)
pub fn seed_hash(&self, hash: FixedBytes<32>)
Caches hash as the hash of the original bytecode unless one is already cached.
hash must be the keccak256 of Self::original_byte_slice. Does nothing for empty
bytecode or the zero hash.
pub fn bytes(&self) -> &Bytes
pub fn bytes(&self) -> &Bytes
Returns a reference to the potentially padded bytecode bytes.
pub fn bytes_slice(&self) -> &[u8] ⓘ
pub fn bytes_slice(&self) -> &[u8] ⓘ
Returns the bytecode as a slice.
pub fn original_bytes(&self) -> Bytes
pub fn original_bytes(&self) -> Bytes
Returns the original bytecode without padding.
pub fn original_byte_slice(&self) -> &[u8] ⓘ
pub fn original_byte_slice(&self) -> &[u8] ⓘ
Returns the original bytecode as a byte slice without padding.
Trait Implementations§
§impl<'de> Deserialize<'de> for Bytecode
impl<'de> Deserialize<'de> for Bytecode
§fn deserialize<D>(
deserializer: D,
) -> Result<Bytecode, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<Bytecode, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
impl Eq for Bytecode
§impl Ord for Bytecode
impl Ord for Bytecode
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
§impl PartialOrd for Bytecode
impl PartialOrd for Bytecode
§impl Serialize for Bytecode
impl Serialize for Bytecode
§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Auto Trait Implementations§
impl Forget for Bytecode
impl Freeze for Bytecode
impl Move for Bytecode
impl RefUnwindSafe for Bytecode
impl Send for Bytecode
impl Sync for Bytecode
impl Unpin for Bytecode
impl UnsafeUnpin for Bytecode
impl UnwindSafe for Bytecode
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<'de, T> BorrowedRpcObject<'de> for Twhere
T: RpcBorrow<'de> + RpcSend,
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreimpl<T> MaybeDebug for Twhere
T: Debug,
impl<T> MaybeSerde for Twhere
T: Serialize + for<'de> Deserialize<'de>,
§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
impl<'de, T> RpcBorrow<'de> for T
impl<T> RpcObject for Twhere
T: RpcSend + RpcRecv,
impl<T> RpcRecv for T
impl<T> RpcSend for T
§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘwhere
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘwhere
S: Into<Dispatch>,
§fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ
fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ
Source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
Source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘwhere
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘwhere
S: Into<Dispatch>,
Source§fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ
fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 8 bytes