Skip to content

Commit

Permalink
validate order in cancelLimitOrder()
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesjhongc committed Jul 1, 2022
1 parent eeb8f5b commit 3ebb1ef
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
3 changes: 2 additions & 1 deletion contracts/LimitOrder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,8 @@ contract LimitOrder is ILimitOrder, BaseLibEIP712, SignatureValidator, Reentranc
cancelledOrder.takerTokenAmount = 0;

bytes32 cancelledOrderHash = getEIP712Hash(LimitOrderLibEIP712._getOrderStructHash(cancelledOrder));
require(isValidSignature(_order.maker, cancelledOrderHash, bytes(""), _cancelOrderMakerSig), "LimitOrder: Cancel request is not signed by maker");
// validate order and check cancel signature
_validateOrder(cancelledOrder, cancelledOrderHash, _cancelOrderMakerSig);
}

// Set cancelled state to storage
Expand Down
23 changes: 22 additions & 1 deletion contracts/test/forkMainnet/LimitOrder.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1107,11 +1107,32 @@ contract LimitOrderTest is StrategySharedSetup {
zeroOrder.takerTokenAmount = 0;

bytes memory cancelPayload = _genCancelLimitOrderPayload(DEFAULT_ORDER, _signOrder(userPrivateKey, zeroOrder, SignatureValidator.SignatureType.EIP712));
vm.expectRevert("LimitOrder: Cancel request is not signed by maker");
vm.expectRevert("LimitOrder: Order is not signed by maker");
vm.prank(user, user); // Only EOA
userProxy.toLimitOrder(cancelPayload);
}

function testCannotCancelExpiredOrder() public {
LimitOrderLibEIP712.Order memory expiredOrder = DEFAULT_ORDER;
expiredOrder.expiry = 0;

bytes memory payload = _genCancelLimitOrderPayload(DEFAULT_ORDER, _signOrder(userPrivateKey, expiredOrder, SignatureValidator.SignatureType.EIP712));
vm.expectRevert("LimitOrder: Order is expired");
vm.prank(user, user); // Only EOA
userProxy.toLimitOrder(payload);
}

function testCannotCancelTwice() public {
LimitOrderLibEIP712.Order memory zeroOrder = DEFAULT_ORDER;
zeroOrder.takerTokenAmount = 0;

bytes memory payload = _genCancelLimitOrderPayload(DEFAULT_ORDER, _signOrder(makerPrivateKey, zeroOrder, SignatureValidator.SignatureType.EIP712));
vm.prank(user, user); // Only EOA
userProxy.toLimitOrder(payload);
vm.expectRevert("LimitOrder: Order is cancelled");
userProxy.toLimitOrder(payload);
}

/*********************************
* Helpers *
*********************************/
Expand Down

0 comments on commit 3ebb1ef

Please sign in to comment.