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

Reentrancy risk, the `flashloan` function allows external contracts to execute arbitrary code during a flash loan, approach used with `s_currentlyFlashLoaning[token]` is not entirely secure

Summary

The flashloan function in the contract has a potential reentrancy vulnerability. While an attempt is made to guard against reentrancy by setting s_currentlyFlashLoaning[token] to true, this may not provide sufficient protection. To mitigate the risk of reentrancy attacks, it is advisable to use a more robust reentrancy protection mechanism, such as the ReentrancyGuard from OpenZeppelin.

Vulnerability Details

In the code, the flashloan function allows external contracts to execute arbitrary code during a flash loan. Although the contract attempts to protect against reentrancy by setting s_currentlyFlashLoaning[token] to true at the beginning of the function and back to false at the end, this approach might not be entirely secure.

While setting s_currentlyFlashLoaning[token] to true is intended to prevent reentrancy, it might not cover all possible reentrancy attack scenarios. It's recommended to use a more robust reentrancy protection mechanism to ensure the security of the contract.

function flashloan(address receiverAddress, IERC20 token, uint256 amount, bytes calldata params) external {
// ...
s_currentlyFlashLoaning[token] = true;
assetToken.transferUnderlyingTo(receiverAddress, amount);
// ...
s_currentlyFlashLoaning[token] = false;
}

Impact

  • Unauthorized Access: An attacker could potentially execute arbitrary code and access sensitive functions and data within the contract during a flash loan.

  • Loss of Funds: Malicious attackers may exploit reentrancy vulnerabilities to drain the contract of its funds, causing financial losses for users and the contract itself.

Tools Used

Manual / VsCode

Recommendations

Mitigating the reentrancy vulnerability, it is recommended to use a more robust reentrancy protection mechanism. One common approach is to implement the ReentrancyGuard from OpenZeppelin. The ReentrancyGuard provides comprehensive protection against reentrancy attacks.

Implement the ReentrancyGuard in the contract, By incorporating the ReentrancyGuard, you can significantly enhance the security of your contract and protect against reentrancy attacks more effectively.

import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
contract ThunderLoan is ReentrancyGuard, ... {
// ...
function flashloan(address receiverAddress, IERC20 token, uint256 amount, bytes calldata params) external nonReentrant {
// ...
// No need to manually set s_currentlyFlashLoaning[token] to true/false
// ...
}
}
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.