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;
},

View File

@ -19,31 +19,35 @@
pragma solidity ^0.5.5;
// solhint-disable max-line-length
// solhint-disable max-line-length, var-name-mixedcase
contract LibConstants {
// Asset data for ZRX token. Used for fee transfers.
// @TODO: Hardcode constant when we deploy. Currently
// @TODO: Hardcode constant when we deploy. Currently
// not constant to make testing easier.
// The proxyId for ZRX_ASSET_DATA is bytes4(keccak256("ERC20Token(address)")) = 0xf47261b0
// Kovan ZRX address is 0x6ff6c0ff1d68b964901f986d4c9fa3ac68346570.
// The ABI encoded proxyId and address is 0xf47261b00000000000000000000000006ff6c0ff1d68b964901f986d4c9fa3ac68346570
// bytes constant public ZRX_ASSET_DATA = "\xf4\x72\x61\xb0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x6f\xf6\xc0\xff\x1d\x68\xb9\x64\x90\x1f\x98\x6d\x4c\x9f\xa3\xac\x68\x34\x65\x70";
// Mainnet ZRX address is 0xe41d2489571d322189246dafa5ebde1f4699f498.
// The ABI encoded proxyId and address is 0xf47261b0000000000000000000000000e41d2489571d322189246dafa5ebde1f4699f498
// bytes constant public ZRX_ASSET_DATA = "\xf4\x72\x61\xb0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xe4\x1d\x24\x89\x57\x1d\x32\x21\x89\x24\x6d\xaf\xa5\xeb\xde\x1f\x46\x99\xf4\x98";
// solhint-disable-next-line var-name-mixedcase
bytes public ZRX_ASSET_DATA;
// @TODO: Remove when we deploy.
constructor (bytes memory zrxAssetData)
// The chain ID of the network this contract is deployed on.
uint256 public CHAIN_ID;
/// @param zrxAssetData Asset data for ZRX token. Used for fee transfers.
/// @param chainId Chain ID of the network this contract is deployed on.
constructor (bytes memory zrxAssetData, uint256 chainId)
public
{
ZRX_ASSET_DATA = zrxAssetData;
CHAIN_ID = chainId;
}
}
// solhint-enable max-line-length

View File

@ -18,8 +18,11 @@
pragma solidity ^0.5.5;
import "./LibConstants.sol";
contract LibEIP712 {
contract LibEIP712 is
LibConstants
{
// EIP191 header for EIP712 prefix
string constant internal EIP191_HEADER = "\x19\x01";
@ -28,13 +31,14 @@ contract LibEIP712 {
string constant internal EIP712_DOMAIN_NAME = "0x Protocol";
// EIP712 Domain Version value
string constant internal EIP712_DOMAIN_VERSION = "2";
string constant internal EIP712_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",
")"
));
@ -50,6 +54,7 @@ contract LibEIP712 {
EIP712_DOMAIN_SEPARATOR_SCHEMA_HASH,
keccak256(bytes(EIP712_DOMAIN_NAME)),
keccak256(bytes(EIP712_DOMAIN_VERSION)),
CHAIN_ID,
uint256(address(this))
));
}
@ -68,7 +73,7 @@ contract LibEIP712 {
// keccak256(abi.encodePacked(
// EIP191_HEADER,
// EIP712_DOMAIN_HASH,
// hashStruct
// hashStruct
// ));
assembly {

View File

@ -39,10 +39,12 @@ contract Exchange is
{
string constant public VERSION = "3.0.0";
// Mixins are instantiated in the order they are inherited
constructor (bytes memory _zrxAssetData)
/// @dev Mixins are instantiated in the order they are inherited
/// @param _zrxAssetData Asset data for ZRX token. Used for fee transfers.
/// @param _chainId Chain ID of the network this contract is deployed on.
constructor (bytes memory _zrxAssetData, uint256 _chainId)
public
LibConstants(_zrxAssetData) // @TODO: Remove when we deploy.
LibConstants(_zrxAssetData, ) // @TODO: Remove _zrxAssetData when we deploy.
MixinExchangeCore()
MixinMatchOrders()
MixinSignatureValidator()