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:
parent
cd4926b540
commit
a21cf398bf
4 changed files with 34 additions and 1 deletions
|
|
@ -473,4 +473,32 @@ contract ThreePositionStrategyTest is TestConstants {
|
|||
strategy.setPositions(CURRENT_TICK, extremeParams);
|
||||
assertEq(strategy.getMintedPositionsCount(), 3, "Should handle extreme parameters gracefully");
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// ANCHOR WIDTH BOUNDS TESTS (#817)
|
||||
// ========================================
|
||||
|
||||
function testAnchorWidthAtMaxBoundarySucceeds() public {
|
||||
// MAX_ANCHOR_WIDTH = 1233: 34 * 1233 * 200 = 8,384,400 fits within int24 max (8,388,607)
|
||||
ThreePositionStrategy.PositionParams memory params = getDefaultParams();
|
||||
params.anchorWidth = 1233;
|
||||
|
||||
strategy.setAnchorPosition(CURRENT_TICK, 20 ether, params);
|
||||
|
||||
MockThreePositionStrategy.MintedPosition memory pos = strategy.getMintedPosition(0);
|
||||
assertTrue(pos.tickLower < pos.tickUpper, "tickLower must be less than tickUpper");
|
||||
assertTrue(pos.tickLower >= -887272, "tickLower must be >= MIN_TICK");
|
||||
assertTrue(pos.tickUpper <= 887272, "tickUpper must be <= MAX_TICK");
|
||||
assertGt(pos.liquidity, 0, "Anchor should have positive liquidity");
|
||||
}
|
||||
|
||||
function testAnchorWidthAboveMaxReverts() public {
|
||||
// anchorWidth = 1234: 34 * 1234 * 200 = 8,391,200 overflows int24 — must not silently produce
|
||||
// an invalid tick range; Solidity 0.8 arithmetic check causes a panic revert instead.
|
||||
ThreePositionStrategy.PositionParams memory params = getDefaultParams();
|
||||
params.anchorWidth = 1234;
|
||||
|
||||
vm.expectRevert();
|
||||
strategy.setAnchorPosition(CURRENT_TICK, 20 ether, params);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue