A reentrancy vulnerability has been identified in the PerpetualVault._handleReturn function. The function makes an external call to _transferToken(depositId, amount) before updating critical state variables. This allows an attacker to re-enter the contract and manipulate its state, potentially leading to fund loss, double withdrawals, or inconsistent balances.
Affected Code (PerpetualVault.sol, lines #1129-1156)
Reentrancy Risk: _transferToken(depositId, amount) makes an external call to a token contract before deleting swapProgressData, flowData, and flow.
State Manipulation: Since the state is not yet updated, an attacker could re-enter the contract and manipulate balances.
Double Withdrawals: By re-entering, an attacker could withdraw multiple times before state updates take effect.
Fund Drain: Attackers can withdraw more than their actual balance.
State Corruption: Attackers can alter contract states (swapProgressData, flowData, flow).
Multiple Withdrawals: Users may withdraw the same deposit more than once.
Vs code
Move all state updates before making external calls to eliminate the reentrancy risk.
ReentrancyGuardImplement ReentrancyGuard to prevent multiple calls in a single transaction.
Ensure that the ERC20 token used does not have hooks or external callbacks that could be exploited.
If possible, use SafeERC20’s safeTransfer instead of direct function calls.
Please read the CodeHawks documentation to know which submissions are valid. If you disagree, provide a coded PoC and explain the real likelihood and the detailed impact on the mainnet without any supposition (if, it could, etc) to prove your point.
There is no real proof, concrete root cause, specific impact, or enough details in those submissions. Examples include: "It could happen" without specifying when, "If this impossible case happens," "Unexpected behavior," etc. Make a Proof of Concept (PoC) using external functions and realistic parameters. Do not test only the internal function where you think you found something.
Please read the CodeHawks documentation to know which submissions are valid. If you disagree, provide a coded PoC and explain the real likelihood and the detailed impact on the mainnet without any supposition (if, it could, etc) to prove your point.
There is no real proof, concrete root cause, specific impact, or enough details in those submissions. Examples include: "It could happen" without specifying when, "If this impossible case happens," "Unexpected behavior," etc. Make a Proof of Concept (PoC) using external functions and realistic parameters. Do not test only the internal function where you think you found something.
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.