EVM Deep Dives: The Path to Shadowy Super Coder 🥷 💻 - Part 3

✅ Storage is an immutable data location

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

Convert sol unit

Storage Fundamentals

A high-level overview of storage fundamentals has been done brilliantly in this  “Program the Blockchain” post

Data Structure

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.

Untitled

Fixed Size Variables

contract StorageTest {
		uint256 value1;
		uint256[2] value2;
		uint256 value3;
}

Untitled


Slot Packing

contract StorageTest {
		uint32 **value1**;
		uint32 **value2**;
		uint64 **value3**;
		uint128 **value4**;
}

Untitled

■■■■ ■■■■ ■■■■■■■■ ■■■■■■■■■■■■■■■■ (32) ■■■■ ■■■■ ■■■■■■■■ ■■■■■■■■■■■■■■■■ (32)

←——————— 1 slot ——————→

■■■■ = 4bytes = 8hex = 32bits

the max value = 0xffffffff


EVM Storage Opcodes

SSTORE: store the 32-byte value in the storage

SLOAD: get the 32-byte value from the storage