๐ From Solidity to Bytecode: How Code Runs
Understand compilation, opcodes, and how the EVM executes instructions
Your Progress
0 / 5 completedโ
Previous
Introduction
โ๏ธ How EVM Works
EVM executes smart contracts step-by-step using bytecode instructions (opcodes). Let's watch a simple contract add two numbers and save the result!
๐ฎ Interactive: EVM Execution Simulator
Step through a simple smart contract that adds 5 + 3 and stores the result
Step 1 of 7
Gas Remaining: 21,000
START
Smart contract execution begins
STACK (LIFO)
Empty
MEMORY (Temporary)
Empty
STORAGE (Permanent)
Empty
๐ The Execution Process
1๏ธโฃ
Solidity โ Bytecode
Your Solidity code is compiled to bytecode (hex):
60056003016000552๏ธโฃ
Deploy to Blockchain
Bytecode is stored at a contract address. Every node has a copy of this code.
3๏ธโฃ
Call Contract Function
User sends transaction โ EVM loads bytecode โ executes opcodes one by one.
4๏ธโฃ
State Changes
Storage updates are written to blockchain. All nodes update their state identically.
5๏ธโฃ
Consensus
Miners/validators verify execution matches. If all agree, changes are permanent.
๐ค Common EVM Opcodes
PUSH / POP
Add/remove values from stack. PUSH1 0x05 pushes 5.
ADD / SUB / MUL / DIV
Arithmetic operations. Pop two values, push result.
SLOAD / SSTORE
Load from or store to permanent blockchain storage.
CALL / DELEGATECALL
Call another contract's function. DELEGATECALL uses caller's context.
JUMPI
Conditional jump (if statement). Jump to bytecode position.
REVERT
Undo all changes and return error. Used in require() statements.
๐ง Why Stack-Based?
โ
Simple & Efficient
Stack operations are fast. Push, pop, operateโminimal overhead. Perfect for deterministic execution.
โ
Easy to Verify
Every node can execute the same stack operations and get identical results. Critical for consensus.
โ
Compact Bytecode
Stack instructions are small. Less data to store on blockchain = lower costs.
๐ก Real Example: Token Transfer
// Solidity
balances[to] += amount;
balances[from] -= amount;
balances[from] -= amount;
// EVM Bytecode Operations
1. SLOAD balances[from] โ load sender balance
2. PUSH amount โ push transfer amount
3. SUB โ subtract amount from balance
4. SSTORE balances[from] โ save new balance
5. SLOAD balances[to] โ load receiver balance
6. PUSH amount โ push transfer amount
7. ADD โ add amount to balance
8. SSTORE balances[to] โ save new balance