2. Naive receiver
Last updated
Last updated
Thereās a pool with 1000 ETH in balance, offering flash loans. It has a fixed fee of 1 ETH.
A user has deployed a contract with 10 ETH in balance. Itās capable of interacting with the pool and receiving flash loans of ETH.
Take all ETH out of the userās contract. If possible, in a single transaction.
We want to drain FlashLoanReceiver.sol
of its ETH.
It only has 2 functions, receiveEther() and receive()
receiveEther() is called by flashLoan() function on NaiveReceiverLenderPool
checks that msg.sender is pool
Notice that anyone can call flashLoan() function and pass a borrower address of choice
receiveEther() does not check originator of transaction
This means we can repeatedly call flashLoan(), passing the FlashLoanReceiver
address, draining the user's contract by repeatedly paying fees
The solution is to repeatedly call flashLoan() on naiveReceiverLenderPool, targetting flashLoanReceiver as the called of the flash loan.
We will achieve this with a while
loop.
calculate the remaining balance on the target contract, less the flash loan fee
take a flashout out with said balance
the user's balances are drained paying fees
while loop breaks when user's balance is 0.