Beginner FriendlyFoundryDeFiOracle
100 EXP
View results
Submission Details
Severity: high
Valid

The flashloan function is subject to reentrancy risks

Summary

The flashloan function is subject to reentrancy. The reason is because the exchange rate is updated (increasing it to account for the fees accrued during a flash loan) before the external call is made to MockFlashLoanReceiver.sol. There is also no need to call updateExchangeRate where it is called because it isn't used for the rest of the function.

Vulnerability Details

The relevant part of the flashloan function is here where updateExchangeRate is called before the external call is made:

assetToken.updateExchangeRate(fee);
emit FlashLoan(receiverAddress, token, amount, fee, params);
s_currentlyFlashLoaning[token] = true;
assetToken.transferUnderlyingTo(receiverAddress, amount);
// slither-disable-next-line unused-return reentrancy-vulnerabilities-2
receiverAddress.functionCall(
abi.encodeWithSignature(
"executeOperation(address,uint256,uint256,address,bytes)",
address(token),
amount,
fee,
msg.sender,
params
)
);

Impact

You open yourself up for a reentrancy attack which could drain funds. Granted this is mostly mitigated by the fact that there is a post check that the ending balance of the tokens in AssetToken.sol is not less than the starting balance plus the fee. But that check doesn't mean that an attacker couldn't figure out how to drive up their amount of asset tokens using flash loan but still return starting balance plus fee of underlying tokens and then withdraw more than their fair share of tokens afterward.

Tools Used

Manual review

Recommendations

Move the call to updateExchangeRate to the end of 'flashloan' or, better yet, as i suggested in another finding, don't use the concept of exchange rate to calculate how many tokens/asset tokens depositors get upon deposit and redemption because it is unnecessary complication.

Updates

Lead Judging Commences

0xnevi Lead Judge about 2 years ago
Submission Judgement Published
Validated
Assigned finding tags:

can't redeem because of the update exchange rate

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.