Expand description
Storage Key Computation Module
Computes deterministic storage keys for Neo N3 smart contract state
variables, matching the layout actually emitted by the compiler’s
bytecode (see src/cli/bytecode/bytecode_helpers/storage/mapping.rs).
§Key Derivation (production scheme)
- Base slot of a state variable:
SHA256(variable_name)—compute_state_slot. Struct fields use the same hash over the qualified"Struct::field"name (seesrc/ir/build/inference.rs). - Mapping entry / dynamic-array element: derived ITERATIVELY per nesting
level on-chain as
slot = keccak256(StdLib.serialize(key) || slot), whereserializeis Neo’s StdLib binary serializer applied to the canonicalized key stack item and the current slot is appended LAST. Dynamic arrays store their length at the base slot and elementiatkeccak256(serialize(i) || slot). - Struct field inside a mapping value:
keccak256(field_key || slot)wherefield_key = SHA256("Struct::field").
The mapping-entry derivation depends on Neo’s StdLib serialize native
call (the serialized form embeds the stack-item type byte), so it cannot
be reproduced faithfully off-chain without replicating Neo’s
BinarySerializer byte-for-byte. A previous derive_mapping_slot /
KeyFragment API in this module implemented a DIFFERENT, untyped
SHA-256-based scheme that matched nothing the compiler emits; it has been
removed so off-chain consumers cannot silently compute wrong keys.
Functions§
- compute_
state_ slot - Compute the canonical storage slot hash for a state variable name.