Expand description
Simulation error types and revert-reason decoding.
Every EVM revert is either one of the two Solidity built-ins —
Error(string) (from require/revert("msg")) and Panic(uint256) (from
overflow, division-by-zero, etc.) — or a contract-defined custom error
identified by a 4-byte selector. This module decodes the two built-ins
natively and lets callers register any number of their own custom Solidity
errors with a RevertDecoder.
Application-specific selectors therefore live in the application, not in this
generic layer: define them with sol! and register them once.
Note that Panic(uint256) codes that exceed
u64::MAX are dropped to None during decoding (and so surface as
RevertReason::Unknown). This is benign: real compiler-emitted panic
codes are single-byte constants (e.g. 0x11, 0x32).
use alloy_sol_types::{SolError, sol};
use evm_fork_cache::errors::{RevertDecoder, RevertReason};
sol! {
#[derive(Debug)]
error Unauthorized(address caller);
}
let decoder = RevertDecoder::new().with_error::<Unauthorized>();
// 4-byte selector of `Unauthorized`, with no parameter bytes.
let raw = alloy_primitives::Bytes::from(Unauthorized::SELECTOR.to_vec());
match decoder.decode(&raw) {
RevertReason::Custom(err) => assert_eq!(err.name, "Unauthorized(address)"),
other => panic!("expected a custom error, got {other}"),
}Structs§
- Custom
Revert - A decoded contract-defined custom error.
- Duplicate
Selector Error - Error returned when registering a custom error selector that already exists.
- Revert
Decoder - Decodes raw EVM revert data into a
RevertReason. - Simulation
Error - A structured simulation revert with its decoded reason.
Enums§
- Access
List Error - Access-list pricing query failure.
- Block
Context Error - Error raised when validating or refreshing the block-execution context
(
NUMBER/BASEFEE/COINBASE/PREVRANDAO/GASLIMITopcodes). - Cache
Error - General cache-operation error for APIs that execute or mutate local fork
state but do not classify EVM reverts as
SimError. - Deploy
Error - Deployment and Foundry-artifact loading failure.
- Freshness
Error - Error returned by speculative freshness orchestration.
- Multicall
Error - Multicall3 helper failure.
- Overlay
Error - Error for immutable snapshot-overlay execution helpers that do not classify
reverts as
SimError. - Persistence
Error - Persistence failure for crate-owned on-disk cache files.
- Revert
Reason - A decoded EVM revert reason.
- RpcError
- Error returned by direct RPC call callbacks installed on
EvmCache. - Runtime
Error - Error returned when crate-managed synchronous RPC bridges cannot enter the required tokio runtime context.
- SimError
- Error returned by simulation entry points.
- SimHost
Error - Host-side failure for simulation entry points.
- Storage
Fetch Error - Error returned by storage/proof batch callbacks.
Constants§
- ERROR_
SELECTOR - 4-byte selector of the standard Solidity
Error(string)revert (0x08c379a0), emitted byrequire/revert("msg"). - PANIC_
SELECTOR - 4-byte selector of the standard Solidity
Panic(uint256)revert (0x4e487b71), emitted on overflow, division-by-zero, etc.
Functions§
- decode_
revert_ reason - Decode revert data using only the standard Solidity built-ins.
Type Aliases§
- Access
List Result - Result type returned by access-list pricing helpers.
- Cache
Result - Result type returned by cache APIs.
- Deploy
Result - Result type returned by deployment helpers.
- Freshness
Result - Result type returned by freshness APIs.
- Multicall
Result - Result type returned by Multicall3 helpers.
- Overlay
Result - Result type returned by overlay APIs that return raw
ExecutionResultvalues instead of classifying reverts. - Simulation
Result - Result type returned by simulation entry points:
Ok(T)on success, or aSimErrordistinguishing a transaction-level revert, an EVM halt, and a host-side failure. - Storage
Fetch Result - Result type returned by storage/proof batch callbacks.