Bird
Raised Fist0
Blockchain / Solidityprogramming~20 mins

Proof of Work vs Proof of Stake in Blockchain / Solidity - Practice Questions

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Consensus Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the output of this Proof of Work simulation code?

Consider this simplified Python code simulating a Proof of Work mining attempt. What will it print?

Blockchain / Solidity
import hashlib

def proof_of_work(data, difficulty):
    nonce = 0
    prefix = '0' * difficulty
    while True:
        text = f'{data}{nonce}'
        hash_result = hashlib.sha256(text.encode()).hexdigest()
        if hash_result.startswith(prefix):
            return nonce, hash_result
        nonce += 1

nonce, hash_val = proof_of_work('block', 2)
print(nonce, hash_val[:4])
AIt depends on the machine speed and may vary
B5 00c1
C0 00ab
D12 00f3
Attempts:
2 left
💡 Hint

The nonce is found by trial and error to get a hash starting with two zeros. This depends on the hash function output and cannot be predicted exactly.

🧠 Conceptual
intermediate
1:30remaining
Which statement correctly describes Proof of Stake?

Choose the correct description of how Proof of Stake (PoS) consensus works in blockchain.

ATransactions are validated by solving cryptographic puzzles faster than others.
BBlocks are created randomly without any stake or resource requirement.
CMiners solve complex puzzles to validate transactions and create blocks.
DValidators are chosen based on the amount of cryptocurrency they hold and lock up.
Attempts:
2 left
💡 Hint

Think about how PoS selects who creates the next block based on ownership rather than computational work.

🔧 Debug
advanced
2:00remaining
Why does this Proof of Work code raise an error?

Identify the error in this Proof of Work Python code snippet and what error it raises.

Blockchain / Solidity
import hashlib

def pow(data, difficulty):
    nonce = 0
    prefix = '0' * difficulty
    while True:
        text = f'{data}{nonce}'
        hash_val = hashlib.sha256(text.encode()).hexdigest()
        if hash_val.startswith(prefix):
            return nonce
        nonce += 1

pow('block', 3)
ASyntaxError due to missing colon after while True
BTypeError because prefix is not a string
CNameError because hashlib is not imported
DRuntimeError due to infinite loop
Attempts:
2 left
💡 Hint

Check the syntax of the while loop line carefully.

❓ Predict Output
advanced
1:30remaining
What is the output of this Proof of Stake validator selection code?

This Python code simulates selecting a validator based on stake weights. What does it print?

Blockchain / Solidity
import random

validators = {'Alice': 50, 'Bob': 30, 'Carol': 20}

random.seed(1)
choices = list(validators.keys())
weights = list(validators.values())
selected = random.choices(choices, weights=weights, k=1)[0]
print(selected)
ABob
BAlice
CCarol
DRandom selection with equal chance for all
Attempts:
2 left
💡 Hint

random.choices with weights picks based on stake amounts.

🧠 Conceptual
expert
1:30remaining
Which is a key difference between Proof of Work and Proof of Stake?

Select the statement that best highlights a fundamental difference between Proof of Work (PoW) and Proof of Stake (PoS) consensus mechanisms.

APoW is energy efficient; PoS consumes large amounts of electricity.
BPoW uses stake to select validators; PoS uses mining hardware to solve puzzles.
CPoW requires validators to solve puzzles using computational power; PoS selects validators based on their cryptocurrency holdings.
DPoW validators are chosen randomly; PoS validators compete to solve cryptographic puzzles.
Attempts:
2 left
💡 Hint

Think about what resource each consensus mechanism uses to secure the network.

Practice

(1/5)
1. Which of the following best describes how Proof of Work (PoW) secures a blockchain?
easy
A. Users vote to approve each new block.
B. Validators are randomly chosen based on coin ownership.
C. Blocks are added by the oldest node in the network.
D. Miners solve complex puzzles using computing power to add blocks.

Solution

  1. Step 1: Understand Proof of Work mechanism

    Proof of Work requires miners to solve difficult puzzles using computing power to find a valid block.
  2. Step 2: Compare options with PoW concept

    Only Miners solve complex puzzles using computing power to add blocks. correctly describes miners solving puzzles with computing power.
  3. Final Answer:

    Miners solve complex puzzles using computing power to add blocks. -> Option D
  4. Quick Check:

    Proof of Work = computing puzzles solved by miners [OK]
Hint: PoW means solving puzzles with power, not random choice. [OK]
Common Mistakes:
  • Confusing PoW with random validator selection.
  • Thinking PoW uses voting instead of computing power.
  • Assuming oldest node adds blocks in PoW.
2. Which syntax correctly represents a simple check for a Proof of Stake validator selection in pseudocode?
easy
A. if (random() < stake_percentage) { validateBlock(); }
B. while (computePower > threshold) { mineBlock(); }
C. for (node in network) { if (node.age > 10) { addBlock(); } }
D. if (votes > 50%) { approveBlock(); }

Solution

  1. Step 1: Identify Proof of Stake selection logic

    Proof of Stake selects validators based on stake percentage, often modeled as a probability check.
  2. Step 2: Match pseudocode to PoS logic

    if (random() < stake_percentage) { validateBlock(); } uses a random check against stake percentage, matching PoS validator selection.
  3. Final Answer:

    if (random() < stake_percentage) { validateBlock(); } -> Option A
  4. Quick Check:

    PoS validator selection uses stake-based probability [OK]
Hint: PoS uses stake chance, so random() < stake_percentage fits. [OK]
Common Mistakes:
  • Choosing mining loop which is PoW, not PoS.
  • Confusing age-based or vote-based logic with PoS.
  • Ignoring stake percentage in validator selection.
3. Given this pseudocode for a simplified blockchain consensus:
stake = {"Alice": 30, "Bob": 70}
random_value = 65
if random_value < stake["Alice"]:
    validator = "Alice"
else:
    validator = "Bob"
print(validator)
What will be the output?
medium
A. Alice
B. Bob
C. Error
D. None

Solution

  1. Step 1: Compare random_value with Alice's stake

    random_value is 65, Alice's stake is 30, so 65 < 30 is false.
  2. Step 2: Determine validator based on condition

    Since condition is false, validator is set to "Bob" and printed.
  3. Final Answer:

    Bob -> Option B
  4. Quick Check:

    65 < 30 is false, so validator = Bob [OK]
Hint: Check if random_value is less than stake to pick validator. [OK]
Common Mistakes:
  • Assuming 65 < 30 is true.
  • Confusing stake values or variable names.
  • Expecting syntax error from pseudocode.
4. This pseudocode tries to simulate Proof of Work mining but has an error:
nonce = 0
while nonce < 5:
    if hash(nonce) == target:
        print("Block mined")
    nonce += 1
What is the main problem here?
medium
A. The print statement is inside the if but no break after mining.
B. The loop never stops because nonce is never updated.
C. The hash function is not defined.
D. The nonce increment is outside the loop.

Solution

  1. Step 1: Analyze loop and mining condition

    The loop increments nonce correctly and stops at 5, so no infinite loop.
  2. Step 2: Check mining success handling

    When hash(nonce) == target, it prints "Block mined" but continues looping without stopping.
  3. Step 3: Identify missing break after mining

    Without break, it may print multiple times or waste resources after mining success.
  4. Final Answer:

    The print statement is inside the if but no break after mining. -> Option A
  5. Quick Check:

    Missing break after mining causes extra loops [OK]
Hint: Stop loop after mining success with break to avoid extra work. [OK]
Common Mistakes:
  • Thinking nonce is not incremented.
  • Assuming infinite loop due to missing increment.
  • Ignoring need to stop after mining success.
5. You want to design a hybrid blockchain consensus that uses Proof of Stake to select a validator and then Proof of Work to confirm the block. Which approach correctly combines both?
hard
A. All nodes solve PoW puzzles, then highest stake node adds block.
B. Random node adds block, then stake holders vote to confirm.
C. Select validator based on stake, then validator solves PoW puzzle to add block.
D. Validators solve PoW puzzles, but stake is ignored.

Solution

  1. Step 1: Understand hybrid consensus design

    Hybrid means combining PoS for validator selection and PoW for block confirmation.
  2. Step 2: Match options to hybrid logic

    Select validator based on stake, then validator solves PoW puzzle to add block. selects validator by stake, then that validator does PoW mining, fitting hybrid design.
  3. Step 3: Eliminate incorrect options

    Options A, C, D either ignore stake or PoW or mix steps incorrectly.
  4. Final Answer:

    Select validator based on stake, then validator solves PoW puzzle to add block. -> Option C
  5. Quick Check:

    Hybrid = PoS select + PoW mining [OK]
Hint: Hybrid = stake picks validator, then PoW confirms block. [OK]
Common Mistakes:
  • Ignoring PoW after validator selection.
  • Assuming all nodes mine in hybrid.
  • Confusing voting with PoW confirmation.
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