0
0
Blockchain / Solidityprogramming~20 mins

Front-running awareness in Blockchain / Solidity - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Front-running Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Detecting front-running in a transaction log

Given a list of blockchain transactions with timestamps and prices, what is the output of the code that detects if a transaction was front-run?

Blockchain / Solidity
transactions = [
    {'tx_id': 'a1', 'timestamp': 100, 'price': 10},
    {'tx_id': 'b2', 'timestamp': 101, 'price': 12},
    {'tx_id': 'c3', 'timestamp': 102, 'price': 11}
]

front_run_detected = False
for i in range(1, len(transactions)):
    if transactions[i]['price'] < transactions[i-1]['price']:
        front_run_detected = True
        break
print(front_run_detected)
ATrue
BFalse
CSyntaxError
DIndexError
Attempts:
2 left
💡 Hint

Look for a price drop after a higher price transaction.

🧠 Conceptual
intermediate
1:30remaining
Understanding front-running impact on transaction ordering

Which statement best describes the impact of front-running on blockchain transaction ordering?

AFront-running removes transactions from the blockchain permanently.
BFront-running delays all transactions equally to maintain fairness.
CFront-running changes the order of transactions to benefit the attacker financially.
DFront-running encrypts transactions to hide their content.
Attempts:
2 left
💡 Hint

Think about how attackers gain advantage by reordering.

🔧 Debug
advanced
2:30remaining
Identify the error causing incorrect front-running detection

Why does the following code fail to detect front-running correctly?

Blockchain / Solidity
txs = [{'id': 'x1', 'price': 5}, {'id': 'x2', 'price': 7}, {'id': 'x3', 'price': 6}]

front_run = False
for i in range(len(txs)):
    if txs[i]['price'] < txs[i-1]['price']:
        front_run = True
        break
print(front_run)
AThe list txs is empty, so the loop never runs.
BThe price comparison uses '<' instead of '>' causing logic error.
CThe variable front_run is never updated inside the loop.
DThe loop starts at 0, so txs[i-1] is invalid on first iteration causing wrong comparison.
Attempts:
2 left
💡 Hint

Check the index used in the loop and how it accesses previous elements.

📝 Syntax
advanced
1:30remaining
Identify the syntax error in front-running detection code

Which option contains the syntax error preventing the code from running?

Blockchain / Solidity
def detect_front_run(txs):
    for i in range(1, len(txs))
        if txs[i]['price'] < txs[i-1]['price']:
            return True
    return False
AMissing colon ':' after for loop declaration.
BMissing parentheses in function call range len(txs).
CIncorrect indentation of return statements.
DUsing single quotes instead of double quotes in dictionary keys.
Attempts:
2 left
💡 Hint

Look carefully at the for loop syntax.

🚀 Application
expert
3:00remaining
Calculate number of front-run opportunities in transaction batch

Given a batch of transactions with prices, how many front-run opportunities exist where a transaction is immediately followed by a lower price?

Blockchain / Solidity
transactions = [
    {'tx_id': 't1', 'price': 20},
    {'tx_id': 't2', 'price': 25},
    {'tx_id': 't3', 'price': 22},
    {'tx_id': 't4', 'price': 30},
    {'tx_id': 't5', 'price': 28}
]

count = 0
for i in range(1, len(transactions)):
    if transactions[i]['price'] < transactions[i-1]['price']:
        count += 1
print(count)
A3
B2
C1
D0
Attempts:
2 left
💡 Hint

Count how many times price drops compared to previous transaction.