A vulnerability allows an attacker to extract a disproportionate share of positive funding fees accumulated in the PerpetualVault without having contributed to their generation, creating an unfair profit at the expense of legitimate users.
The vulnerability has a significant financial impact on users, but requires specific timing and conditions to be exploited.
The vulnerability lies in the implementation of the funding fee distribution mechanism in the PerpetualVault.sol contract. When funding fees are claimed, they are simply added to the total vault value, thus increasing the value of all shares proportionally.
An attacker can exploit this behavior by:
Observing off-chain the accumulation of positive funding fees
Depositing funds just before the scheduled claiming of funding fees
Instantly receiving shares that entitle them to a portion of the funding fees
Waiting for the lock period to end to withdraw their funds with profit
Below is a complete Proof of Concept that demonstrates this vulnerability:
The PoC demonstrates that an attacker acquiring 16.67% of the shares can extract exactly 16.6% of the funding fees, despite not having contributed to their generation.
This vulnerability has a significant financial impact:
Legitimate users who have maintained their positions for a long time have a portion of their rightful revenue stolen
Attackers can extract risk-free profits, creating a negative-sum game for long-term users
At scale, this exploitation could create deposit/withdrawal cycles synchronized with funding fee claims, destabilizing the protocol
Numerical proof: An attacker depositing 10,000 USDC (16.67% of shares) extracts exactly 166 USDC (16.6%) from the 1,000 USDC of funding fees, despite not having contributed to generating them.
Foundry for writing and executing the proof of concept test
Manual code analysis
To address this vulnerability, I propose:
Time-based distribution: Implement a mechanism where funding fees are distributed proportionally to time spent in the vault and deposit amount.
Vesting periods: Establish a system where new deposits do not immediately receive previously accumulated funding fees. New deposits should only be entitled to funding fees accumulated after their entry.
Regular snapshots: Create regular snapshots of held shares and distribute funding fees based on these historical snapshots rather than current shares.
Reserve account for funding fees: Maintain a separate account for claimed funding fees and distribute them gradually to shareholders according to a formula that takes into account the duration of holding.
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.
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.