Check that a Cairo StorePacking implementation round-trips

Packing several fields into one storage slot can reduce the number of state writes. A layout error can cause one field to overwrite another without changing the contract’s external types.

Reserve disjoint bit ranges

The pseudocode packs a 16-bit counter and 32-bit flags into a wider integer before storage. Widen the operands before shifting. For counter 65535 and flags 1, the packed integer should be 131071 and unpack to the exact original pair.

packed = uint16(counter) | (uint32(flags) << 16)
counter = packed & 0xffff
flags   = packed >> 16

Test zero values, the maximum of each field and mixed values. Compare unpack(pack(x)) with x and ensure the chosen packed type covers all used bits without field reduction or truncation. Implement the two conversions consistently in StorePacking.

Treat the layout as persistent data

Changing widths or field order changes how already stored slots decode. An upgrade needs a migration or an explicit versioned representation. Changing an ABI serializer alone cannot repair values written under an older packing scheme. starknet.io The Cairo Programming Language