0
0
Blockchain / Solidityprogramming~10 mins

Front-running awareness in Blockchain / Solidity - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to detect if a transaction is front-run by checking if the current gas price is higher than the previous one.

Blockchain / Solidity
if current_gas_price [1] previous_gas_price:
    print("Possible front-running detected")
Drag options to blanks, or click blank then click option'
A>
B<=
C==
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' causes the check to miss front-running.
Using '==' only checks equality, not increase.
2fill in blank
medium

Complete the code to add a delay before sending a transaction to reduce front-running risk.

Blockchain / Solidity
import time

time.[1](5)  # wait 5 seconds before sending transaction
Drag options to blanks, or click blank then click option'
Await
Bsleep
Cdelay
Dpause
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent functions like 'wait' or 'delay' causes errors.
Misspelling 'sleep' leads to runtime errors.
3fill in blank
hard

Fix the error in the code that tries to check if a transaction nonce is less than the last confirmed nonce.

Blockchain / Solidity
if tx_nonce [1] last_confirmed_nonce:
    print("Transaction might be front-run")
Drag options to blanks, or click blank then click option'
A<
B<=
C>
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>=' or '>' reverses the logic and misses front-running.
Using '<=' includes equal nonces which is not the intended check.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps transaction hashes to their gas prices only if the gas price is higher than 100 gwei.

Blockchain / Solidity
tx_gas_prices = {tx_hash: tx[1] for tx_hash, tx in transactions.items() if tx['gas_price'] [2] 100}
Drag options to blanks, or click blank then click option'
A['gas_price']
B>
C<
D['nonce']
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong key like 'nonce' instead of 'gas_price'.
Using '<' instead of '>' reverses the filter logic.
5fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps user addresses to their transaction counts only if the count is greater than 10.

Blockchain / Solidity
user_tx_counts = {user[1]: tx_count for user, tx_count in user_transactions.items() if tx_count [2] 10}
Drag options to blanks, or click blank then click option'
A.lower()
C>
D.upper()
Attempts:
3 left
💡 Hint
Common Mistakes
Leaving the user address unchanged may cause inconsistent keys.
Using '<' instead of '>' filters the wrong transaction counts.