fix: Optimizer.sol base class only guards slots 0 and 1 (#968)
Replace the two per-slot require checks with a loop over all 8 input slots so future subclasses using slots 2-7 are protected from silent uint256 wrap. Add testCalculateParamsRevertsOnNegativeMantissaSlots2to7 to verify the guard. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
b30e3a8d51
commit
28ce5ec8cd
2 changed files with 15 additions and 2 deletions
|
|
@ -370,8 +370,9 @@ contract Optimizer is Initializable, UUPSUpgradeable, IOptimizer {
|
|||
returns (uint256 capitalInefficiency, uint256 anchorShare, uint24 anchorWidth, uint256 discoveryDepth)
|
||||
{
|
||||
// Guard against negative mantissa — uint256() cast silently wraps negatives.
|
||||
require(inputs[0].mantissa >= 0, "negative mantissa");
|
||||
require(inputs[1].mantissa >= 0, "negative mantissa");
|
||||
for (uint256 k; k < 8; k++) {
|
||||
require(inputs[k].mantissa >= 0, "negative mantissa");
|
||||
}
|
||||
// Extract slots 0 and 1 (shift=0 assumed — mantissa IS the value)
|
||||
uint256 percentageStaked = uint256(inputs[0].mantissa);
|
||||
uint256 averageTaxRate = uint256(inputs[1].mantissa);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue