There is a logical error in the removeFeeExemption() function
The removeFeeExemption function checks for a value of 1 in the lower 24 bits, but setFeeExemption sets those bits to 0xFFFFFF, so the check always fails and the exemption is never removed. An attacker (or any user with an exemption) could continue to receive reduced fees indefinitely, causing fee losses for LPs and the protocol.
0xc0ffEE Follow with BugPull, Ironsidesec and 12 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-08-flayer-judging/issues/219
Found by
0xc0ffEE, BugPull, Ironsidesec, NoOne, Tendency, ZeroTrust, alexzoid, cawfree, g, h2134, kuprum, stuart_the_minion, valuevalk, xKeywordx, zzykxx
Summary
There is a logical error in the removeFeeExemption() function, causing feeOverrides[_beneficiary] to never be removed.
Vulnerability Detail
function removeFeeExemption(address _beneficiary) public onlyOwner {
// Check that a beneficiary is currently enabled
@>> uint24 hasExemption = uint24(feeOverrides[_beneficiary] & 0xFFFFFF);
@>> if (hasExemption != 1) {
revert NoBeneficiaryExemption(_beneficiary);
}
delete feeOverrides[_beneficiary];
emit BeneficiaryFeeRemoved(_beneficiary);
}
Through setFeeExemption(), we know that the lower 24 bits of feeOverrides[_beneficiary] are set to 0xFFFFFF. Therefore, the expression uint24 hasExemption = uint24(feeOverrides[_beneficiary] & 0xFFFFFF) results in 0xFFFFFF & 0xFFFFFF = 0xFFFFFF. As a result, hasExemption will never be 1, causing removeFeeExemption() to always revert. Consequently, feeOverrides[_beneficiary] will never be removed.
function setFeeExemption(address _beneficiary, uint24 _flatFee) public onlyOwner {
// Ensure that our custom fee conforms to Uniswap V4 requirements
if (!_flatFee.isValid()) {
revert FeeExemptionInvalid(_flatFee, LPFeeLibrary.MAX_LP_FEE);
}
// We need to be able to detect if the zero value is a flat fee being applied to
// the user, or it just hasn't been set. By packing the `1` in the latter `uint24`
// we essentially get a boolean flag to show this.
@>> feeOverrides[_beneficiary] = uint48(_flatFee) << 24 | 0xFFFFFF;
emit BeneficiaryFeeSet(_beneficiary, _flatFee);
}
Impact
Since feeOverrides[_beneficiary] cannot be removed, the user continues to receive reduced fee benefits, leading to partial fee losses for LPs and the protocol.
Code Snippet
Tool used
Manual Review
Recommendation
function removeFeeExemption(address _beneficiary) public onlyOwner {
// Check that a beneficiary is currently enabled
uint24 hasExemption = uint24(feeOverrides[_beneficiary] & 0xFFFFFF);
- if (hasExemption != 1) {
+ if (hasExemption != 0xFFFFFF) {
revert NoBeneficiaryExemption(_beneficiary);
}
delete feeOverrides[_beneficiary];
emit BeneficiaryFeeRemoved(_beneficiary);
}
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The check in removeFeeExemption compares the lower 24 bits to 1 instead of 0xFFFFFF, which is the value set by setFeeExemption.
Impact
Users with a fee exemption cannot have it removed, so they continue to pay reduced fees, leading to partial fee losses for LPs and the protocol.
What the attacker needed
Owner calls setFeeExemption; owner tries to remove exemption
The fix
The check should compare hasExemption to 0xFFFFFF instead of 1.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A smart contract has a function to remove a fee discount, but it checks for the wrong number. The discount is stored with a marker value of 0xFFFFFF, but the removal function expects 1, so it always fails. This means once a discount is given, it can never be taken away.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.