Skip to main content

PrecompileStorageProvider

Trait PrecompileStorageProvider 

Source
pub trait PrecompileStorageProvider {
Show 22 methods // Required methods fn chain_id(&self) -> u64; fn timestamp(&self) -> U256; fn beneficiary(&self) -> Address; fn block_number(&self) -> u64; fn set_code(&mut self, address: Address, code: Bytecode) -> Result<()>; fn with_account_info( &mut self, address: Address, f: &mut dyn FnMut(&AccountInfo), ) -> Result<()>; fn sload(&mut self, address: Address, key: U256) -> Result<U256>; fn tload(&mut self, address: Address, key: U256) -> Result<U256>; fn sstore(&mut self, address: Address, key: U256, value: U256) -> Result<()>; fn tstore(&mut self, address: Address, key: U256, value: U256) -> Result<()>; fn emit_event(&mut self, address: Address, event: LogData) -> Result<()>; fn deduct_gas(&mut self, gas: u64) -> Result<()>; fn refund_gas(&mut self, gas: i64); fn gas_used(&self) -> u64; fn gas_refunded(&self) -> i64; fn spec(&self) -> TempoHardfork; fn is_static(&self) -> bool; fn checkpoint(&mut self) -> JournalCheckpoint; fn checkpoint_commit(&mut self, checkpoint: JournalCheckpoint); fn checkpoint_revert(&mut self, checkpoint: JournalCheckpoint); // Provided methods fn keccak256(&mut self, data: &[u8]) -> Result<B256> { ... } fn recover_signer( &mut self, digest: B256, v: u8, r: B256, s: B256, ) -> Result<Option<Address>> { ... }
}
Expand description

Low-level storage provider for interacting with the EVM.

§Implementations

  • EvmPrecompileStorageProvider - Production EVM storage
  • HashMapStorageProvider - Test storage

§Sync with [StorageCtx]

StorageCtx mirrors these methods with split mutability for read (staticcall) vs write (call). When adding new methods here, remember to add corresponding methods to StorageCtx.

Required Methods§

Source

fn chain_id(&self) -> u64

Returns the chain ID.

Source

fn timestamp(&self) -> U256

Returns the current block timestamp.

Source

fn beneficiary(&self) -> Address

Returns the current block beneficiary (coinbase).

Source

fn block_number(&self) -> u64

Returns the current block number.

Source

fn set_code(&mut self, address: Address, code: Bytecode) -> Result<()>

Sets the bytecode at the given address.

Source

fn with_account_info( &mut self, address: Address, f: &mut dyn FnMut(&AccountInfo), ) -> Result<()>

Executes a closure with access to the account info for the given address.

Source

fn sload(&mut self, address: Address, key: U256) -> Result<U256>

Performs an SLOAD operation (persistent storage read).

Source

fn tload(&mut self, address: Address, key: U256) -> Result<U256>

Performs a TLOAD operation (transient storage read).

Source

fn sstore(&mut self, address: Address, key: U256, value: U256) -> Result<()>

Performs an SSTORE operation (persistent storage write).

Source

fn tstore(&mut self, address: Address, key: U256, value: U256) -> Result<()>

Performs a TSTORE operation (transient storage write).

Source

fn emit_event(&mut self, address: Address, event: LogData) -> Result<()>

Emits an event from the given contract address.

Source

fn deduct_gas(&mut self, gas: u64) -> Result<()>

Deducts gas from the remaining gas and returns an error if insufficient.

Source

fn refund_gas(&mut self, gas: i64)

Add refund to the refund gas counter.

Source

fn gas_used(&self) -> u64

Returns the gas used so far.

Source

fn gas_refunded(&self) -> i64

Returns the gas refunded so far.

Source

fn spec(&self) -> TempoHardfork

Returns the currently active hardfork.

Source

fn is_static(&self) -> bool

Returns whether the current call context is static.

Source

fn checkpoint(&mut self) -> JournalCheckpoint

Creates a new journal checkpoint so that all subsequent state-changing operations can be atomically committed (checkpoint_commit) or reverted (checkpoint_revert).

Prefer StorageCtx::checkpoint which returns a CheckpointGuard that auto-reverts on drop and is hardfork-aware (no-op pre-T1C).

Source

fn checkpoint_commit(&mut self, checkpoint: JournalCheckpoint)

Commits all state changes since the given checkpoint.

Prefer CheckpointGuard::commit.

Source

fn checkpoint_revert(&mut self, checkpoint: JournalCheckpoint)

Reverts all state changes back to the given checkpoint.

Prefer CheckpointGuard (auto-reverts on drop).

Provided Methods§

Source

fn keccak256(&mut self, data: &[u8]) -> Result<B256>

Computes keccak256 and charges the appropriate gas.

Implementations should use this over naked keccak256 call to ensure gas is accounted for.

Source

fn recover_signer( &mut self, digest: B256, v: u8, r: B256, s: B256, ) -> Result<Option<Address>>

Recovers the signer address from an ECDSA signature and charges ecrecover gas. As per TIP-1004, it only accepts v values of 27 or 28 (no 0/1 normalization).

Returns Ok(None) on invalid signatures; callers map to domain-specific errors.

Implementors§