Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cache/solidity-files-cache.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions cache/test-failures
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
testFail_linear_decrease_tau_zero_reverts|testFail_stairstep_step_zero_reverts
11 changes: 11 additions & 0 deletions foundry.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"lib/ds-test": {
"rev": "0a5da56b0d65960e6a994d2ec8245e6edd38c248"
},
"lib/ds-token": {
"rev": "a5e709b205383720a3d47c7b234771daf4b58766"
},
"lib/ds-value": {
"rev": "4049ecd2652a39cbab464bb1c2c627985f720f97"
}
}
4 changes: 2 additions & 2 deletions src/abaci.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ contract LinearDecrease is Abacus {

// --- Administration ---
function file(bytes32 what, uint256 data) external auth {
if (what == "tau") tau = data;
if (what == "tau") require((tau = data) > 0, "LinearDecrease/tau-is-zero");
else revert("LinearDecrease/file-unrecognized-param");
emit File(what, data);
}
Expand Down Expand Up @@ -120,7 +120,7 @@ contract StairstepExponentialDecrease is Abacus {
// --- Administration ---
function file(bytes32 what, uint256 data) external auth {
if (what == "cut") require((cut = data) <= RAY, "StairstepExponentialDecrease/cut-gt-RAY");
else if (what == "step") step = data;
else if (what == "step") require((step = data) > 0, "StairstepExponentialDecrease/step-is-zero");
else revert("StairstepExponentialDecrease/file-unrecognized-param");
emit File(what, data);
}
Expand Down
20 changes: 20 additions & 0 deletions src/test/abaci.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ interface Hevm {
function store(address,bytes32,bytes32) external;
}

interface Vm {
function expectRevert(bytes calldata) external;
}

contract ClipperTest is DSTest {
Hevm hevm;

Expand Down Expand Up @@ -227,4 +231,20 @@ contract ClipperTest is DSTest {
price = calc.price(top, now - tic);
assertEq(price, 0);
}

// --- Revert tests for zero-value parameter validation ---

// LinearDecrease must reject tau = 0 to prevent division-by-zero in price()
function test_linear_decrease_tau_zero_reverts() public {
LinearDecrease calc = new LinearDecrease();
Vm(address(CHEAT_CODE)).expectRevert(bytes("LinearDecrease/tau-is-zero"));
calc.file(bytes32("tau"), 0);
}

// StairstepExponentialDecrease must reject step = 0 to prevent division-by-zero in price()
function test_stairstep_step_zero_reverts() public {
StairstepExponentialDecrease calc = new StairstepExponentialDecrease();
Vm(address(CHEAT_CODE)).expectRevert(bytes("StairstepExponentialDecrease/step-is-zero"));
calc.file(bytes32("step"), 0);
}
}