EVM reads and writes in 32-byte (256-bit) slots. Variables smaller than 32 bytes that are declared consecutively share a slot, reducing SSTORE operations. A new SSTORE costs 20,000 gas; packing avoids additional slot allocations.
What to verify: Consecutive variables of the same or smaller combined size (≤32 bytes) are grouped together. Place uint128 next to uint128, not separated by a uint256.
Custom errors are encoded as 4-byte selectors, whereas revert strings store the full string in contract bytecode and in memory at runtime. Custom errors save gas on both deployment (smaller bytecode) and execution (cheaper encoding).
Gasoptimierungsmuster für Solidity Smart Contracts. Zur Optimierung der Vertragsbereitstellungskosten, des Gasverbrauchs zur Laufzeit oder der Speichereffizienz. Deckt Speicherpaketierung, benutzerdefinierte Fehler, unveränderliche Variablen, Aufrufdatenoptimierung, Schleifenmuster, Assembly-Nutzung und für Solady-Gas optimierte Alternativen ab. Wird bei Aufgaben ausgelöst, die Gasoptimierung, Speicherlayout, Reduzierung der Bereitstellungskosten oder EVM-Effizienz umfassen. Quelle: whackur/solidity-agent-toolkit.