From 00c2116e0e3df4022ab88dc974cc963102e94812 Mon Sep 17 00:00:00 2001 From: Felipe Faria Date: Mon, 9 Oct 2023 09:40:07 -0300 Subject: [PATCH 1/2] replacing signature checker --- .../contracts/exchange/OrderValidator.sol | 22 +++++-------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/packages/marketplace/contracts/exchange/OrderValidator.sol b/packages/marketplace/contracts/exchange/OrderValidator.sol index b21bd994fa..b6428028b3 100644 --- a/packages/marketplace/contracts/exchange/OrderValidator.sol +++ b/packages/marketplace/contracts/exchange/OrderValidator.sol @@ -4,8 +4,7 @@ pragma solidity 0.8.21; import {LibOrder} from "../lib-order/LibOrder.sol"; import {LibAsset} from "../lib-asset/LibAsset.sol"; -import {IERC1271Upgradeable} from "@openzeppelin/contracts-upgradeable/interfaces/IERC1271Upgradeable.sol"; -import {ECDSAUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/cryptography/ECDSAUpgradeable.sol"; +import {SignatureCheckerUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/cryptography/SignatureCheckerUpgradeable.sol"; import {AddressUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol"; import {EIP712Upgradeable, Initializable} from "@openzeppelin/contracts-upgradeable/utils/cryptography/draft-EIP712Upgradeable.sol"; import {IOrderValidator} from "../interfaces/IOrderValidator.sol"; @@ -14,10 +13,8 @@ import {WhiteList} from "./WhiteList.sol"; /// @title contract for order validation /// @notice validate orders and contains a white list of tokens contract OrderValidator is IOrderValidator, Initializable, EIP712Upgradeable, WhiteList { - using ECDSAUpgradeable for bytes32; using AddressUpgradeable for address; - - bytes4 internal constant MAGICVALUE = 0x1626ba7e; + using SignatureCheckerUpgradeable for address; /// @dev this protects the implementation contract from being initialized. /// @custom:oz-upgrades-unsafe-allow constructor @@ -67,18 +64,9 @@ contract OrderValidator is IOrderValidator, Initializable, EIP712Upgradeable, Wh } bytes32 hash = LibOrder.hash(order); - // if maker is contract checking ERC1271 signature - if (order.maker.isContract()) { - require( - IERC1271Upgradeable(order.maker).isValidSignature(_hashTypedDataV4(hash), signature) == MAGICVALUE, - "contract order signature verification error" - ); - return; - } - - // if maker is not contract then checking ECDSA signature - address recovered = _hashTypedDataV4(hash).recover(signature); - require(recovered == order.maker, "order signature verification error"); + + require(order.maker.isValidSignatureNow(_hashTypedDataV4(hash), signature), "order signature verification error"); + } /// @notice if ERC20 token is accepted From 1728b8babbb12edc108fb0fd30d35082e1d777ec Mon Sep 17 00:00:00 2001 From: Felipe Faria Date: Mon, 9 Oct 2023 09:46:38 -0300 Subject: [PATCH 2/2] format --- .../marketplace/contracts/exchange/OrderValidator.sol | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/marketplace/contracts/exchange/OrderValidator.sol b/packages/marketplace/contracts/exchange/OrderValidator.sol index b6428028b3..dac90171d0 100644 --- a/packages/marketplace/contracts/exchange/OrderValidator.sol +++ b/packages/marketplace/contracts/exchange/OrderValidator.sol @@ -64,9 +64,11 @@ contract OrderValidator is IOrderValidator, Initializable, EIP712Upgradeable, Wh } bytes32 hash = LibOrder.hash(order); - - require(order.maker.isValidSignatureNow(_hashTypedDataV4(hash), signature), "order signature verification error"); - + + require( + order.maker.isValidSignatureNow(_hashTypedDataV4(hash), signature), + "order signature verification error" + ); } /// @notice if ERC20 token is accepted