Challenge - 5 Problems
Flash Loan Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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");
}
}Attempts:
2 left
💡 Hint
Think about what the require statement enforces about the contract's balance after the loan.
✗ Incorrect
The require statement ensures the contract's balance after the flash loan operation is at least the same as before, meaning the loan must be fully repaid within the transaction. Therefore, balanceAfter equals balanceBefore.
🧠 Conceptual
intermediate1: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?
Attempts:
2 left
💡 Hint
Think about what happens if the borrower does not repay the loan in the same transaction.
✗ Incorrect
Flash loans require the borrower to repay the loan within the same blockchain transaction. If repayment does not happen, the entire transaction is reverted, so the lender never loses funds.
🔧 Debug
advanced2: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");
}Attempts:
2 left
💡 Hint
Consider how low-level call works when sending Ether and invoking functions.
✗ Incorrect
Using call with only value sends Ether but does not specify which function to call on the lender contract. If the lender expects a function call to repay the loan, this will fail or not behave as intended.
📝 Syntax
advanced1: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.
Attempts:
2 left
💡 Hint
Remember that flash loan functions usually modify state and do not return values.
✗ Incorrect
The correct syntax uses uint256 for amount, external visibility, and no view modifier because the function changes state. It also does not return a value.
🚀 Application
expert2: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?
Attempts:
2 left
💡 Hint
Count calls between different contracts, including lender to borrower and borrower to lender.
✗ Incorrect
There are two external calls: lender calls borrower (executeOperation), and borrower calls lender to repay. The initial request is a transaction from an EOA, not a contract call.