0
0
Blockchain / Solidityprogramming~20 mins

Cross-chain bridges in Blockchain / Solidity - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Cross-chain Bridge Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of a simple cross-chain token lock function
What is the output of this Solidity function when called with amount = 100 and sender balance = 150?
Blockchain / Solidity
mapping(address => uint256) balances;

function lockTokens(uint256 amount) public returns (string memory) {
    require(balances[msg.sender] >= amount, "Insufficient balance");
    balances[msg.sender] -= amount;
    // Tokens locked for cross-chain transfer
    return "Tokens locked";
}

// Assume balances[msg.sender] = 150 before call
A"Tokens locked"
B"Insufficient balance"
CRevert with error "Insufficient balance"
D"Tokens unlocked"
Attempts:
2 left
💡 Hint
Check the require condition and the initial balance.
🧠 Conceptual
intermediate
1:30remaining
Understanding cross-chain message verification
Which of the following best describes the role of a relayer in a cross-chain bridge?
AA relayer mints new tokens on the source chain without verification.
BA relayer verifies and submits proofs of events from one chain to another to enable token transfers.
CA relayer stores user private keys to sign transactions on their behalf.
DA relayer directly modifies the consensus rules of the destination chain.
Attempts:
2 left
💡 Hint
Think about how information is passed securely between chains.
🔧 Debug
advanced
2:30remaining
Identify the error in cross-chain token minting code
What error will this Solidity code produce when mintTokens is called without proper verification?
Blockchain / Solidity
mapping(address => uint256) public balances;

function mintTokens(address to, uint256 amount) public {
    // Missing verification of cross-chain proof
    balances[to] += amount;
}
ANo error, tokens minted successfully
BRevert due to missing proof verification
CPotential double minting vulnerability (logical error, no revert)
DCompilation error due to missing visibility on balances
Attempts:
2 left
💡 Hint
Consider security implications of minting without checks.
📝 Syntax
advanced
1:30remaining
Syntax error in cross-chain event emission
Which option correctly fixes the syntax error in this Solidity event emission code?
Blockchain / Solidity
event TransferLocked(address indexed sender, uint256 amount);

function lock(uint256 amount) public {
    emit TransferLocked(msg.sender, amount)
}
AReplace emit with call: call TransferLocked(msg.sender, amount);
BChange event name to transferLocked without uppercase letters
CRemove the indexed keyword from the event declaration
DAdd a semicolon after the emit statement: emit TransferLocked(msg.sender, amount);
Attempts:
2 left
💡 Hint
Check the end of the emit statement.
🚀 Application
expert
2:00remaining
Calculate the number of confirmations needed for secure cross-chain transfer
A cross-chain bridge requires 12 confirmations on the source chain before releasing tokens on the destination chain. If blocks are produced every 15 seconds, how long in minutes does a user wait before tokens are released?
A3 minutes
B12 minutes
C180 minutes
D30 minutes
Attempts:
2 left
💡 Hint
Multiply confirmations by block time, then convert seconds to minutes.