From 5f8e092c96139d7c86a3aaca56b3f12562d34e0f Mon Sep 17 00:00:00 2001 From: Amir Bandeali Date: Thu, 29 Aug 2019 23:24:55 -0700 Subject: [PATCH] Move EIP1271 selectors to their own interface --- .../contracts/src/MixinSignatureValidator.sol | 9 ++-- .../contracts/src/interfaces/IEIP1271Data.sol | 47 +++++++++++++++++++ .../src/interfaces/IEIP1271Wallet.sol | 21 --------- contracts/exchange/package.json | 2 +- contracts/exchange/src/artifacts.ts | 2 + contracts/exchange/src/wrappers.ts | 1 + contracts/exchange/tsconfig.json | 1 + 7 files changed, 57 insertions(+), 26 deletions(-) create mode 100644 contracts/exchange/contracts/src/interfaces/IEIP1271Data.sol diff --git a/contracts/exchange/contracts/src/MixinSignatureValidator.sol b/contracts/exchange/contracts/src/MixinSignatureValidator.sol index 5b585a4ad6..42f7e9bd23 100644 --- a/contracts/exchange/contracts/src/MixinSignatureValidator.sol +++ b/contracts/exchange/contracts/src/MixinSignatureValidator.sol @@ -30,6 +30,7 @@ import "@0x/contracts-exchange-libs/contracts/src/LibExchangeRichErrors.sol"; import "./interfaces/IWallet.sol"; import "./interfaces/IEIP1271Wallet.sol"; import "./interfaces/ISignatureValidator.sol"; +import "./interfaces/IEIP1271Data.sol"; import "./MixinTransactions.sol"; @@ -221,7 +222,7 @@ contract MixinSignatureValidator is // The entire order is verified by a validator contract. isValid = _validateBytesWithValidator( abi.encodeWithSelector( - IEIP1271Wallet(address(0)).OrderWithHash.selector, + IEIP1271Data(address(0)).OrderWithHash.selector, order, orderHash ), @@ -233,7 +234,7 @@ contract MixinSignatureValidator is // The entire order is verified by a wallet contract. isValid = _validateBytesWithWallet( abi.encodeWithSelector( - IEIP1271Wallet(address(0)).OrderWithHash.selector, + IEIP1271Data(address(0)).OrderWithHash.selector, order, orderHash ), @@ -277,7 +278,7 @@ contract MixinSignatureValidator is // The entire transaction is verified by a validator contract. isValid = _validateBytesWithValidator( abi.encodeWithSelector( - IEIP1271Wallet(address(0)).ZeroExTransactionWithHash.selector, + IEIP1271Data(address(0)).ZeroExTransactionWithHash.selector, transaction, transactionHash ), @@ -289,7 +290,7 @@ contract MixinSignatureValidator is // The entire transaction is verified by a wallet contract. isValid = _validateBytesWithWallet( abi.encodeWithSelector( - IEIP1271Wallet(address(0)).ZeroExTransactionWithHash.selector, + IEIP1271Data(address(0)).ZeroExTransactionWithHash.selector, transaction, transactionHash ), diff --git a/contracts/exchange/contracts/src/interfaces/IEIP1271Data.sol b/contracts/exchange/contracts/src/interfaces/IEIP1271Data.sol new file mode 100644 index 0000000000..fb39bf2439 --- /dev/null +++ b/contracts/exchange/contracts/src/interfaces/IEIP1271Data.sol @@ -0,0 +1,47 @@ +/* + + Copyright 2019 ZeroEx Intl. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +*/ + +pragma solidity ^0.5.9; +pragma experimental ABIEncoderV2; + +import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibZeroExTransaction.sol"; + + +contract IEIP1271Data { + + /// @dev This function's selector is used when ABI encoding the order + /// and hash into a byte array before calling `isValidSignature`. + /// This function serves no other purpose. + function OrderWithHash( + LibOrder.Order calldata order, + bytes32 orderHash + ) + external + pure; + + /// @dev This function's selector is used when ABI encoding the transaction + /// and hash into a byte array before calling `isValidSignature`. + /// This function serves no other purpose. + function ZeroExTransactionWithHash( + LibZeroExTransaction.ZeroExTransaction calldata transaction, + bytes32 transactionHash + ) + external + pure; +} diff --git a/contracts/exchange/contracts/src/interfaces/IEIP1271Wallet.sol b/contracts/exchange/contracts/src/interfaces/IEIP1271Wallet.sol index 7e0fe5c0c7..2cd254e5d8 100644 --- a/contracts/exchange/contracts/src/interfaces/IEIP1271Wallet.sol +++ b/contracts/exchange/contracts/src/interfaces/IEIP1271Wallet.sol @@ -17,7 +17,6 @@ */ pragma solidity ^0.5.9; -pragma experimental ABIEncoderV2; import "@0x/contracts-utils/contracts/src/LibEIP1271.sol"; import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol"; @@ -38,24 +37,4 @@ contract IEIP1271Wallet is external view returns (bytes4 magicValue); - - /// @dev This function's selector is used when ABI encoding the order - /// and hash into a byte array before calling `isValidSignature`. - /// This function serves no other purpose. - function OrderWithHash( - LibOrder.Order calldata order, - bytes32 orderHash - ) - external - pure; - - /// @dev This function's selector is used when ABI encoding the transaction - /// and hash into a byte array before calling `isValidSignature`. - /// This function serves no other purpose. - function ZeroExTransactionWithHash( - LibZeroExTransaction.ZeroExTransaction calldata transaction, - bytes32 transactionHash - ) - external - pure; } diff --git a/contracts/exchange/package.json b/contracts/exchange/package.json index 5d5b15f036..a1db64b70e 100644 --- a/contracts/exchange/package.json +++ b/contracts/exchange/package.json @@ -35,7 +35,7 @@ "compile:truffle": "truffle compile" }, "config": { - "abis": "./generated-artifacts/@(Exchange|IAssetProxy|IAssetProxyDispatcher|IEIP1271Wallet|IExchange|IExchangeCore|IMatchOrders|IProtocolFees|ISignatureValidator|ITransactions|ITransferSimulator|IWallet|IWrapperFunctions|IsolatedExchange|LibExchangeRichErrorDecoder|MixinAssetProxyDispatcher|MixinExchangeCore|MixinMatchOrders|MixinProtocolFees|MixinSignatureValidator|MixinTransactions|MixinTransferSimulator|MixinWrapperFunctions|ReentrancyTester|TestAssetProxyDispatcher|TestExchangeInternals|TestLibExchangeRichErrorDecoder|TestProtocolFees|TestProtocolFeesReceiver|TestSignatureValidator|TestTransactions|TestValidatorWallet|TestWrapperFunctions).json", + "abis": "./generated-artifacts/@(Exchange|IAssetProxy|IAssetProxyDispatcher|IEIP1271Data|IEIP1271Wallet|IExchange|IExchangeCore|IMatchOrders|IProtocolFees|ISignatureValidator|ITransactions|ITransferSimulator|IWallet|IWrapperFunctions|IsolatedExchange|LibExchangeRichErrorDecoder|MixinAssetProxyDispatcher|MixinExchangeCore|MixinMatchOrders|MixinProtocolFees|MixinSignatureValidator|MixinTransactions|MixinTransferSimulator|MixinWrapperFunctions|ReentrancyTester|TestAssetProxyDispatcher|TestExchangeInternals|TestLibExchangeRichErrorDecoder|TestProtocolFees|TestProtocolFeesReceiver|TestSignatureValidator|TestTransactions|TestValidatorWallet|TestWrapperFunctions).json", "abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually." }, "repository": { diff --git a/contracts/exchange/src/artifacts.ts b/contracts/exchange/src/artifacts.ts index 7dd571fd74..15a1d88233 100644 --- a/contracts/exchange/src/artifacts.ts +++ b/contracts/exchange/src/artifacts.ts @@ -8,6 +8,7 @@ import { ContractArtifact } from 'ethereum-types'; import * as Exchange from '../generated-artifacts/Exchange.json'; import * as IAssetProxy from '../generated-artifacts/IAssetProxy.json'; import * as IAssetProxyDispatcher from '../generated-artifacts/IAssetProxyDispatcher.json'; +import * as IEIP1271Data from '../generated-artifacts/IEIP1271Data.json'; import * as IEIP1271Wallet from '../generated-artifacts/IEIP1271Wallet.json'; import * as IExchange from '../generated-artifacts/IExchange.json'; import * as IExchangeCore from '../generated-artifacts/IExchangeCore.json'; @@ -50,6 +51,7 @@ export const artifacts = { MixinWrapperFunctions: MixinWrapperFunctions as ContractArtifact, IAssetProxy: IAssetProxy as ContractArtifact, IAssetProxyDispatcher: IAssetProxyDispatcher as ContractArtifact, + IEIP1271Data: IEIP1271Data as ContractArtifact, IEIP1271Wallet: IEIP1271Wallet as ContractArtifact, IExchange: IExchange as ContractArtifact, IExchangeCore: IExchangeCore as ContractArtifact, diff --git a/contracts/exchange/src/wrappers.ts b/contracts/exchange/src/wrappers.ts index 9d6cda62ee..f5d76edb4d 100644 --- a/contracts/exchange/src/wrappers.ts +++ b/contracts/exchange/src/wrappers.ts @@ -6,6 +6,7 @@ export * from '../generated-wrappers/exchange'; export * from '../generated-wrappers/i_asset_proxy'; export * from '../generated-wrappers/i_asset_proxy_dispatcher'; +export * from '../generated-wrappers/i_e_i_p1271_data'; export * from '../generated-wrappers/i_e_i_p1271_wallet'; export * from '../generated-wrappers/i_exchange'; export * from '../generated-wrappers/i_exchange_core'; diff --git a/contracts/exchange/tsconfig.json b/contracts/exchange/tsconfig.json index 382a04a52d..6783d6851e 100644 --- a/contracts/exchange/tsconfig.json +++ b/contracts/exchange/tsconfig.json @@ -6,6 +6,7 @@ "generated-artifacts/Exchange.json", "generated-artifacts/IAssetProxy.json", "generated-artifacts/IAssetProxyDispatcher.json", + "generated-artifacts/IEIP1271Data.json", "generated-artifacts/IEIP1271Wallet.json", "generated-artifacts/IExchange.json", "generated-artifacts/IExchangeCore.json",