From 509c76b1a3ea8039ec502435fc205b5c72939223 Mon Sep 17 00:00:00 2001 From: Remco Bloemen Date: Tue, 13 Feb 2018 15:27:43 -0800 Subject: [PATCH] Implement EIP712 at verify-signature call site --- .../current/protocol/Exchange/LibOrder.sol | 17 +++++++++++++- .../protocol/Exchange/MixinExchangeCore.sol | 4 ++-- .../Exchange/MixinSignatureValidator.sol | 23 +------------------ 3 files changed, 19 insertions(+), 25 deletions(-) diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/LibOrder.sol b/packages/contracts/src/contracts/current/protocol/Exchange/LibOrder.sol index f4d0315103..7f01fc1b7f 100644 --- a/packages/contracts/src/contracts/current/protocol/Exchange/LibOrder.sol +++ b/packages/contracts/src/contracts/current/protocol/Exchange/LibOrder.sol @@ -19,7 +19,22 @@ pragma solidity ^0.4.19; contract LibOrder { - + + bytes32 constant orderSchemaHash = keccak256( + "address exchangeContractAddress", + "address makerAddress", + "address takerAddress", + "address makerTokenAddress", + "address takerTokenAddress", + "address feeRecipientAddress", + "uint256 makerTokenAmount", + "uint256 takerTokenAmount", + "uint256 makerFeeAmount", + "uint256 takerFeeAmount", + "uint256 expirationTimestamp", + "uint256 salt" + ); + struct Order { address maker; address taker; diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/MixinExchangeCore.sol b/packages/contracts/src/contracts/current/protocol/Exchange/MixinExchangeCore.sol index 4f7c3d4a12..7000f63891 100644 --- a/packages/contracts/src/contracts/current/protocol/Exchange/MixinExchangeCore.sol +++ b/packages/contracts/src/contracts/current/protocol/Exchange/MixinExchangeCore.sol @@ -102,7 +102,7 @@ contract MixinExchangeCore is require(order.makerTokenAmount > 0); require(order.takerTokenAmount > 0); require(isValidSignature( - order.orderHash, + keccak256(orderSchemaHash, order.orderHash), order.maker, signature )); @@ -188,7 +188,7 @@ contract MixinExchangeCore is require(order.takerTokenAmount > 0); require(takerTokenCancelAmount > 0); require(isValidSignature( - order.orderHash, + keccak256(orderSchemaHash, order.orderHash), order.maker, signature )); diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol b/packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol index 179b1b02c7..e243eade13 100644 --- a/packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol +++ b/packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol @@ -32,22 +32,6 @@ contract MixinSignatureValidator is EIP712, Contract } - - bytes32 public constant orderSchemaHash = keccak256( - "address exchangeContractAddress", - "address makerAddress", - "address takerAddress", - "address makerTokenAddress", - "address takerTokenAddress", - "address feeRecipientAddress", - "uint256 makerTokenAmount", - "uint256 takerTokenAmount", - "uint256 makerFeeAmount", - "uint256 takerFeeAmount", - "uint256 expirationTimestamp", - "uint256 salt" - ); - function isValidSignature( bytes32 hash, @@ -98,12 +82,7 @@ contract MixinSignatureValidator is v = uint8(signature[1]); r = get32(signature, 2); s = get32(signature, 35); - address recovered = ecrecover( - keccak256(orderSchemaHash, orderHash), - v, - r, - s - ); + address recovered = ecrecover(hash, v, r, s); isValid = signer == recovered; return;