The audit identified a vulnerability in the UpliftOnlyExample contract where a division rounding in the admin fee calculation lead to significant precision loss, resulting in unfair fee distribution.
Found in pkg/pool-hooks/contracts/hooks-quantamm/UpliftOnlyExample.sol at Line 335
The root cause of the vulnerability is that the equation adminFee = hookFee / (1e18 / quantAMMFeeTake) takes advantage of the precision loss of integer division, where the denominator 1e18 / quantAMMFeeTake rounds down significantly before the next division of hookFee, making the adminFee larger than expected.
Let's observe the following comparison table to see the impact of the rounding error:
quantAMMFeeTake |
adminFee |
expectedAdminFee |
ownerFee |
expectedOwnerFee |
router loss |
|---|---|---|---|---|---|
| 0.1e18 (10%) | 0.1 * hookFee | 0.1 * hookFee | 0.9 * hookFee | 0.9 * hookFee | 0 |
| 0.2e18 (20%) | 0.2 * hookFee | 0.2 * hookFee | 0.8 * hookFee | 0.8 * hookFee | 0 |
| 0.3e18 (30%) | 0.333 * hookFee | 0.3 * hookFee | 0.667 * hookFee | 0.7 * hookFee | 0.033 * hookFee |
| 0.4e18 (40%) | 0.5 * hookFee | 0.4 * hookFee | 0.5 * hookFee | 0.6 * hookFee | 0.1 * hookFee |
| 0.5e18 (50%) | 0.5 * hookFee | 0.5 * hookFee | 0.5 * hookFee | 0.5 * hookFee | 0 |
| 0.5001e18 (50.01%) | 1 * hookFee | 0.5001 * hookFee | 0 | 0.4999 * hookFee | 0.4999 * hookFee |
| 0.6e18 (60%) | 1 * hookFee | 0.6 * hookFee | 0 | 0.4 * hookFee | 0.4 * hookFee |
| 0.7e18 (70%) | 1 * hookFee | 0.7 * hookFee | 0 | 0.3 * hookFee | 0.3 * hookFee |
| 0.8e18 (80%) | 1 * hookFee | 0.8 * hookFee | 0 | 0.2 * hookFee | 0.2 * hookFee |
| 0.9e18 (90%) | 1 * hookFee | 0.9 * hookFee | 0 | 0.1 * hookFee | 0.1 * hookFee |
| 1.0e18 (100%) | 1 * hookFee | 1.0 * hookFee | 0 | 0 | 0 |
adminFee values are calculated using hookFee / (1e18 / quantAMMFeeTake) and normalized where applicable.
expectedAdminFee is calculated using hookFee * quantAMMFeeTake / 1e18.
ownerFee is hookFee - adminFee.
expectedOwnerFee is hookFee - expectedAdminFee.
This clearly demonstrates how the incorrect formula causes inflated adminFee and diminished ownerFee, especially as quantAMMFeeTake starts to exceed 0.5e18 (50%).
The inability to accurately calculate the admin fee not only breaks the core functionality of the protocol's fee distribution, but also causes a significant loss for the router in terms of accrued fee incomes.
Manual Review
Consider using the normal practice of multiplying before division, such as
to minimize precision loss and ensure fair fee distribution.
Likelyhood: High, quantAMMFeeTake is a percentage on calculated fees. Being between 30-70% is very likely. Impact: High, fees for LP providers will be lower than expected and 0 if the admin fees is above 50%.
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.