fix: Unclamped anchorWidth can overflow tick range — no upper-bound guard after MAX_ANCHOR_WIDTH removal (#783) (#817)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
openhands 2026-03-15 21:34:33 +00:00
parent cd4926b540
commit a21cf398bf
4 changed files with 34 additions and 1 deletions

View file

@ -204,7 +204,7 @@ contract LiquidityManager is ThreePositionStrategy, PriceOracle {
PositionParams memory params = PositionParams({
capitalInefficiency: (capitalInefficiency > MAX_PARAM_SCALE) ? MAX_PARAM_SCALE : capitalInefficiency,
anchorShare: (anchorShare > MAX_PARAM_SCALE) ? MAX_PARAM_SCALE : anchorShare,
anchorWidth: anchorWidth,
anchorWidth: (anchorWidth > MAX_ANCHOR_WIDTH) ? MAX_ANCHOR_WIDTH : anchorWidth,
discoveryDepth: (discoveryDepth > MAX_PARAM_SCALE) ? MAX_PARAM_SCALE : discoveryDepth
});

View file

@ -30,6 +30,10 @@ abstract contract ThreePositionStrategy is UniswapMath, VWAPTracker {
int24 internal constant DISCOVERY_SPACING = 11_000;
/// @notice Minimum discovery depth multiplier
uint128 internal constant MIN_DISCOVERY_DEPTH = 200;
/// @notice Maximum safe anchorWidth: ensures 34 * MAX_ANCHOR_WIDTH * TICK_SPACING / 100 fits in int24
/// @dev With TICK_SPACING=200: 34 * 1233 * 200 = 8,384,400 int24 max (8,388,607).
/// anchorWidth=1234 produces 8,391,200 which overflows int24 and reverts in Solidity 0.8.
uint24 internal constant MAX_ANCHOR_WIDTH = 1233;
/// @notice The three liquidity position types
enum Stage {