Expand description
Storage slot identification and decoding utilities for Solidity storage layouts.
This module provides functionality to identify and decode storage slots based on Solidity storage layout information from the compiler.
Re-exportsΒ§
use crate::constants::EIP1967_ADMIN_SLOT;πuse crate::constants::EIP1967_BEACON_SLOT;πuse crate::constants::EIP1967_IMPLEMENTATION_SLOT;πuse crate::mapping_slots::MappingSlots;πuse crate::namespaced_storage::unscoped_type_id;πuse alloy_dyn_abi::DynSolType;πuse alloy_dyn_abi::DynSolValue;πuse alloy_primitives::B256;πuse alloy_primitives::U256;πuse alloy_primitives::hex;πuse alloy_primitives::hex;πuse alloy_primitives::keccak256;πuse alloy_primitives::map::B256Map;πuse foundry_common_fmt::format_token_raw;πuse foundry_compilers::artifacts::Storage;πuse foundry_compilers::artifacts::StorageLayout;πuse foundry_compilers::artifacts::StorageType;πuse serde::Serialize;πuse serde::Serialize;πuse serde::ser::SerializeMap;πuse serde::ser::SerializeStruct;πuse std::collections::BTreeMap;πuse std::fmt;πuse std::str::FromStr;πuse std::sync::Arc;πuse tracing::trace;π
StructsΒ§
- Decoded
Slot Values - Decoded storage slot values
- Slot
Identifier - Storage slot identifier that uses Solidity [
StorageLayout] to identify storage slots. - Slot
Info - Information about a storage slot including its label, type, and decoded values.
- Storage
Type Info - Wrapper type that holds both the original type label and the parsed DynSolType.
ConstantsΒ§
- ENCODING_
BYTES - βbytesβ encoding type for bytes and string types, which use either inplace or keccak256 hash-based storage depending on length
- ENCODING_
DYN_ ARRAY - βdynamic_arrayβ encoding type for dynamic arrays, which uses keccak256 hash-based storage
- ENCODING_
INPLACE - βinplaceβ encoding type for variables that fit in one storage slot i.e 32 bytes
- ENCODING_
MAPPING - βmappingβ encoding type for Solidity mappings, which use keccak256 hash-based storage
- MAX_
ARRAY_ πSLOTS - How many slots past its data start an element of a dynamic array is searched for. Data starts are hashes, so any other slot this close to one would be a hash collision.
- MAX_
DEPTH π - How deep nested structs, mappings and dynamic arrays are followed when identifying a slot.
- MAX_
VALUE_ πSLOTS - How far into a mapping value a recorded entry is searched for: the slot offset of a struct field from the entry holding the struct.
- UDVT_
TYPE_ πPREFIX - Prefix of the layoutβs type ids for user-defined value types, e.g.
t_userDefinedValueType(Delay)1234.
FunctionsΒ§
- decode_
packed π - Decodes the value of type
typacked intowordat byteoffset. - get_
array_ πbase_ indices - Returns the base indices for array types, e.g. β[0][0]β for 2D arrays.
- identify_
eip1967_ slot - Identifies the standard EIP-1967 proxy slots, which proxies write from assembly constants that no storage layout covers.
- is_
struct - Checks if a given type label represents a struct type.
- mapping_
entry π - The recorded mapping entry
slotbelongs to and its slot offset from it: the entry itself, or a field of a struct stored there. - packed_
array π - The element type, length and element size of an array of several elements packed into one slot.
- packed_
size π - The size in bytes of a value type that can share a slot with others.
- parse_
sol_ πtype - Parses a storage type label into a [
DynSolType], returningNonefor labels that have no direct ABI equivalent (mappings, structs). - resolve_
sol_ πtype - Resolves the layout type
idto a [DynSolType], returningNonefor types that have no direct ABI equivalent (mappings, structs). - serialize_
mapping_ πkeys - Custom serializer for mapping keys
- serialize_
slot_ πtype - Custom serializer for StorageTypeInfo that only outputs the label