0
0
Blockchain / Solidityprogramming~20 mins

Flash loans in Blockchain / Solidity - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Flash Loan 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 Solidity flash loan example?
Consider this simplified Solidity code snippet for a flash loan. What will be the value of balanceAfter after the executeFlashLoan function runs successfully?
Blockchain / Solidity
contract FlashLoanExample {
    uint256 public balanceAfter;

    function executeFlashLoan(uint256 amount) external {
        uint256 balanceBefore = address(this).balance;
        // Simulate flash loan received
        uint256 loan = amount;
        // Use the loan for some operation (omitted)
        // Repay the loan
        balanceAfter = address(this).balance;
        require(balanceAfter >= balanceBefore, "Loan not repaid");
    }
}
AbalanceAfter is less than balanceBefore, causing the require to fail and revert.
BbalanceAfter is zero because the contract balance is reset after the function.
CbalanceAfter is greater than balanceBefore, indicating profit from the loan.
DbalanceAfter equals balanceBefore, meaning the loan was fully repaid.
Attempts:
2 left
💡 Hint
Think about what the require statement enforces about the contract's balance after the loan.
🧠 Conceptual
intermediate
1:30remaining
Why are flash loans considered risk-free for lenders?
Which of the following best explains why flash loans do not expose lenders to default risk?
ABecause the lender holds the borrower's private keys during the loan.
BBecause the loan is given only to trusted addresses with collateral.
CBecause the loan must be repaid within the same transaction or the whole transaction reverts.
DBecause the loan amount is always very small and insured by the protocol.
Attempts:
2 left
💡 Hint
Think about what happens if the borrower does not repay the loan in the same transaction.
🔧 Debug
advanced
2:30remaining
Identify the error in this flash loan repayment code snippet
This Solidity function attempts to repay a flash loan but causes a runtime error. What is the cause?
Blockchain / Solidity
function repayLoan(uint256 amount) external {
    // Attempt to repay loan
    (bool success, ) = lender.call{value: amount}();
    require(success, "Repayment failed");
}
AThe call is missing the function signature, so it sends plain Ether without calling repay function.
BThe amount variable is not declared, causing a compilation error.
CThe call should use transfer() instead of call() to send Ether.
DThe require statement is incorrectly placed after the call.
Attempts:
2 left
💡 Hint
Consider how low-level call works when sending Ether and invoking functions.
📝 Syntax
advanced
1:30remaining
Which option correctly defines a flash loan function in Solidity?
Select the option that correctly declares a flash loan function that takes a loan amount and a callback address.
Afunction flashLoan(uint256 amount, address callback) external { ... }
Bfunction flashLoan(uint amount, address callback) public returns (bool) { ... }
Cfunction flashLoan(uint256 amount, address callback) external payable { ... }
Dfunction flashLoan(uint256 amount, address callback) external view { ... }
Attempts:
2 left
💡 Hint
Remember that flash loan functions usually modify state and do not return values.
🚀 Application
expert
2:00remaining
How many external calls are made in this flash loan transaction?
Given this sequence in a flash loan transaction: 1. Borrower requests loan from lender contract. 2. Lender contract calls borrower's executeOperation function. 3. Borrower performs arbitrage and repays lender. How many external contract calls occur during this transaction?
A4
B2
C3
D1
Attempts:
2 left
💡 Hint
Count calls between different contracts, including lender to borrower and borrower to lender.