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

Reentrancy in flashloan function

Summary

This piece of code allows an external contract to execute an arbitrary operation before the flash loan is paid back.

Vulnerability Details

This piece of code allows an arbitrary external contract (receiverAddress) to execute an arbitrary operation before the flash loan is paid back, potentially allowing malicious behavior.

Impact

Modifying the code ensures that the state is modified only after the external contract has executed and funds have been returned, making the code less susceptible to reentrancy attacks. Without this, the funds can be manipulated.

Tools Used

Manual code analysis.

Recommendations

To fix this reentrancy vulnerability, we should follow the pattern of performing state changes after interacting with external contracts. Update the state (such as modifying s_currentlyFlashLoaning) after the external contract call is made.

s_currentlyFlashLoaning[token] = true;
assetToken.transferUnderlyingTo(receiverAddress, amount);
// Perform the external contract call after funds have been transferred
receiverAddress.functionCall(
abi.encodeWithSignature(
"executeOperation(address,uint256,uint256,address,bytes)",
address(token),
amount,
fee,
msg.sender,
params
)
);
- uint256 endingBalance = token.balanceOf(address(assetToken));
- if (endingBalance < startingBalance + fee) {
- revert ThunderLoan__NotPaidBack(startingBalance + fee, endingBalance);
- }
// Update the state after the external contract call
+ s_currentlyFlashLoaning[token] = false;
+ uint256 endingBalance = token.balanceOf(address(assetToken));
+ if (endingBalance < startingBalance + fee) {
+ revert ThunderLoan__NotPaidBack(startingBalance + fee, endingBalance);
+ }
Updates

Lead Judging Commences

0xnevi Lead Judge
over 1 year ago
0xnevi Lead Judge over 1 year ago
Submission Judgement Published
Invalidated
Reason: Vague generalities

Support

FAQs

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