0
0
Blockchain / Solidityprogramming~10 mins

Ethereum Virtual Machine (EVM) in Blockchain / Solidity - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Ethereum Virtual Machine (EVM)
Start Transaction
Fetch Contract Bytecode
Initialize EVM Environment
Execute Bytecode Instructions
Update State & Storage
Return Output or Error
End
The EVM takes a transaction, loads contract code, runs instructions step-by-step, updates blockchain state, and returns results.
Execution Sample
Blockchain / Solidity
PUSH1 0x60
PUSH1 0x40
MSTORE
CALLVALUE
DUP1
ISZERO
PUSH2 0x0010
JUMPI
This EVM bytecode sets up memory, checks if any ether was sent, and conditionally jumps based on that.
Execution Table
StepInstructionStack BeforeStack AfterMemory ChangesProgram CounterNotes
1PUSH1 0x60[][0x60]No change1Push 0x60 onto stack
2PUSH1 0x40[0x60][0x40, 0x60]No change2Push 0x40 onto stack
3MSTORE[0x40, 0x60][]Memory[0x40..0x5f] = 0x603Store 0x60 at memory offset 0x40
4CALLVALUE[][0x00]No change4Push call value (0 ether) onto stack
5DUP1[0x00][0x00, 0x00]No change5Duplicate top stack item
6ISZERO[0x00, 0x00][0x01, 0x00]No change6Check if top is zero, push 1 (true)
7PUSH2 0x0010[0x01, 0x00][0x0010, 0x01, 0x00]No change7Push jump destination 0x10
8JUMPI[0x0010, 0x01, 0x00][0x00]No change8Jump to 0x10 because condition is true
9End[0x00][0x00]No changeEndExecution jumps to 0x10 or ends
💡 Execution ends after jump or reaching end of bytecode
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4After Step 5After Step 6After Step 7After Step 8Final
Stack[][0x60][0x40, 0x60][][0x00][0x00, 0x00][0x01, 0x00][0x0010, 0x01, 0x00][0x00][0x00]
Memoryemptyemptyempty0x40:0x60 stored0x40:0x60 stored0x40:0x60 stored0x40:0x60 stored0x40:0x60 stored0x40:0x60 stored0x40:0x60 stored
Program Counter012345678End
Key Moments - 3 Insights
Why does the stack get emptied after MSTORE at step 3?
MSTORE consumes two items from the stack (offset and value) to store in memory, so both are removed, leaving the stack empty as shown in execution_table row 3.
How does JUMPI decide to jump or not?
JUMPI checks the top stack item as a condition; if it's nonzero (true), it jumps to the address below it on the stack. Here, at step 8, condition is 1 (true), so it jumps.
What does CALLVALUE push onto the stack?
CALLVALUE pushes the amount of ether sent with the call. In this example, it's 0, so 0x00 is pushed at step 4.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 6. What is the stack after ISZERO executes?
A[]
B[0x00, 0x00]
C[0x01, 0x00]
D[0x0010, 0x01]
💡 Hint
Check the 'Stack After' column for step 6 in the execution_table.
At which step does the memory get updated with the value 0x60?
AStep 2
BStep 3
CStep 4
DStep 5
💡 Hint
Look at the 'Memory Changes' column in the execution_table.
If CALLVALUE pushed 0x05 instead of 0x00, what would be the stack after ISZERO at step 6?
A[0x00, 0x05]
B[0x01]
C[0x00, 0x00]
D[0x00]
💡 Hint
ISZERO pushes 1 if input is zero, else 0; check variable_tracker for CALLVALUE value.
Concept Snapshot
Ethereum Virtual Machine (EVM) executes smart contract bytecode step-by-step.
It uses a stack for operations and memory/storage for data.
Instructions manipulate stack, memory, and program counter.
JUMPI conditionally jumps based on stack top.
CALLVALUE pushes sent ether amount.
MSTORE stores data in memory at given offset.
Full Transcript
The Ethereum Virtual Machine (EVM) runs smart contract code by reading bytecode instructions one by one. It uses a stack to hold temporary values and memory to store data during execution. For example, PUSH1 adds a value to the stack, MSTORE saves a value from the stack into memory, and CALLVALUE pushes the amount of ether sent with the transaction. The program counter moves through instructions, and JUMPI can jump to a different instruction if a condition on the stack is true. This step-by-step process updates the blockchain state or returns output. The execution table shows how the stack and memory change after each instruction, helping beginners see exactly what happens inside the EVM.