The liquidity pool contract exhibits a vulnerability in its fee distribution mechanism. Specifically, the calculation of fees distributed to receivers is flawed, potentially leading to incorrect or unintended fee allocations. This can result in economic disadvantages for users and may impact the overall trust and utility of the liquidity pool.
In the _updateStrategyRewards function, the contract calculates fees based on the totalRewards generated from the strategies. However, the current implementation does not account for edge cases, such as rounding errors and incorrect fee distribution when the total rewards are less than the total fees. As a result, some receivers may not receive their intended share, leading to an unfair distribution of funds.
Code Snippet from _updateStrategyRewards:
In this implementation, the calculation of feeAmounts does not correctly ensure that the total fee distribution does not exceed the totalRewards.
PoC:
Suppose there is a scenario where the total rewards generated are less than the total fees defined in the contract. This could occur due to reduced user activity, leading to lower rewards. When the contract calculates the fee distribution, it could incorrectly allocate fees based on the current calculation logic, resulting in some addresses receiving less than they should.
Example scenario:
Assume totalRewards generated is 500 tokens.
The defined fees are:
Receiver A: 50% (5000 basis points)
Receiver B: 30% (3000 basis points)
Receiver C: 20% (2000 basis points)
The total fees in basis points sum to 10000. However, when the total rewards are 500 tokens, the calculated fees will be:
Receiver A: (500 * 5000) / 10000 = 2500
Receiver B: (500 * 3000) / 10000 = 1500
Receiver C: (500 * 2000) / 10000 = 1000
This would lead to a total fee distribution of 5000, exceeding the available 500 tokens.
To validate the vulnerability, we can create a Hardhat test case.
Users may not receive the correct amount of fees they are entitled to, leading to dissatisfaction and potential loss of trust in the liquidity pool.
The contract’s behavior becomes unpredictable, making it harder for users to estimate their returns.
If users are aware of the miscalculation, they may find ways to exploit the fee distribution system, exacerbating the economic harm.
Manual review.
To mitigate this vulnerability, the fee distribution calculation must be adjusted to ensure that the total fees do not exceed the available rewards. This could be achieved by implementing a check after calculating the total fees to ensure they are within the available rewards.
Fix:
Adjusted fee distribution logic:
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.