An attacker can repay the loan by calling the ThunderLoan::deposit
function during the flash loan execution, acquiring asset tokens. These asset tokens are then redeemed for the underlying tokens, allowing the attacker to drain all deposited tokens.
The attacker contract exploits the balance check of the ThunderLoan::flashloan
function by deploying a malicious flash loan receiver contract that will use the borrowed tokens to call ThunderLoan::deposit
and get asset tokens to redeem for the underlying tokens. Any liquidity provider holding asset tokens won't be able to redeem them after the attack.
Attacker: A user who owns a malicious receiver contract.
Victim: A liquidity provider who deposits tokens.
Protocol: ThunderLoan protocol, its flashLoan
function checks the token balance before and after the flash loan, allowing the attacker to repay the loan by calling the deposit
function to deposit the borrowed amount + fee, getting asset tokens as result.
Copy paste the following function into ThunderLoanTest.t.sol::ThunderLoanTest
Copy paste the following code into ThunderLoanTest.t.sol
Copy paste the test function into ThunderLoanTest.t.sol::ThunderLoanTest
Copy paste the malicious contract into ThunderLoanTest.t.sol
Run forge test --mt testMaliciousFlashLoanReceiverCanDrainTokenBalance -vv
in the terminal
The liquidity providers can't redeem their asset tokens.
Foundry
Change the way in which repayment check in ThunderLoan::flashloan
function is made:
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.