Gas Model
- Gas mechanics. Every opcode costs gas: the transaction pays computation, memory and storage as it goes.
- Storage dominates. SSTORE dominates cost: a storage write outweighs thousands of arithmetic ops.
- Refunds and zeroing. Zeroing storage earns partial refunds: cleanup priced into the protocol.
Storage and Execution Costs
- Packing and caching. Costs fall by packing slots and caching storage reads into memory locals.
- Calldata over memory. External inputs stay in calldata: the cheapest data location for read-only arguments.
- Batching. Batching amortises fixed overhead: one transaction settling many operations.
Optimising Without Sacrificing Safety
- Measure gas. Gas work starts with reports: per-function costs measured in the test suite, tracked per commit.
- Readability guard. An optimisation that obscures an invariant is a net loss: audits cost more than gas.
- Optimiser settings. The compiler optimiser tunes for deploy versus runtime cost: a setting chosen, not defaulted.
Before and after this level
- Before: Level 9: Smart Contract Security: Reentrancy and External Calls, Access and Economic Attacks, Secure Contract Patterns.
- Next: Level 11: Testing: Unit and Integration Tests, Fuzz and Invariant Testing, Testing Adversarial Conditions.
In the app each of these ideas is taught and then asked back, and the level ends with a checkpoint and flashcards. See Checkpoints and flashcards.
Frequently asked questions
What does Solidity Level 10: Gas & EVM Efficiency cover?
Gas Model, Storage and Execution Costs, Optimising Without Sacrificing Safety: 3 lessons and 9 ideas.
What should I know before this level?
The level before it, Level 9: Smart Contract Security, which covers Reentrancy and External Calls, Access and Economic Attacks, Secure Contract Patterns.