Expand description
Shared utilities for packing and unpacking values in EVM storage slots.
This module provides helper functions for bit-level manipulation of storage slots, enabling efficient packing of multiple small values into single 32-byte slots.
Packing only applies to primitive types where LAYOUT::Bytes(count) && count < 32.
Non-primitives (structs, fixed-size arrays, dynamic types) have LAYOUT = Layout::Slot.
§Solidity Compatibility
This implementation matches Solidity’s value packing convention:
- Values are right-aligned within their byte range
- Types smaller than 32 bytes can pack multiple per slot when dimensions align
Structs§
- Field
Location - Location information for a packed field within a storage slot.
- Packed
Slot - A helper struct to support packing elements into a single slot. Represents an in-memory storage slot value.
Functions§
- calc_
element_ loc - Calculate the element location within a slot for an array element at index
idx. - calc_
element_ offset - Calculate the byte offset within a slot for an array element at index
idx. - calc_
element_ slot - Calculate which slot an array element at index
idxstarts in. - calc_
packed_ slot_ count - Calculate the total number of slots needed for an array.
- create_
element_ mask - Create a bit mask for a value of the given byte size.
- extract_
packed_ value - Extract a packed value from a storage slot at a given byte offset.
- gen_
word_ from test-utils - Test helper function for constructing EVM words from hex string literals.
- insert_
packed_ value - Insert a packed value into a storage slot at a given byte offset.
- zero_
packed_ value - Zero out a packed value in a storage slot at a given byte offset.