Integer overflow in observation index calculation leads to denial of service
An integer overflow in the observation index calculation of the Strategy contract causes a revert when observationCardinality and currentIndex are large enough. This blocks critical functions like rebalance and compound, leading to a denial of service.
Source: https://github.com/sherlock-audit/2025-02-yieldoor-judging/issues/103
Found by
iamnmt
Summary
When observationCardinality and currentIndex are large enough, the index calculation in Strategy#checkPoolActivity will revert due to integer overflow, causing a denial of service for critical protocol functions.
Relevant Context
checkPoolActivity is called by:
Strategy#_requirePriceWithinRangeStrategy#rebalanceStrategy#compoundStrategy#addVestingPositionLeverager#openLeveragedPosition
These functions are essential for protocol operation.
Root Cause
In Strategy#checkPoolActivity, the observation index calculation:
https://github.com/sherlock-audit/2025-02-yieldoor/blob/b5a0f779dce4236b02665606adb610099451a51a/yieldoor/src/Strategy.sol#L320
uint256 index = (observationCardinality + currentIndex - i) % observationCardinality;
will revert when observationCardinality + currentIndex >= 2**16 due to integer overflow in the addition operation, as both variables are uint16.
Attack Path
- An attacker increases
observationCardinalityNextto 60000 viaUniswapV3Pool#increaseObservationCardinalityNext(See the Appendix for calculation of gas cost) currentIndexincreases so thatobservationCardinality + currentIndex >= 2**16.- The
checkPoolActivityfunction will revert untilcurrentIndexwraps around to 0.
Impact Explanation
High. The integer overflow causes all critical functions that rely on checkPoolActivity to revert, making the contract completely unusable. This includes:
rebalance()- Cannot adjust positions when market conditions changecompound()- Cannot reinvest earned feesaddVestingPosition()- Cannot add new vesting positions
Most critically, when positions become out-of-range, the protocol cannot rebalance them back into profitable ranges. This leads to:
- Loss of yield since out-of-range positions earn no fees
- Locked funds that cannot be rebalanced back into range
The issue persists until currentIndex wraps around to 0, which could take a significant amount of time depending on pool activity.
Proof of Concept
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
import "forge-std/Test.sol";
contract PoC is Test {
function test_PoC() public {
uint16 observationCardinality = 2**15 + 1;
uint16 currentIndex = 2**15;
uint16 i = 1;
uint256 index = (observationCardinality + currentIndex - i) % observationCardinality;
}
}
Logs
[FAIL: panic: arithmetic underflow or overflow (0x11)] test_PoC() (gas: 433)
Traces:
[433] PoC::test_PoC()
└─ ← [Revert] panic: arithmetic underflow or overflow (0x11)
Suite result: FAILED. 0 passed; 1 failed; 0 skipped; finished in 332.96µs (74.17µs CPU time)
Recommendation
Cast observationCardinality to uint32
- uint256 index = (observationCardinality + currentIndex - i) % observationCardinality;
+ uint256 index = (uint32(observationCardinality) + currentIndex - i) % observationCardinality;
Appendix
At block 26923358 on Base tx, on ETH/USDC pool:
observationCardinality = 5000observationCardinalityNext = 5000- Gas Price: 0.002855 Gwei
- 2230192 gas to increase
observationCardinalityNextby 100. Assuming that 1 ETH = 2500 USD. This means it costs 2230192 * 0.002855 / 1e9 = 6.36719816e-06 ETH = 0.0159179954 USD - It costs ((60000 - 5000) / 100) * 0.0159179954 USD = 8.75489747 USD to increase
observationCardinalityNextto 60000.
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
import "forge-std/Test.sol";
import {IUniswapV3Pool} from "../src/interfaces/IUniswapV3Pool.sol";
import {IUniswapV3Factory} from "../src/interfaces/IUniswapV3Factory.sol";
contract PoC is Test {
address WETH = 0x4200000000000000000000000000000000000006;
address USDT = 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913;
IUniswapV3Factory factory = IUniswapV3Factory(0x33128a8fC17869897dcE68Ed026d694621f6FDfD);
function test_PoC() public {
IUniswapV3Pool pool = IUniswapV3Pool(factory.getPool(WETH, USDT, 500));
(uint160 sqrtPriceX96, int24 tick,, uint16 observationCardinality, uint16 observationCardinalityNext,,) = pool.slot0();
console.log("observationCardinality", observationCardinality);
console.log("observationCardinalityNext", observationCardinalityNext);
uint256 gasStart = gasleft();
pool.increaseObservationCardinalityNext(observationCardinality + 100);
uint256 gasEnd = gasleft();
console.log("Gas cost of increaseObservationCardinalityNext", gasStart - gasEnd);
}
}
Logs
Logs:
observationCardinality 5000
observationCardinalityNext 5000
Gas cost of increaseObservationCardinalityNext 2230192
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
Impact
The integer overflow causes all critical functions that rely on checkPoolActivity to revert, making the contract completely unusable and potentially locking funds.
What the attacker needed
Attacker can call increaseObservationCardinalityNext; sufficient gas to increase cardinality
The fix
Cast observationCardinality to uint32 before the addition to prevent overflow.
How it was found
- An attacker increases observationCardinalityNext to 60000 via UniswapV3Pool#increaseObservationCardinalityNext.
- currentIndex increases so that observationCardinality + currentIndex >= 2**16.
- The checkPoolActivity function reverts until currentIndex wraps around to 0.
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 uses a small number type (uint16) to store two values. When added together, they can exceed the maximum value that type can hold, causing the calculation to fail and the function to stop working. This means important actions like rebalancing funds cannot be performed.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.