fix: Shift field silently ignored — dyadic rational inputs effectively unsupported (#606)
Add require(shift == 0) guards to Optimizer.calculateParams and OptimizerV3.calculateParams so non-zero shifts revert instead of being silently discarded. OptimizerV3Push3 already had this guard. Update IOptimizer.sol NatSpec to document that shift is reserved for future use and must be 0 in all current implementations. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
26957dae88
commit
42b4bf4149
5 changed files with 35 additions and 2 deletions
|
|
@ -359,6 +359,18 @@ contract OptimizerTest is Test {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice calculateParams reverts when any slot has shift != 0
|
||||
*/
|
||||
function testCalculateParamsRevertsOnNonZeroShift() public {
|
||||
for (uint256 k = 0; k < 8; k++) {
|
||||
OptimizerInput[8] memory inputs;
|
||||
inputs[k] = OptimizerInput({ mantissa: 0, shift: 1 });
|
||||
vm.expectRevert("shift not yet supported");
|
||||
optimizer.calculateParams(inputs);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice Non-admin calling upgradeTo should revert with UnauthorizedAccount
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -224,6 +224,17 @@ contract OptimizerV3Push3Test is Test {
|
|||
push3.calculateParams(inp);
|
||||
}
|
||||
|
||||
// ---- Shift guard ----
|
||||
|
||||
function testNonZeroShiftReverts() public {
|
||||
for (uint256 k = 0; k < 8; k++) {
|
||||
OptimizerInput[8] memory inp;
|
||||
inp[k] = OptimizerInput({mantissa: 0, shift: 1});
|
||||
vm.expectRevert("shift not yet supported");
|
||||
push3.calculateParams(inp);
|
||||
}
|
||||
}
|
||||
|
||||
// ---- Fuzz ----
|
||||
|
||||
function testFuzzNeverReverts(uint256 percentageStaked, uint256 averageTaxRate) public view {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue