Currently the fee calculation in the swap hook is vulnerable to precision loss and can lead to incorrect admin and owner fees being distributed.
The fee calculation in onAfterSwap will be impacted by a precision loss at the following operation: adminFee = hookFee / (1e18 / quantAMMFeeTake).
The precision loss will be dependent on the value of quantAMMFeeTake. Since it can be updated by a setter function and it accepts any value below 1e18, the precision loss can happen in practice. Although it can be fixed by setting a new value, once the precision loss happen it's irreversible on the affected swaps.
Please note this precision loss issue was not reported by the bot report.
Numerical POC:
If we multiply the numerator and denominator by 1e18 we would receive a more accurate result:
With the precision loss the adminFee would be 200e18 and the ownerFee would be 400e18.
Without the precision loss, the adminFee would be 180e18 and the ownerFee would be 420e18.
Therefore, in this example we can see a 20e18 in difference for the adminFee and ownerFee.
The consequence would be miscalculations of the fees received by the quant AMM and the pool.
As these calculations will be executed via the hook on every swap, the inaccuracies can accumulate over time.
The bigger the raw token amount calculated by the swap entered via the hook, the bigger the difference will be.
Manual review.
Multiply the numerator and the denominator by 1e18 to avoid the precision loss while calculating the adminFee:
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.