Expand description
Registration of constant-folded mapping slots as concrete Keccak preimages.
With the optimizer on, solc folds the slot of a mapping entry at a constant key,
keccak256(abi.encode(key, slot)), into one PUSH32. The engine treats a constant slot as a
hash only when it knows a preimage, so the folded slot would otherwise count as a fixed slot
that a write through a symbolic key never reaches. A mapping entry that setUp wrote is such a
constant slot in the backend, and a read through a symbolic key only selects it with a known
preimage. Before a run, the mapping roots in the storage layout of each deployed contract are
hashed with every candidate key: the source literals, the addresses of the backendβs accounts,
and the contractβs PUSH immediates. The nested level of a nested mapping is a product over
the literals and immediates, so it is searched only when the run accesses a large constant slot
that the contractβs code pushes, and only the match is recorded. A registered preimage is a
real one, so this adds no unsoundness; constants that no candidate produces, such as ERC-1967
and ERC-7201 roots, stay fixed slots.
Re-exportsΒ§
use foundry_common::slot_identifier::ENCODING_INPLACE;πuse foundry_common::slot_identifier::ENCODING_MAPPING;πuse foundry_compilers::artifacts::Storage;πuse foundry_compilers::artifacts::StorageLayout;πuse foundry_compilers::artifacts::StorageType;πuse super::*;π
StructsΒ§
- Folded
Contract π - Folded
Slots π - Candidate keys and storage layouts of the deployed contracts, kept to resolve the nested level of a folded mapping slot on demand.
ConstantsΒ§
FunctionsΒ§
- key_
fits π - Returns whether
keyis a value of the mapping key typetyasabi.encodepads it. - mapping_
preimage π - Returns
keccak(key . slot)and its 64-byte preimage. - past_
deadline π - push_
immediates π - Returns the right-aligned values of the
PUSHimmediates incode. - record_
mapping_ πpreimage - Records
keccak(key . slot)with its preimage and returns the hash. - record_
preimage_ πbytes - walk_
mapping_ πslots - Calls
hashfor every candidate key that fits the key type of the mapping atslot, descending into struct members andlevels - 1nested mapping levels through the returned hash. Returnsfalsewhenhashstopped the walk.