Skip to content

Commit

Permalink
fix: enforce dutch decay actually decays
Browse files Browse the repository at this point in the history
Previously there was ambiguous undefined behavior for if startTime and
endTime were the same - This commit removes that ambiguity by enforcing
startTime !== endTime
  • Loading branch information
marktoda committed Aug 22, 2023
1 parent 0d81086 commit 068076f
Show file tree
Hide file tree
Showing 37 changed files with 55 additions and 40 deletions.
@@ -1 +1 @@
181978
181972
2 changes: 1 addition & 1 deletion .forge-snapshots/Base-DutchOrder-ExecuteBatch.snap
@@ -1 +1 @@
196879
196867
@@ -1 +1 @@
206650
206635
@@ -1 +1 @@
260307
260289
@@ -1 +1 @@
190411
190399
2 changes: 1 addition & 1 deletion .forge-snapshots/Base-DutchOrder-ExecuteSingle.snap
@@ -1 +1 @@
148194
148188
@@ -1 +1 @@
133756
133750
@@ -1 +1 @@
137605
157499
@@ -1 +1 @@
150633
182180
@@ -1 +1 @@
197283
197271
@@ -1 +1 @@
207049
207034
@@ -1 +1 @@
260720
260702
@@ -1 +1 @@
190809
190797
@@ -1 +1 @@
148401
148395
@@ -1 +1 @@
95568
133962
@@ -1 +1 @@
157716
157710
@@ -1 +1 @@
133743
153643
2 changes: 1 addition & 1 deletion .forge-snapshots/DirectFillerFillMacroSingleOrder.snap
@@ -1 +1 @@
136213
136207
@@ -1 +1 @@
175064
175055
2 changes: 1 addition & 1 deletion .forge-snapshots/DirectFillerFillMacroTestEth1Output.snap
@@ -1 +1 @@
147390
147384
2 changes: 1 addition & 1 deletion .forge-snapshots/DirectFillerFillMacroTestEth2Outputs.snap
@@ -1 +1 @@
170604
170592
@@ -1 +1 @@
435187
435160
2 changes: 1 addition & 1 deletion .forge-snapshots/DirectFillerFillMacroTwoOrders.snap
@@ -1 +1 @@
255972
255957
@@ -1 +1 @@
363478
363457
2 changes: 1 addition & 1 deletion .forge-snapshots/EthOutputTestEthOutput.snap
@@ -1 +1 @@
156223
156217
@@ -1 +1 @@
176915
176906
@@ -1 +1 @@
162907
162898
@@ -1 +1 @@
166046
166037
@@ -1 +1 @@
146873
146864
2 changes: 1 addition & 1 deletion .forge-snapshots/ProtocolFeesGasComparisonTest-NoFees.snap
@@ -1 +1 @@
149267
149261
@@ -1 +1 @@
124929
124923
2 changes: 1 addition & 1 deletion .forge-snapshots/SwapRouter02ExecutorExecute.snap
@@ -1 +1 @@
262973
262967
@@ -1 +1 @@
118092
118086
2 changes: 1 addition & 1 deletion .forge-snapshots/testExclusiveFillerSucceeds.snap
@@ -1 +1 @@
174066
174060
2 changes: 1 addition & 1 deletion src/lib/DutchDecayLib.sol
Expand Up @@ -28,7 +28,7 @@ library DutchDecayLib {
view
returns (uint256 decayedAmount)
{
if (decayEndTime < decayStartTime) {
if (decayEndTime <= decayStartTime) {
revert EndTimeBeforeStartTime();
} else if (decayEndTime <= block.timestamp) {
decayedAmount = endAmount;
Expand Down
6 changes: 3 additions & 3 deletions test/lib/DutchDecayLib.t.sol
Expand Up @@ -6,7 +6,7 @@ import {DutchDecayLib} from "../../src/lib/DutchDecayLib.sol";

contract DutchDecayLibTest is Test {
function testDutchDecayNoDecay(uint256 amount, uint256 decayStartTime, uint256 decayEndTime) public {
vm.assume(decayEndTime >= decayStartTime);
vm.assume(decayEndTime > decayStartTime);
assertEq(DutchDecayLib.decay(amount, amount, decayStartTime, decayEndTime), amount);
}

Expand Down Expand Up @@ -78,7 +78,7 @@ contract DutchDecayLibTest is Test {
public
{
vm.assume(endAmount > startAmount);
vm.assume(decayEndTime >= decayStartTime);
vm.assume(decayEndTime > decayStartTime);
uint256 decayed = DutchDecayLib.decay(startAmount, endAmount, decayStartTime, decayEndTime);
assertGe(decayed, startAmount);
assertLe(decayed, endAmount);
Expand All @@ -91,7 +91,7 @@ contract DutchDecayLibTest is Test {
uint256 decayEndTime
) public {
vm.assume(endAmount < startAmount);
vm.assume(decayEndTime >= decayStartTime);
vm.assume(decayEndTime > decayStartTime);
uint256 decayed = DutchDecayLib.decay(startAmount, endAmount, decayStartTime, decayEndTime);
assertLe(decayed, startAmount);
assertGe(decayed, endAmount);
Expand Down
19 changes: 17 additions & 2 deletions test/reactors/DutchOrderReactor.t.sol
Expand Up @@ -160,13 +160,28 @@ contract DutchOrderReactorValidationTest is Test, DeployPermit2 {
reactor.resolveOrder(SignedOrder(abi.encode(dlo), sig));
}

function testValidateDutchEndTimeAfterStart() public view {
function testValidateDutchEndTimeEqualStart() public {
vm.expectRevert(DutchDecayLib.EndTimeBeforeStartTime.selector);
DutchOutput[] memory dutchOutputs = new DutchOutput[](1);
dutchOutputs[0] = DutchOutput(address(0), 1000, 900, address(0));
DutchOrder memory dlo = DutchOrder(
OrderInfoBuilder.init(address(reactor)).withDeadline(1659130540),
1659120540,
1659130540,
1659130540,
DutchInput(MockERC20(address(0)), 0, 0),
dutchOutputs
);
bytes memory sig = hex"1234";
reactor.resolveOrder(SignedOrder(abi.encode(dlo), sig));
}

function testValidateDutchEndTimeAfterStart() public view {
DutchOutput[] memory dutchOutputs = new DutchOutput[](1);
dutchOutputs[0] = DutchOutput(address(0), 1000, 900, address(0));
DutchOrder memory dlo = DutchOrder(
OrderInfoBuilder.init(address(reactor)).withDeadline(1659130541),
1659120540,
1659130541,
DutchInput(MockERC20(address(0)), 0, 0),
dutchOutputs
);
Expand Down

0 comments on commit 068076f

Please sign in to comment.