Make contracts/exchange-libs/.../LibEIP712.sol stateless

This commit is contained in:
Lawrence Forman
2019-03-30 14:26:20 -04:00
committed by Amir Bandeali
parent a0b1f3efa2
commit e5fed57b8b
8 changed files with 28 additions and 36 deletions

View File

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

View File

@@ -27,10 +27,10 @@ contract LibConstants {
// The 0x Exchange contract. // The 0x Exchange contract.
ITransactions internal EXCHANGE; ITransactions internal EXCHANGE;
/// @param _exchange Address of the 0x Exchange contract. /// @param exchange Address of the 0x Exchange contract.
constructor (address _exchange) constructor (address exchange)
public public
{ {
EXCHANGE = ITransactions(_exchange); EXCHANGE = ITransactions(exchange);
} }
} }

View File

@@ -42,17 +42,20 @@ contract LibEIP712Domain is
// Hash of the EIP712 Domain Separator data for the Exchange // Hash of the EIP712 Domain Separator data for the Exchange
bytes32 public EIP712_EXCHANGE_DOMAIN_HASH; bytes32 public EIP712_EXCHANGE_DOMAIN_HASH;
constructor () /// @param chainId Chain ID of the network this contract is deployed on.
constructor (uint256 chainId)
public public
{ {
EIP712_COORDINATOR_DOMAIN_HASH = hashEIP712Domain( EIP712_COORDINATOR_DOMAIN_HASH = hashEIP712Domain(
EIP712_COORDINATOR_DOMAIN_NAME, EIP712_COORDINATOR_DOMAIN_NAME,
EIP712_COORDINATOR_DOMAIN_VERSION, EIP712_COORDINATOR_DOMAIN_VERSION,
chainId,
address(this) address(this)
); );
EIP712_EXCHANGE_DOMAIN_HASH = hashEIP712Domain( EIP712_EXCHANGE_DOMAIN_HASH = hashEIP712Domain(
EIP712_EXCHANGE_DOMAIN_NAME, EIP712_EXCHANGE_DOMAIN_NAME,
EIP712_EXCHANGE_DOMAIN_VERSION, EIP712_EXCHANGE_DOMAIN_VERSION,
chainId,
address(EXCHANGE) address(EXCHANGE)
); );
} }

View File

@@ -27,30 +27,20 @@ contract LibEIP712 {
"string name,", "string name,",
"string version,", "string version,",
"uint256 chainId,", "uint256 chainId,",
"address verifyingContract", "address verifyingContractAddress",
")" ")"
)); ));
// Chain ID of the network this contract is deployed on.
// solhint-disable-next-line var-name-mixedcase
uint256 internal CHAIN_ID;
/// @param chainId Chain ID of the network this contract is deployed on.
constructor (uint256 chainId)
public
{
CHAIN_ID = chainId;
}
/// @dev Calculates a EIP712 domain separator. /// @dev Calculates a EIP712 domain separator.
/// @param name The EIP712 domain name. /// @param name The EIP712 domain name.
/// @param version The EIP712 domain version. /// @param version The EIP712 domain version.
/// @param verifyingContract The EIP712 verifying contract. /// @param verifyingContractAddress The EIP712 verifying contract.
/// @return EIP712 domain separator. /// @return EIP712 domain separator.
function hashEIP712Domain( function hashEIP712Domain(
string memory name, string memory name,
string memory version, string memory version,
address verifyingContract uint256 chainId,
address verifyingContractAddress
) )
internal internal
view view
@@ -60,8 +50,8 @@ contract LibEIP712 {
EIP712_DOMAIN_SEPARATOR_SCHEMA_HASH, EIP712_DOMAIN_SEPARATOR_SCHEMA_HASH,
keccak256(bytes(name)), keccak256(bytes(name)),
keccak256(bytes(version)), keccak256(bytes(version)),
CHAIN_ID, chainId,
uint256(verifyingContract) uint256(verifyingContractAddress)
)); ));
} }

View File

@@ -30,12 +30,14 @@ contract LibEIP712ExchangeDomain is
// solhint-disable-next-line var-name-mixedcase // solhint-disable-next-line var-name-mixedcase
bytes32 internal EIP712_EXCHANGE_DOMAIN_HASH; bytes32 internal EIP712_EXCHANGE_DOMAIN_HASH;
constructor () /// @param chainId Chain ID of the network this contract is deployed on.
constructor (uint256 chainId)
public public
{ {
EIP712_EXCHANGE_DOMAIN_HASH = hashEIP712Domain( EIP712_EXCHANGE_DOMAIN_HASH = hashEIP712Domain(
EIP712_EXCHANGE_DOMAIN_NAME, EIP712_EXCHANGE_DOMAIN_NAME,
EIP712_EXCHANGE_DOMAIN_VERSION, EIP712_EXCHANGE_DOMAIN_VERSION,
chainId,
address(this) address(this)
); );
} }

View File

@@ -36,7 +36,7 @@ contract TestLibs is
{ {
constructor (uint256 chainId) constructor (uint256 chainId)
public public
LibEIP712(chainId) LibEIP712ExchangeDomain(chainId)
{} {}
function publicAbiEncodeFillOrder( function publicAbiEncodeFillOrder(

View File

@@ -20,7 +20,6 @@ pragma solidity ^0.5.5;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
import "@0x/contracts-exchange-libs/contracts/src/LibConstants.sol"; import "@0x/contracts-exchange-libs/contracts/src/LibConstants.sol";
import "@0x/contracts-exchange-libs/contracts/src/LibEIP712.sol";
import "./MixinExchangeCore.sol"; import "./MixinExchangeCore.sol";
import "./MixinSignatureValidator.sol"; import "./MixinSignatureValidator.sol";
import "./MixinWrapperFunctions.sol"; import "./MixinWrapperFunctions.sol";
@@ -41,12 +40,12 @@ contract Exchange is
string constant public VERSION = "3.0.0"; string constant public VERSION = "3.0.0";
/// @dev Mixins are instantiated in the order they are inherited /// @dev Mixins are instantiated in the order they are inherited
/// @param _zrxAssetData Asset data for ZRX token. Used for fee transfers. /// @param zrxAssetData Asset data for ZRX token. Used for fee transfers.
/// @param _chainId Chain ID of the network this contract is deployed on. /// @param chainId Chain ID of the network this contract is deployed on.
constructor (bytes memory _zrxAssetData, uint256 _chainId) constructor (bytes memory zrxAssetData, uint256 chainId)
public public
LibConstants(_zrxAssetData) // @TODO: Remove _zrxAssetData when we deploy. LibConstants(zrxAssetData) // @TODO: Remove zrxAssetData when we deploy.
LibEIP712(_chainId) LibEIP712ExchangeDomain(chainId)
MixinExchangeCore() MixinExchangeCore()
MixinMatchOrders() MixinMatchOrders()
MixinSignatureValidator() MixinSignatureValidator()

View File

@@ -32,7 +32,7 @@ contract TestSignatureValidator is
// solhint-disable no-empty-blocks // solhint-disable no-empty-blocks
constructor (uint256 chainId) constructor (uint256 chainId)
public public
LibEIP712(chainId) LibEIP712ExchangeDomain(chainId)
{} {}
function publicIsValidSignature( function publicIsValidSignature(