From 6a9cd636754aa95857af0bb46df0b329a0f78299 Mon Sep 17 00:00:00 2001 From: Hammad Ghazi Date: Wed, 11 Oct 2023 17:34:22 +0500 Subject: [PATCH] implemented order specific sanity checks --- src/AdvancedOrderEngine.sol | 26 ++++++++++++++++++++++++++ src/AdvancedOrderEngineErrors.sol | 3 +++ 2 files changed, 29 insertions(+) diff --git a/src/AdvancedOrderEngine.sol b/src/AdvancedOrderEngine.sol index 33dcf3e..bc433a7 100644 --- a/src/AdvancedOrderEngine.sol +++ b/src/AdvancedOrderEngine.sol @@ -46,6 +46,32 @@ contract AdvancedOrderEngine { revert ZeroFacilitatorTargetAddress(); // TBD: use generic error message i.e. ZeroAddress() } + for (uint256 i; i < orders.length; ) { + OrderEngine.Order calldata order = orders[i]; + + bytes32 orderHash; + + if (block.timestamp > order.validTill) { + revert OrderExpired(orderHash); + } + + if (order.buyTokenAmount == 0 || order.sellTokenAmount == 0) { + revert ZeroTokenAmounts(); + } + + if ( + order.maker == address(0) || + order.buyToken == address(0) || + order.sellToken == address(0) + ) { + revert ZeroAddress(); + } + + unchecked { + ++i; + } + } + // Loop start // Perform order specific sanity checks // Verify signatjures diff --git a/src/AdvancedOrderEngineErrors.sol b/src/AdvancedOrderEngineErrors.sol index 8270062..c02a532 100644 --- a/src/AdvancedOrderEngineErrors.sol +++ b/src/AdvancedOrderEngineErrors.sol @@ -4,3 +4,6 @@ pragma solidity 0.8.21; error ArraysLengthMismatch(uint256 ordersArrLen, uint256 clearingPricesArrLen); error ZeroFacilitatorTargetAddress(); error EmptyOrdersArray(); +error OrderExpired(bytes32 orderHash); +error ZeroTokenAmounts(); +error ZeroAddress();