Bird
Raised Fist0
Blockchain / Solidityprogramming~20 mins

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

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
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.

Practice

(1/5)
1. What is the main purpose of a cross-chain bridge in blockchain technology?
easy
A. To mine new blocks faster on a single blockchain
B. To increase the block size limit on a blockchain
C. To create new cryptocurrencies from scratch
D. To connect different blockchains and allow asset transfers between them

Solution

  1. Step 1: Understand the role of cross-chain bridges

    Cross-chain bridges enable communication and asset transfers between different blockchains.
  2. Step 2: Compare options with this role

    Only To connect different blockchains and allow asset transfers between them describes connecting blockchains and transferring assets, which matches the bridge's purpose.
  3. Final Answer:

    To connect different blockchains and allow asset transfers between them -> Option D
  4. Quick Check:

    Cross-chain bridge = connect blockchains [OK]
Hint: Bridges connect blockchains to move tokens or data [OK]
Common Mistakes:
  • Confusing bridges with mining or block creation
  • Thinking bridges create new cryptocurrencies
  • Assuming bridges only increase block size
2. Which of the following is the correct basic step in a cross-chain bridge operation?
easy
A. Lock tokens on the source chain and mint equivalent tokens on the destination chain
B. Mint tokens on the source chain and burn on the destination chain
C. Burn tokens on the source chain and mine new tokens on the same chain
D. Transfer tokens directly without locking or minting

Solution

  1. Step 1: Recall how cross-chain bridges work

    They lock tokens on the source chain to prevent double spending and mint equivalent tokens on the destination chain.
  2. Step 2: Match this with the options

    Lock tokens on the source chain and mint equivalent tokens on the destination chain correctly describes locking on source and minting on destination, which is the standard process.
  3. Final Answer:

    Lock tokens on the source chain and mint equivalent tokens on the destination chain -> Option A
  4. Quick Check:

    Lock then mint = bridge step [OK]
Hint: Tokens are locked first, then minted on another chain [OK]
Common Mistakes:
  • Mixing up minting and burning order
  • Thinking tokens transfer directly without locking
  • Assuming minting happens on source chain
3. Consider this simplified pseudocode for a cross-chain bridge function:
function bridgeTransfer(amount, sourceChain, destChain) {
  lockTokens(sourceChain, amount);
  mintTokens(destChain, amount);
  return 'Transfer complete';
}
What will be the output when calling bridgeTransfer(100, 'ChainA', 'ChainB')?
medium
A. 'Transfer complete'
B. Error: lockTokens undefined
C. 'Tokens locked on ChainA'
D. 100

Solution

  1. Step 1: Analyze the function steps

    The function calls lockTokens and mintTokens, then returns the string 'Transfer complete'.
  2. Step 2: Determine the output of the function call

    Assuming lockTokens and mintTokens work correctly, the function returns 'Transfer complete'.
  3. Final Answer:

    'Transfer complete' -> Option A
  4. Quick Check:

    Function returns 'Transfer complete' [OK]
Hint: Look at the return statement for output [OK]
Common Mistakes:
  • Confusing function calls with return value
  • Assuming intermediate functions print output
  • Ignoring the return statement
4. The following code snippet is intended to lock tokens on the source chain and mint on the destination chain, but it has a bug:
function bridgeTransfer(amount, sourceChain, destChain) {
  lockTokens(destChain, amount);
  mintTokens(sourceChain, amount);
  return 'Transfer complete';
}
What is the bug in this code?
medium
A. The function uses incorrect function names
B. The lockTokens and mintTokens calls have swapped chain arguments
C. The function does not return any value
D. The amount parameter is missing

Solution

  1. Step 1: Check the order of locking and minting

    Tokens should be locked on the source chain and minted on the destination chain.
  2. Step 2: Identify the argument mismatch

    The code locks tokens on destChain and mints on sourceChain, which is reversed.
  3. Final Answer:

    The lockTokens and mintTokens calls have swapped chain arguments -> Option B
  4. Quick Check:

    Lock on source, mint on destination [OK]
Hint: Lock on source chain, mint on destination chain [OK]
Common Mistakes:
  • Swapping source and destination chains
  • Forgetting to return a value
  • Using wrong function names
5. You want to design a cross-chain bridge that prevents double spending by ensuring tokens are locked before minting on the destination chain. Which approach best achieves this in a smart contract environment?
hard
A. Allow users to mint tokens on destination chain without locking on source chain
B. Mint tokens on destination chain first, then lock tokens on source chain
C. Use an event listener to confirm tokens are locked on source chain before minting on destination chain
D. Transfer tokens directly between chains without any locking or minting

Solution

  1. Step 1: Understand double spending prevention

    Tokens must be locked on the source chain before minting on the destination chain to avoid duplicates.
  2. Step 2: Evaluate approaches for enforcing this

    Using an event listener to confirm locking before minting ensures the correct order and security.
  3. Final Answer:

    Use an event listener to confirm tokens are locked on source chain before minting on destination chain -> Option C
  4. Quick Check:

    Confirm lock event before minting [OK]
Hint: Confirm lock event before minting tokens [OK]
Common Mistakes:
  • Minting before locking causes double spending
  • Allowing mint without lock breaks security
  • Skipping locking or minting steps