Flashloan
function can be used to drain user funds.
When flashloan is called, it update the exchange rate, before sending the requested tokens to receiver contract. Requested contract will deposit the tokens using deposit
function, this will mint the asset tokens to receiver and update the exchange rate. Then Attacker can call redeem. By doing this (deposit and redeem) recursively, attacker will get enough asset tokens, using that he will be able to get more tokens that he deposited. Attacker repay the flashloan with fee and keep the extra amount. This gives attacker a incentive, which will cause user fund loss.
There are 3 users, liquidityProvider
, user
and alice
with having 100
, 100
and 20
tokens. Here AMOUNT = 10e18
First of all we mock liquidityProvider
, who deposit 10 tokens twice.
Then we mock user
who deposit 10
and 20
tokens in two transaction respectively.
Consider this 2nd transaction as flashloan
initialization, where exchange rate updates.
Assume these 20 tokens
are in receiver address, and alice
is receiver address
so it will keep depositing and redeeming it X times (here we used just 200 times).
he will be in profit, stats can be seen by using forge test --match-test testFlashLoanScenerio
PS- This is simplest example to demonstrate, actual values will be more profitable
User funds will be lost, they will be unable to claim there deposit.
Manual Review
Add a time delay b/w deposit and redeem, so it can't be exploited. Alternatively, minting asset tokens logic should be improved.
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.