Skip to content

Commit

Permalink
feat: handle invalid signature
Browse files Browse the repository at this point in the history
This commit handles the case where cosignature is invalid, reverting.
It also removes the special casing for address(0) cosigner specified
by the user, as that would enable any filler to arbitrarily set the
auction timings

Issue: Cantina #23
  • Loading branch information
marktoda committed Apr 15, 2024
1 parent 88a7f94 commit d56c833
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
188641
188652
2 changes: 1 addition & 1 deletion .forge-snapshots/Base-V2DutchOrder-ExclusiveFiller.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
158755
158766
2 changes: 1 addition & 1 deletion .forge-snapshots/Base-V2DutchOrder-ExecuteBatch.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
210706
210728
Original file line number Diff line number Diff line change
@@ -1 +1 @@
220975
220997
Original file line number Diff line number Diff line change
@@ -1 +1 @@
275146
275168
Original file line number Diff line number Diff line change
@@ -1 +1 @@
204232
204254
2 changes: 1 addition & 1 deletion .forge-snapshots/Base-V2DutchOrder-ExecuteSingle.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
155058
155069
Original file line number Diff line number Diff line change
@@ -1 +1 @@
140620
140631
Original file line number Diff line number Diff line change
@@ -1 +1 @@
164369
164380
2 changes: 1 addition & 1 deletion .forge-snapshots/Base-V2DutchOrder-InputOverride.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
159044
159055
2 changes: 1 addition & 1 deletion .forge-snapshots/Base-V2DutchOrder-OutputOverride.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
158782
158793
2 changes: 1 addition & 1 deletion src/reactors/V2DutchOrderReactor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ contract V2DutchOrderReactor is BaseReactor {
uint8 v = uint8(order.cosignature[64]);
// cosigner signs over (orderHash || cosignerData)
address signer = ecrecover(keccak256(abi.encodePacked(orderHash, abi.encode(order.cosignerData))), v, r, s);
if (order.cosigner != signer && signer != address(0)) {
if (order.cosigner != signer || signer == address(0)) {
revert InvalidCosignature();
}

Expand Down
28 changes: 27 additions & 1 deletion test/reactors/V2DutchOrderReactor.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ contract V2DutchOrderTest is PermitSignature, DeployPermit2, BaseDutchOrderReact
return (SignedOrder(abi.encode(order), signOrder(swapperPrivateKey, address(permit2), order)), orderHash);
}

function testInvalidCosignature() public {
function testWrongCosigner() public {
address wrongCosigner = makeAddr("wrongCosigner");
CosignerData memory cosignerData = CosignerData({
decayStartTime: block.timestamp,
Expand All @@ -147,6 +147,32 @@ contract V2DutchOrderTest is PermitSignature, DeployPermit2, BaseDutchOrderReact
fillContract.execute(signedOrder);
}

function testInvalidCosignature() public {
address wrongCosigner = makeAddr("wrongCosigner");
CosignerData memory cosignerData = CosignerData({
decayStartTime: block.timestamp,
decayEndTime: block.timestamp + 100,
exclusiveFiller: address(0),
exclusivityOverrideBps: 0,
inputAmount: 1 ether,
outputAmounts: ArrayBuilder.fill(1, 1 ether)
});

V2DutchOrder memory order = V2DutchOrder({
info: OrderInfoBuilder.init(address(reactor)).withSwapper(swapper),
cosigner: wrongCosigner,
baseInput: DutchInput(tokenIn, 1 ether, 1 ether),
baseOutputs: OutputsBuilder.singleDutch(address(tokenOut), 1 ether, 1 ether, swapper),
cosignerData: cosignerData,
cosignature: bytes("")
});
order.cosignature = bytes.concat(keccak256("invalidSignature"), keccak256("invalidSignature"), hex"33");
SignedOrder memory signedOrder =
SignedOrder(abi.encode(order), signOrder(swapperPrivateKey, address(permit2), order));
vm.expectRevert(V2DutchOrderReactor.InvalidCosignature.selector);
fillContract.execute(signedOrder);
}

function testInputOverrideWorse() public {
CosignerData memory cosignerData = CosignerData({
decayStartTime: block.timestamp,
Expand Down

0 comments on commit d56c833

Please sign in to comment.