Skip to main content

Module slot_identifier

Module slot_identifier 

Source
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Β§

DecodedSlotValues
Decoded storage slot values
SlotIdentifier
Storage slot identifier that uses Solidity [StorageLayout] to identify storage slots.
SlotInfo
Information about a storage slot including its label, type, and decoded values.
StorageTypeInfo
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 ty packed into word at byte offset.
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 slot belongs 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], returning None for labels that have no direct ABI equivalent (mappings, structs).
resolve_sol_type πŸ”’
Resolves the layout type id to a [DynSolType], returning None for 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