A critical vulnerability was discovered in the PerpetualVault contract that allows an attacker to drain funds by manipulating the vault's state through the setVaultState
function. This vulnerability enables an attacker to create duplicate positions and execute double withdrawals, potentially draining the entire vault.
The vulnerability exists in the setVaultState
function which allows direct manipulation of critical vault state variables without proper validation:
The root cause of this vulnerability is the lack of validation in the setVaultState
function, which allows an attacker to:
Set positionIsClosed = true
while maintaining an active position
Process new deposits as if the position is closed
Create duplicate positions on GMX
Execute double withdrawals
The impact of this vulnerability is severe:
Complete drain of vault funds possible
No complex market manipulation required
Single transaction execution possible
Bypasses existing security mechanisms
No warning signs or indicators of exploitation
For this audit, the following tools were utilized:
Manual code review
Static analysis
State flow analysis
Hardhat
Here's a test implementation using Hardhat to demonstrate the vulnerability:
When run, this test will demonstrate the vulnerability by showing that an attacker can:
Create an initial position
Manipulate the state to show the position as closed
Process a new deposit as if the position is closed
Verify that shares are minted for the same position twice
To fix this vulnerability, implement the following changes:
Add validation to prevent state inconsistencies:
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. Keepers are added by the admin, there is no "malicious keeper" and if there is a problem in those keepers, that's out of scope. ReadMe and known issues states: " * System relies heavily on keeper for executing trades * Single keeper point of failure if not properly distributed * Malicious keeper could potentially front-run or delay transactions * Assume that Keeper will always have enough gas to execute transactions. There is a pay execution fee function, but the assumption should be that there's more than enough gas to cover transaction failures, retries, etc * There are two spot swap functionalies: (1) using GMX swap and (2) using Paraswap. We can assume that any swap failure will be retried until success. " " * Heavy dependency on GMX protocol functioning correctly * Owner can update GMX-related addresses * Changes in GMX protocol could impact system operations * We can assume that the GMX keeper won't misbehave, delay, or go offline. " "Issues related to GMX Keepers being DOS'd or losing functionality would be considered invalid."
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. Keepers are added by the admin, there is no "malicious keeper" and if there is a problem in those keepers, that's out of scope. ReadMe and known issues states: " * System relies heavily on keeper for executing trades * Single keeper point of failure if not properly distributed * Malicious keeper could potentially front-run or delay transactions * Assume that Keeper will always have enough gas to execute transactions. There is a pay execution fee function, but the assumption should be that there's more than enough gas to cover transaction failures, retries, etc * There are two spot swap functionalies: (1) using GMX swap and (2) using Paraswap. We can assume that any swap failure will be retried until success. " " * Heavy dependency on GMX protocol functioning correctly * Owner can update GMX-related addresses * Changes in GMX protocol could impact system operations * We can assume that the GMX keeper won't misbehave, delay, or go offline. " "Issues related to GMX Keepers being DOS'd or losing functionality would be considered invalid."
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.