QuantAMM

QuantAMM
49,600 OP
View results
Submission Details
Severity: high
Valid

Unfair Split Between Owner Fee and Admin Fee in `UpliftOnlyExample::onAfterSwap`

Summary

In the UpliftOnlyExample::onAfterSwap function, an incorrect calculation of the admin fee (adminFee) leads to scenarios where the entire fee is allocated to the admin, leaving no rewards for the owner. This issue arises due to the division-based calculation method that fails in certain cases because of Solidity's integer math.

Vulnerability Details

The issue lies in this calculation:

uint256 adminFee = hookFee / (1e18 / quantAMMFeeTake); // Potential for incorrect result

Since Solidity does not support floating-point arithmetic, the calculation can result in a rounding error, causing adminFee to be calculated more than expected or as equal to hookFee under specific values.

POC

Unit test:

function testFeeAdmin() public {
uint256 quantAMMFeeTake = 6e17;
uint256 hookFee = 1e18;
uint256 adminFee1 = hookFee / (1e18 / quantAMMFeeTake);
uint256 ownerFee = hookFee - adminFee1;
console2.log("quantAMMFeeTake:", quantAMMFeeTake);
console2.log("hookFee:", hookFee);
console2.log("adminFee1:", adminFee1);
console2.log("ownerFee:", ownerFee);
}
Logs:
quantAMMFeeTake: 600000000000000000
hookFee: 1000000000000000000
adminFee1: 1000000000000000000
ownerFee: 0

Impact

The owner loses their rightful share of the rewards, resulting in an unfair distribution of fees.

Tools Used

  • Manual Review

  • Fuzz Testing

Recommendations

Replace the current calculation of adminFee with a multiplication-based approach to avoid precision loss.
By rewriting the formula, we eliminate the intermediate division, preventing rounding issues and ensuring a fair split between adminFee and ownerFee.

In math, we can change the calculation like this:
(a/b) / (c/d) = (a*d) / (b*c)
so:
(hookFee) / (1e18/quantAMMFeeTake) = (hookFee/1) / (1e18/quantAMMFeeTake) = (hookFee*quantAMMFeeTake) / (1e18)

Code Diff

if (quantAMMFeeTake > 0) {
- uint256 adminFee = hookFee / (1e18 / quantAMMFeeTake);
+ uint256 adminFee = (hookFee * quantAMMFeeTake) / 1e18;
ownerFee = hookFee - adminFee;
}
Updates

Lead Judging Commences

n0kto Lead Judge 11 months ago
Submission Judgement Published
Validated
Assigned finding tags:

finding_onAfterSwap_adminFee_overestimated_solidity_rounding_down

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%.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.

Give us feedback!