The PerpetualVault contract does not properly handle fee-on-transfer tokens, which deduct a fee on every transfer. The contract incorrectly records the pre-fee amount instead of the actual received amount, leading to incorrect share allocations, accounting discrepancies, and possible insolvency.
The deposit function does not account for potential token transfer fees:
Accounting Errors: The contract assumes it received the full deposit amount, but in reality, the balance is lower.
Incorrect Share Allocation: Users get more shares than they actually contributed, leading to unfair distributions.
Loss of Funds for Other Users: Over time, withdrawals based on inflated balances drain contract liquidity, leading to insolvency.
Potential Exploit Scenario: A user could deposit, receive extra shares, and withdraw more tokens than they should.
Severity: 🔴 HIGH
Manual code review
This proof of concept demonstrates how an attacker can exploit the lack of post-transfer balance validation to receive more shares than they should, leading to unfair distribution and potential insolvency of the protocol.
Attacker: User who deposits fee-on-transfer tokens to receive inflated share allocation.
Victim: Honest user of the protocol who will be unable to withdraw their full funds.
Protocol: PerpetualVault contract that incorrectly accounts for fee-on-transfer tokens.
The vulnerability in PerpetualVault stems from how it calculates shares during the deposit process, particularly in the _mint function:
Here's what happens in the exploit:
First Deposit (Victim):
Victim deposits 1000 tokens, but only 900 actually arrive due to the 10% fee
Contract records deposit as 1000 tokens
Since this is the first deposit, victim receives 1000 * 1e8 shares (based on recorded amount, not actual)
Second Deposit (Attacker):
Attacker deposits 1000 tokens, but only 900 actually arrive due to the fee
Contract records deposit as 1000 tokens
Share calculation now uses totalAmountBefore = 1000 (first deposit's recorded amount)
Attacker receives shares calculated as: 1000 * totalShares / 1000
Despite both users contributing the same actual amount (900 tokens), the attacker receives an equal share percentage of the pool based on inflated numbers
Share Distribution Analysis:
Both depositors contributed equal actual amounts (900 tokens)
In a fair system, both would receive equal shares
Due to the vulnerability, the share calculation doesn't reflect actual contributions
The test includes a detailed analysis showing exactly how many more shares per token the attacker receives compared to the victim
Withdrawal Impact:
When both users withdraw, they receive tokens proportional to their shares
This results in the victim receiving less than their fair share (900 tokens)
The attacker receives more than their fair share
A detailed fairness analysis quantifies exactly how much the victim loses and the attacker gains
Protocol Insolvency Risk:
As more users deposit with fee-on-transfer tokens, the discrepancy between recorded and actual balances grows
Later depositors gain advantage over earlier ones
The contract becomes increasingly insolvent as recorded deposits exceed actual token holdings
Eventually, later withdrawals may fail entirely as the contract cannot fulfill all claims
This demonstrates that the accounting error in PerpetualVault is not just theoretical but leads to a concrete exploit that results in financial loss for users and potential insolvency of the protocol.
Modify the deposit function to record the actual received amount instead of the input amount, and include additional checks to handle edge cases:
This fix addresses the following edge cases:
Handles tokens with 100% fees by checking if actualAmount is zero
Re-validates minimum deposit amount using the actual received tokens
Re-validates maximum deposit cap using the actual received tokens
By implementing these changes, the contract will correctly account for any fees deducted during token transfers, ensuring accurate share allocation and protecting the protocol from potential exploitation.
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.