Bird
Raised Fist0
Blockchain / Solidityprogramming~20 mins

Ethereum Virtual Machine (EVM) in Blockchain / Solidity - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
EVM Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
1:30remaining
EVM Stack Behavior on PUSH and ADD
What is the final value on top of the EVM stack after executing these instructions?

PUSH1 0x03
PUSH1 0x05
ADD
Blockchain / Solidity
PUSH1 0x03
PUSH1 0x05
ADD
A0x08
B0x15
C0x02
D0x53
Attempts:
2 left
💡 Hint
Remember that ADD pops two values and pushes their sum.
🧠 Conceptual
intermediate
1:30remaining
Gas Cost for SSTORE Operation
Which of the following best describes the gas cost behavior of the SSTORE operation in the EVM?
ASSTORE always costs a fixed 20,000 gas regardless of the storage state.
BSSTORE costs more gas when changing a storage slot from zero to non-zero than from non-zero to zero.
CSSTORE costs less gas when changing a storage slot from zero to non-zero than from non-zero to zero.
DSSTORE gas cost is always refunded fully after execution.
Attempts:
2 left
💡 Hint
Think about how storage writes affect blockchain state and refunds.
🔧 Debug
advanced
1:30remaining
Identify the Error in EVM Bytecode Sequence
Given this EVM bytecode sequence, what error will occur during execution?

PUSH1 0x01
ADD
Blockchain / Solidity
PUSH1 0x01
ADD
ANo error, outputs 0x01
BOut of gas error
CInvalid opcode error
DStack underflow error
Attempts:
2 left
💡 Hint
ADD requires two values on the stack to operate.
📝 Syntax
advanced
1:30remaining
Correct EVM Assembly for Conditional Jump
Which EVM assembly code correctly performs a conditional jump to label 'loop' if the top stack value is non-zero?
A
PUSH1 loop
JUMPI
B
JUMPI
PUSH1 loop
C
PUSH1 loop
JUMP
D
PUSH1 0x00
JUMPI
Attempts:
2 left
💡 Hint
JUMPI expects the destination and condition on the stack.
🚀 Application
expert
2:00remaining
Calculate Final Gas After Execution
A contract execution starts with 100,000 gas. It performs:
- 3 SSTORE operations changing zero to non-zero
- 2 SSTORE operations changing non-zero to zero
- 10 ADD operations

Given:
- SSTORE zero->non-zero costs 20,000 gas each
- SSTORE non-zero->zero costs 5,000 gas each and refunds 15,000 gas each
- ADD costs 3 gas each

What is the final gas left after execution (ignoring other costs and refunds)?
A50,000 gas
B40,000 gas
C55,000 gas
D35,000 gas
Attempts:
2 left
💡 Hint
Calculate total cost, then subtract refunds from gas used.

Practice

(1/5)
1. What is the main role of the Ethereum Virtual Machine (EVM) in the Ethereum network?
easy
A. It executes smart contract bytecode to run decentralized applications.
B. It stores user account balances and transaction history.
C. It mines new Ethereum blocks using proof of work.
D. It manages the Ethereum wallet user interface.

Solution

  1. Step 1: Understand EVM's purpose

    The EVM is a virtual computer that runs smart contracts on Ethereum.
  2. Step 2: Identify correct role

    It executes compiled bytecode from smart contracts, enabling decentralized apps to run safely and consistently.
  3. Final Answer:

    It executes smart contract bytecode to run decentralized applications. -> Option A
  4. Quick Check:

    EVM runs smart contracts = B [OK]
Hint: EVM runs code, not stores or mines [OK]
Common Mistakes:
  • Confusing EVM with blockchain storage
  • Thinking EVM mines blocks
  • Mixing EVM with wallet software
2. Which of the following is the correct way to represent a simple EVM instruction to add two numbers?
easy
A. ADD 5 3
B. PUSH1 5 PUSH1 3 ADD
C. LOAD 5 3 ADD
D. SUM 5 3

Solution

  1. Step 1: Recall EVM instruction format

    EVM uses stack operations like PUSH1 to push values, then ADD to add top stack items.
  2. Step 2: Identify correct instruction sequence

    "PUSH1 5 PUSH1 3 ADD" pushes 5 and 3, then adds them on the stack.
  3. Final Answer:

    PUSH1 5 PUSH1 3 ADD -> Option B
  4. Quick Check:

    Push values then add = C [OK]
Hint: EVM uses PUSH and then operation instructions [OK]
Common Mistakes:
  • Using invalid instructions like ADD 5 3 directly
  • Confusing LOAD with PUSH
  • Using non-EVM commands like SUM
3. Given this EVM bytecode snippet:
PUSH1 0x02
PUSH1 0x03
ADD

What is the result on the stack after execution?
medium
A. 0x05
B. 0x06
C. 0x23
D. 0x00

Solution

  1. Step 1: Understand PUSH1 and ADD operations

    PUSH1 0x02 pushes 2, PUSH1 0x03 pushes 3, ADD adds top two stack values.
  2. Step 2: Calculate addition result

    2 + 3 = 5, so 0x05 remains on the stack.
  3. Final Answer:

    0x05 -> Option A
  4. Quick Check:

    2 + 3 = 5 = 0x05 [OK]
Hint: Add pushed hex values on stack [OK]
Common Mistakes:
  • Adding hex as strings instead of numbers
  • Confusing 0x02 + 0x03 as 0x06
  • Misreading PUSH1 as PUSH2
4. Identify the error in this EVM bytecode sequence:
PUSH1 0x01
ADD
medium
A. No error; code is correct.
B. PUSH1 opcode is invalid.
C. ADD cannot be used after PUSH1.
D. Missing second operand on stack for ADD instruction.

Solution

  1. Step 1: Check stack before ADD

    PUSH1 0x01 pushes one value, but ADD needs two values on stack.
  2. Step 2: Identify missing operand

    Since only one value is pushed, ADD causes stack underflow error.
  3. Final Answer:

    Missing second operand on stack for ADD instruction. -> Option D
  4. Quick Check:

    ADD needs two stack values [OK]
Hint: ADD requires two values on stack [OK]
Common Mistakes:
  • Assuming ADD works with one operand
  • Thinking PUSH1 is invalid
  • Believing code is correct as is
5. You want to write an EVM bytecode sequence that calculates (4 + 5) * 3. Which sequence correctly achieves this?
hard
A. PUSH1 0x03 PUSH1 0x04 ADD PUSH1 0x05 MUL
B. PUSH1 0x04 PUSH1 0x05 MUL PUSH1 0x03 ADD
C. PUSH1 0x04 PUSH1 0x05 ADD PUSH1 0x03 MUL
D. PUSH1 0x04 PUSH1 0x03 MUL PUSH1 0x05 ADD

Solution

  1. Step 1: Understand operation order

    (4 + 5) * 3 means add 4 and 5 first, then multiply by 3.
  2. Step 2: Match EVM instructions to operations

    PUSH1 0x04 PUSH1 0x05 ADD pushes 4 and 5, adds them; then PUSH1 0x03 MUL multiplies result by 3.
  3. Step 3: Check other options

    Options B, C, and D change operation order or operands, producing incorrect results (B: 23, C: 35, D: 17).
  4. Final Answer:

    PUSH1 0x04 PUSH1 0x05 ADD PUSH1 0x03 MUL -> Option C
  5. Quick Check:

    Add then multiply = A [OK]
Hint: Add first, then multiply in EVM code [OK]
Common Mistakes:
  • Changing operation order incorrectly
  • Confusing MUL and ADD positions
  • Ignoring operator precedence
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard