Possible precision loss in `_checkpositionsRange` function
The `_checkpositionsRange` function divides a signed integer range by two before a modulo check, so the fractional part is truncated and the comparison can be wrong. This could let an invalid positions range pass validation.
0xdice91 Follow with BugBusters, ash and 6 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-06-real-wagmi-judging/issues/82
Found by
0xdice91, BugBusters, ash, ginlee, josephdara, lil.eth, shealtielanz, tsvetanovv, twcctop
Summary
The _checkpositionsRange function contains a potential precision loss issue. The problem arises from the expression ((_range / 2) % _tickSpacing != 0).
Vulnerability Detail
The vulnerability lies in the calculation of (_range / 2) % _tickSpacing. The code assumes that _range and _tickSpacing are both int24 variables, representing signed 24-bit integers. However, when _range is 9 and _tickSpacing is, for example, 3, the division operation (_range / 2) will truncate the fractional part, resulting in 4 instead of 4.5. Subsequently, the modulo operation (4 % _tickSpacing) will evaluate to 1. This can lead to incorrect comparisons and unexpected behavior.
Impact
It can potentially lead to incorrect validation and can also affect the correctness of the positions range check, potentially allowing invalid positions to be considered valid
Code Snippet
function _checkpositionsRange(
int24 _range,
int24 _tickSpacing,
int24 tickSpacingOffset
) private pure {
ErrLib.requirement(
(_range > _tickSpacing) &&
(_range % _tickSpacing == 0) &&
(((_range / 2) % _tickSpacing != 0) || tickSpacingOffset != 0),
ErrLib.ErrorCode.INVALID_POSITIONS_RANGE
);
}
Tool used
Manual Review
Recommendation
Discussion
0xffff11
Seems like a valid medium to me. Reference from tickSpacing: https://docs.uniswap.org/contracts/v3/reference/core/libraries/Tick
fann95
0xffff11
This link seems wrong, it does not bring me to a PR, please check
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
Likely integer division truncates the fractional part before the modulo check, so the validation compares a rounded-down value instead of the true half-range.
Impact
It could allow invalid positions to be considered valid, though the text gives no demonstration of exploitation.
What the attacker needed
Calling the strategy with a crafted range
The fix
The project says it was fixed in a later commit, though a reviewer noted the linked change did not point to a pull request.
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.
Computers store whole numbers, so when you divide an odd number by two the leftover half is thrown away. This code checks a range using that halved value, so the check can give the wrong answer and accept a range it should reject.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.