Update exchange and coordinator contracts to incorporate chainID in their domain separators.

This commit is contained in:
Lawrence Forman
2019-03-21 11:11:54 -04:00
committed by Amir Bandeali
parent 5b1cbbf157
commit 964d8171dd
7 changed files with 53 additions and 23 deletions

View File

@@ -20,6 +20,7 @@ pragma solidity ^0.5.5;
pragma experimental "ABIEncoderV2";
import "./libs/LibConstants.sol";
import "./libs/LibEIP712Domain.sol";
import "./MixinSignatureValidator.sol";
import "./MixinCoordinatorApprovalVerifier.sol";
import "./MixinCoordinatorCore.sol";
@@ -28,12 +29,15 @@ import "./MixinCoordinatorCore.sol";
// solhint-disable no-empty-blocks
contract Coordinator is
LibConstants,
LibEIP712Domain,
MixinSignatureValidator,
MixinCoordinatorApprovalVerifier,
MixinCoordinatorCore
{
constructor (address _exchange)
/// @param _exchange Address of the 0x Exchange contract.
/// @param _chainId Chain ID of the network this contract is deployed on.
constructor (address _exchange, uint256 _chainId)
public
LibConstants(_exchange)
LibConstants(_exchange, _chainId)
{}
}

View File

@@ -21,14 +21,20 @@ pragma solidity ^0.5.5;
import "../interfaces/ITransactions.sol";
// solhint-disable var-name-mixedcase
contract LibConstants {
// solhint-disable-next-line var-name-mixedcase
// The 0x Exchange contract.
ITransactions internal EXCHANGE;
// The numerical ID of the network this contract is deployed on.
uint256 internal CHAIN_ID;
constructor (address _exchange)
/// @param _exchange Address of the 0x Exchange contract.
/// @param _chainId Chain ID of the network this contract is deployed on.
constructor (address _exchange, uint256 _chainId)
public
{
EXCHANGE = ITransactions(_exchange);
CHAIN_ID = _chainId;
}
}

View File

@@ -21,6 +21,7 @@ pragma solidity ^0.5.5;
import "./LibConstants.sol";
// solhint-disable var-name-mixedcase
contract LibEIP712Domain is
LibConstants
{
@@ -38,23 +39,22 @@ contract LibEIP712Domain is
string constant internal EIP712_EXCHANGE_DOMAIN_NAME = "0x Protocol";
// EIP712 Domain Version value for the Exchange
string constant internal EIP712_EXCHANGE_DOMAIN_VERSION = "2";
string constant internal EIP712_EXCHANGE_DOMAIN_VERSION = "3.0.0";
// Hash of the EIP712 Domain Separator Schema
bytes32 constant internal EIP712_DOMAIN_SEPARATOR_SCHEMA_HASH = keccak256(abi.encodePacked(
"EIP712Domain(",
"string name,",
"string version,",
"uint256 chainId",
"address verifyingContract",
")"
));
// Hash of the EIP712 Domain Separator data for the Coordinator
// solhint-disable-next-line var-name-mixedcase
bytes32 public EIP712_COORDINATOR_DOMAIN_HASH;
// Hash of the EIP712 Domain Separator data for the Exchange
// solhint-disable-next-line var-name-mixedcase
bytes32 public EIP712_EXCHANGE_DOMAIN_HASH;
constructor ()
@@ -64,6 +64,7 @@ contract LibEIP712Domain is
EIP712_DOMAIN_SEPARATOR_SCHEMA_HASH,
keccak256(bytes(EIP712_COORDINATOR_DOMAIN_NAME)),
keccak256(bytes(EIP712_COORDINATOR_DOMAIN_VERSION)),
CHAIN_ID,
uint256(address(this))
));
@@ -71,6 +72,7 @@ contract LibEIP712Domain is
EIP712_DOMAIN_SEPARATOR_SCHEMA_HASH,
keccak256(bytes(EIP712_EXCHANGE_DOMAIN_NAME)),
keccak256(bytes(EIP712_EXCHANGE_DOMAIN_VERSION)),
CHAIN_ID,
uint256(address(EXCHANGE))
));
}

View File

@@ -6,6 +6,7 @@ import * as _ from 'lodash';
export const hashUtils = {
getApprovalHashBuffer(
transaction: SignedZeroExTransaction,
chainId: BigNumber,
verifyingContractAddress: string,
txOrigin: string,
approvalExpirationTimeSeconds: BigNumber,
@@ -21,12 +22,18 @@ export const hashUtils = {
},
getApprovalHashHex(
transaction: SignedZeroExTransaction,
chainId: BigNumber,
verifyingContractAddress: string,
txOrigin: string,
approvalExpirationTimeSeconds: BigNumber,
): string {
const hashHex = `0x${hashUtils
.getApprovalHashBuffer(transaction, verifyingContractAddress, txOrigin, approvalExpirationTimeSeconds)
.getApprovalHashBuffer(
transaction,
chainId,
verifyingContractAddress,
txOrigin,
approvalExpirationTimeSeconds)
.toString('hex')}`;
return hashHex;
},