The `flashloan()` function has reentrancy concerns identified by Slither. The exchange rate is updated before external calls, and state variables are modified after external calls. While the current implementation may be safe due to the checks at the end, the order of operations creates potential reentrancy risks that could be exploited if combined with other vulnerabilities.
The `flashloan()` function updates state and makes external calls in an order that creates reentrancy concerns:
```solidity
function flashloan(address receiverAddress, IERC20 token, uint256 amount, bytes calldata params) external {
// ... checks ...
uint256 fee = getCalculatedFee(token, amount);
assetToken.updateExchangeRate(fee); *// @> State updated (exchange rate)*
emit FlashLoan(receiverAddress, token, amount, fee, params);
s_currentlyFlashLoaning[token] = true; // @> State updated
assetToken.transferUnderlyingTo(receiverAddress, amount); *// @> External call*
receiverAddress.functionCall(...); *// @> External call (can reenter)*
uint256 endingBalance = token.balanceOf(address(assetToken));
if (endingBalance < startingBalance + fee) {
revert ThunderLoan__NotPaidBack(startingBalance + fee, endingBalance);
}
s_currentlyFlashLoaning[token] = false; // @> State updated after external calls
}
```
The function:
1. Updates exchange rate before external calls
2. Makes external calls to the receiver
3. Updates state after external calls
If the receiver can reenter `flashloan()` before the first call completes, it could potentially exploit the updated exchange rate or the `s_currentlyFlashLoaning` flag.
Likelihood:
* This occurs on every flash loan transaction
* While the current checks prevent most reentrancy issues, the order of operations is not following the checks-effects-interactions pattern
* If combined with other vulnerabilities (like the exchange rate update issues), could be exploited
Impact:
* Potential for reentrancy attacks if combined with other vulnerabilities
* Exchange rate could be manipulated through reentrant calls
* Could lead to incorrect accounting or loss of funds
* The `s_currentlyFlashLoaning` flag might not properly prevent reentrancy in all cases
The contest is live. Earn rewards by submitting a finding.
Submissions are being reviewed by our AI judge. Results will be available in a few minutes.
View all submissionsThe contest is complete and the rewards are being distributed.