0
0
Blockchain / Solidityprogramming~20 mins

Staking mechanisms in Blockchain / Solidity - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Staking 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 staking reward calculation?

Consider a simple staking contract where rewards are calculated as 5% of the staked amount per epoch. What will be the total reward after 3 epochs if a user stakes 100 tokens?

Blockchain / Solidity
def calculate_rewards(staked_amount, epochs):
    reward_rate = 0.05
    total_reward = 0
    for _ in range(epochs):
        total_reward += staked_amount * reward_rate
    return total_reward

print(calculate_rewards(100, 3))
A15
B15.0
C10.5
D5
Attempts:
2 left
💡 Hint

Multiply the staked amount by the reward rate for each epoch and sum it up.

🧠 Conceptual
intermediate
1:30remaining
Which staking mechanism prevents double-spending by locking tokens?

In blockchain staking, which mechanism ensures tokens cannot be used for other transactions while staked?

ADelegation
BSlashing
CToken Locking
DYield Farming
Attempts:
2 left
💡 Hint

Think about what stops tokens from moving during staking.

🔧 Debug
advanced
2:00remaining
Identify the error in this staking reward function

The function below is intended to calculate compounded staking rewards per epoch. What error will it cause when run?

Blockchain / Solidity
def compounded_rewards(staked_amount, epochs, rate):
    total = staked_amount
    for _ in range(epochs):
        total = total + total * rate
    return total

print(compounded_rewards(100, 3, 0.05))
ATypeError because of wrong operator
BOutputs 115.7625 but should be 115.7625
CSyntaxError due to missing colon
DOutputs 115.7625
Attempts:
2 left
💡 Hint

Check if the formula correctly compounds the reward.

Predict Output
advanced
2:00remaining
What is the output of this delegation mapping code?

This code maps delegators to validators and sums total delegated tokens per validator. What is the output?

Blockchain / Solidity
delegations = [
    {'delegator': 'Alice', 'validator': 'Val1', 'amount': 50},
    {'delegator': 'Bob', 'validator': 'Val2', 'amount': 30},
    {'delegator': 'Charlie', 'validator': 'Val1', 'amount': 20},
    {'delegator': 'Dave', 'validator': 'Val3', 'amount': 40}
]

validator_totals = {}
for d in delegations:
    validator_totals[d['validator']] = validator_totals.get(d['validator'], 0) + d['amount']

print(validator_totals)
A{'Val1': 70, 'Val2': 30, 'Val3': 40}
B{'Val1': 50, 'Val2': 30, 'Val3': 40}
C{'Val1': 20, 'Val2': 30, 'Val3': 40}
D{'Val1': 70, 'Val2': 40, 'Val3': 30}
Attempts:
2 left
💡 Hint

Sum amounts for each validator key.

🧠 Conceptual
expert
1:30remaining
Which staking mechanism best balances security and liquidity?

Among these staking mechanisms, which one allows users to earn rewards while maintaining token liquidity?

ALiquid Staking
BCold Staking
CSlashing Mechanism
DLock-up Period Staking
Attempts:
2 left
💡 Hint

Think about staking that lets you trade or use tokens while still earning rewards.