EVM Deep Dives: The Path to Shadowy Super Coder 🥷 💻 - Part 3
knowledge of slot packing is vital for EVM hackers
If you cannot understand the relationships with bytes, hex, and bit, you have to read this article
A high-level overview of storage fundamentals has been done brilliantly in this “Program the Blockchain” post
Contract storage is simply a key to value mapping. It maps a 32-byte key to a 32-byte value. Given our key is 32 bytes in size we can have a maximum of (2^256)-1 keys.
contract StorageTest {
uint256 value1;
uint256[2] value2;
uint256 value3;
}
contract StorageTest {
uint32 **value1**;
uint32 **value2**;
uint64 **value3**;
uint128 **value4**;
}
■■■■ ■■■■ ■■■■■■■■ ■■■■■■■■■■■■■■■■ (32) ■■■■ ■■■■ ■■■■■■■■ ■■■■■■■■■■■■■■■■ (32)
←——————— 1 slot ——————→
■■■■ = 4bytes = 8hex = 32bits
the max value = 0xffffffff
SSTORE: store the 32-byte value in the storage
SLOAD: get the 32-byte value from the storage