Skip to content
Smart contracts Audit finding Intermediate

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

Solidity
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 
        );
    }

https://github.com/sherlock-audit/2023-06-real-wagmi/blob/82a234a5c2c1fc1921c63265a9349b71d84675c4/concentrator/contracts/MultiStrategy.sol#L93-L104

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

FIXED https://github.com/RealWagmi/concentrator/blob/fbccf1caf28edbb23db8c7e0409d0c40c3a56461/contracts/MultiStrategy.sol#L98

0xffff11

FIXED https://github.com/RealWagmi/concentrator/blob/fbccf1caf28edbb23db8c7e0409d0c40c3a56461/contracts/MultiStrategy.sol#L98

This link seems wrong, it does not bring me to a PR, please check

The original report as published on Sherlock, by 0xdice91. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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.

More by 0xdice91

View all

5 more disclosed reports, best first.

More from Real Wagmi #2

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.