Skip to content

Commit 8ea679a

Browse files
committed
Add also overflow protection for slope
1 parent 2af76dd commit 8ea679a

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

src/Configurator.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ contract Configurator {
110110
);
111111
require(
112112
slope <= defSlope ||
113+
slope <= current.slope || // avoid overflow for an hypothetical case where current slope is type(uint256).max
113114
slope <= current.slope * maxChange / WAD,
114115
"Configurator/exceeds-max-slope"
115116
);

test/Configurator.t.sol

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,22 @@ contract ConfiguratorTest is DssTest {
405405
assertEq(data.slope, 10 * WAD, "slope should be set correctly");
406406
}
407407

408+
function testSetRateLimitNoOverflowWhenCurrentSlopeIsMax() public {
409+
bytes32 key = keccak256("overflow-slope-key");
410+
_setupCBeam(address(target1), CBEAM1);
411+
_setupDefaultRateLimits(key, address(target1), 1_000 * WAD, 500 * WAD);
412+
// Current slope is type(uint256).max — would overflow in `current.slope * maxChange / WAD`
413+
_setupRateLimitData(target1, key, 1_000 * WAD, type(uint256).max, 1_000 * WAD, block.timestamp);
414+
415+
// Decrease slope to finite value above defaults — should not overflow
416+
vm.prank(CBEAM1);
417+
configurator.setRateLimit(address(target1), key, 1_000 * WAD, 1_000 * WAD);
418+
419+
RateLimitsLike.RateLimitData memory data = target1.getRateLimitData(key);
420+
assertEq(data.maxAmount, 1_000 * WAD, "maxAmount should be set correctly");
421+
assertEq(data.slope, 1_000 * WAD, "slope should decrease from type(uint256).max");
422+
}
423+
408424
// --- LastAmount Capping Tests ---
409425

410426
function testLastAmountCappedAtMaxAmount() public {

0 commit comments

Comments
 (0)