Incorrect order of multiplication and division in UpliftOnlyExample::onAfterSwap leads to large errors in calculation adminFee. The adminFee will always greater than or equal to the amount it should be base on the UpdateWeightRunner::quantAMMSwapFeeTake percent. And if the UpdateWeightRunner::quantAMMSwapFeeTake larger than 0.5e18 (>50%), adminFee will take all hookFee, leaving ownerFee zero.
In onAfterSwap function, when calculate the fee that quantammAdmin should take on swap fee base on quantAMMSwapFeeTake UpliftOnlyExample.sol#L335.
However, the value of quantAMMFeeTake is not much smaller than 1e18, the result of (1e18 / quantAMMFeeTake) will have large errors because solidity round down the result. And if quantAMMFeeTake >= 0.5e18 + 1, the result of (1e18 / quantAMMFeeTake) will always 1. Meaning the quantammAdmin will have all the hookFee, the owner have nothing.
First test:
Place this test into UpliftExample.t.sol
In /2024-12-quantamm/pkg/pool-hooks run forge test --mt test_largeErrorWhenCalculate_adminFee -vv.
Look into the logs in terminal, adminFee actual percent always greater than or equal to the quantAMMFeeTake percent. And in worst case, when quantAMMFeeTake > 50%, the adminFee actual percent is 100%.
Second test: With QuantAMMUpliftFeeTake > 0.5e18 (50%), quantammAdmin have all the hook fee.
Place this test into UpliftExample.t.sol and in In /2024-12-quantamm/pkg/pool-hooks run forge test --mt test_quantammAdminHaveAllHookFee. It passes.
The adminFee will always greater than or equal to the amount it should be base on the UpdateWeightRunner::quantAMMSwapFeeTake percent. And if the UpdateWeightRunner::quantAMMSwapFeeTake larger than 0.5e18 (>50%), adminFee will take all hookFee, leaving ownerFee zero.
Manual review
Foundry
Multiply hookFee by quantAMMFeeTake first then divide by 1e18.
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.