pub struct Substate {
pub refunded_gas: u64,
/* private fields */
}Expand description
Execution substate that tracks changes during transaction execution.
The substate maintains all information that may need to be reverted if a call fails, including:
- Self-destructed accounts
- Accessed addresses and storage slots (for EIP-2929 gas accounting)
- Created accounts
- Gas refunds
- Transient storage (EIP-1153)
- Event logs
§Backup Mechanism
The substate supports checkpointing via [push_backup] and restoration via
[revert_backup] or commitment via [commit_backup]. This is used to handle
nested calls where inner calls may fail and need to be reverted.
Most fields are private by design. The backup mechanism only works correctly if data modifications are append-only.
Fields§
§refunded_gas: u64Accumulated gas refund (e.g., from storage clears).
Implementations§
Source§impl Substate
impl Substate
pub fn from_accesses( fork: Fork, accessed_addresses: FxHashSet<Address>, accessed_storage_slots: FxHashMap<Address, FxHashSet<H256>>, ) -> Self
Sourcepub fn push_backup(&mut self)
pub fn push_backup(&mut self)
Push a checkpoint that can be either reverted or committed. All data up to this point is still accessible.
Sourcepub fn commit_backup(&mut self)
pub fn commit_backup(&mut self)
Pop and merge with the last backup.
Does nothing if the substate has no backup.
Sourcepub fn revert_backup(&mut self)
pub fn revert_backup(&mut self)
Discard current changes and revert to last backup.
Does nothing if the substate has no backup.
Sourcepub fn iter_selfdestruct(&self) -> impl Iterator<Item = &Address>
pub fn iter_selfdestruct(&self) -> impl Iterator<Item = &Address>
Return an iterator over all selfdestruct addresses.
Sourcepub fn add_selfdestruct(&mut self, address: Address) -> bool
pub fn add_selfdestruct(&mut self, address: Address) -> bool
Mark an address as selfdestructed and return whether is was already marked.
Sourcepub fn is_selfdestruct(&self, address: &Address) -> bool
pub fn is_selfdestruct(&self, address: &Address) -> bool
Return whether an address is already marked as selfdestructed.
Sourcepub fn make_access_list(&self) -> Vec<AccessListEntry>
pub fn make_access_list(&self) -> Vec<AccessListEntry>
Build an access list from all accessed storage slots.
Sourcepub fn add_accessed_slot(&mut self, address: Address, key: H256) -> bool
pub fn add_accessed_slot(&mut self, address: Address, key: H256) -> bool
Mark an address as accessed and return whether the slot was cold.
Sourcepub fn is_slot_accessed(&self, address: &Address, key: &H256) -> bool
pub fn is_slot_accessed(&self, address: &Address, key: &H256) -> bool
Return whether an address has already been accessed.
Sourcepub fn get_accessed_storage_slots(&self, address: &Address) -> BTreeSet<H256>
pub fn get_accessed_storage_slots(&self, address: &Address) -> BTreeSet<H256>
Returns all accessed storage slots for a given address. Used by SELFDESTRUCT to record storage reads in BAL per EIP-7928: “SELFDESTRUCT: Include modified/read storage keys as storage_read”
Sourcepub fn add_accessed_address(&mut self, address: Address) -> bool
pub fn add_accessed_address(&mut self, address: Address) -> bool
Mark an address as accessed and return whether the address was cold.
Sourcepub fn is_address_accessed(&self, address: &Address) -> bool
pub fn is_address_accessed(&self, address: &Address) -> bool
Return whether an address has already been accessed.
Sourcepub fn add_created_account(&mut self, address: Address) -> bool
pub fn add_created_account(&mut self, address: Address) -> bool
Mark an address as a new account and return whether is was already marked.
Sourcepub fn is_account_created(&self, address: &Address) -> bool
pub fn is_account_created(&self, address: &Address) -> bool
Return whether an address has already been marked as a new account.
Sourcepub fn get_transient(&self, to: &Address, key: &U256) -> U256
pub fn get_transient(&self, to: &Address, key: &U256) -> U256
Return the data associated with a transient storage entry, or zero if not present.
Sourcepub fn set_transient(&mut self, to: &Address, key: &U256, value: U256)
pub fn set_transient(&mut self, to: &Address, key: &U256, value: U256)
Return the data associated with a transient storage entry, or zero if not present.
Sourcepub fn extract_logs(&self) -> Vec<Log>
pub fn extract_logs(&self) -> Vec<Log>
Extract all logs in order.
Source§impl Substate
impl Substate
Sourcepub fn initialize(
env: &Environment,
tx: &Transaction,
) -> Result<Substate, VMError>
pub fn initialize( env: &Environment, tx: &Transaction, ) -> Result<Substate, VMError>
Initializes the VM substate, mainly adding addresses to the “accessed_addresses” field and the same with storage slots
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Substate
impl RefUnwindSafe for Substate
impl Send for Substate
impl Sync for Substate
impl Unpin for Substate
impl UnsafeUnpin for Substate
impl UnwindSafe for Substate
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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
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 moreSource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.