The flashloan function in the ThunderLoan contract has a potential reentrancy vulnerability that can be exploited to drain tokens from the contract. This vulnerability occurs because the function does not enforce proper order of operations when handling external calls, allowing an attacker to create a reentrancy attack.
Lack of Correct Sequence: The function's improper order of operations, calculating a fee and updating exchange rates before verifying the user's contract (external), poses a reentrancy risk.
Reentrancy Attack Vector: The vulnerability arises from executeOperation on receiverAddress, allowing malicious or unexpected behavior, potentially disrupting the flash loan process.
This vulnerability can lead to unauthorized reentrancy attacks, enabling malicious external contracts to disrupt the flash loan process and potentially drain assets from the ThunderLoan contract.
Manual review
For removing the reentrancy risk, you should follow these steps:
1 - Calculate the fee and update the exchange rate before interacting with external contracts. This is critical to ensure the correct sequence of operations.
2 - Implement guard conditions to prevent reentrancy attacks by checking whether the function has already been called during the execution of a flash loan.
New code will look like this for preventing reentrancy risks:
In this code, a bool variable alreadyCalled is introduced to ensure that the receiverAddress contract's executeOperation function is not called reentrantly within the same transaction. This helps prevent reentrancy attacks.
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.