-
Notifications
You must be signed in to change notification settings - Fork 465
[3.0] Add chain ID to EIP 712 domains #1742
[3.0] Add chain ID to EIP 712 domains #1742
Conversation
…heir domain separators.
Add `chainId` to constructors for all test contracts deriving from `LibEIP712.sol`
Split up EIP712 constants and functionality in `/contracts/exchange-libs` across 3, modular contracts. Make coordinator inherit from the modular EIP712 contracts in `@0x\contracts-exchange`.
…rCore` from `/contracts/extensions`.
…n domain separators.
Obey the linter gods.
Update coordinator tests for new tooling. Remove unecessary `chainId` parameter in `eip712_utils.createCoordinatorApprovalTypeData`
…s` because reentrancy guard is sort of a breaking change
51cf3d4
to
c0b2e1a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Might not be necessary but it could be worthwhile to add explicit tests for known Chain ID's / expected behavior when an unrecognized/malformed Chain ID is used client-side.
@hysz Wondering if the new tests I just added to contracts/exchange-libs/test/src/exchange_libs.ts cover this requirement. Is it sufficient to prove that |
packages/types/src/index.ts
Outdated
@@ -18,6 +18,7 @@ export interface Order { | |||
takerAssetData: string; | |||
salt: BigNumber; | |||
exchangeAddress: string; | |||
chainId: number; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than just adding the chainId
, I think we should take this opportunity to add an extra eip712Domain
field that looks like:
{
verifyingContract: ...,
chainId: ...,
name: ...,
version: ...
}
Alternatively, we can just make it a eip712DomainHash
field and do all of the calculations beforehand. This would consume less bandwidth but make it a bit harder to develop with.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went with domain
rather than eip712Domain
for the new field in the Order
and ZeroExTransaction
types for brevity. Let me know if this is fine or you'd rather be more explicit.
…LibEIP712ExchangeDomain` rather than `LibEIP712`
Add required field `domain` to `order` and `zeroExTransaction` schemas.
…abi-gen-wrappers` to use new domain schema and `Order` format.
…e`, and `extensions` contract tests to use new order and transaction structure
…racts/test-utils/.../formatters.ts`.
…racts/exchange` tests.
}; | ||
const makerPrivateKey = devConstants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(makerAddress)]; | ||
const takerPrivateKey = devConstants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(takerAddress)]; | ||
const feeRecipientPrivateKey = devConstants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(feeRecipientAddress)]; | ||
orderFactory = new OrderFactory(makerPrivateKey, defaultOrderParams); | ||
makerTransactionFactory = new TransactionFactory(makerPrivateKey, exchange.address); | ||
takerTransactionFactory = new TransactionFactory(takerPrivateKey, exchange.address); | ||
makerTransactionFactory = new TransactionFactory(makerPrivateKey, exchange.address, chainId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a blocker, but this should probably be changes later to just take a domain
parameter.
Description
This adds a
chainId
to the domain separator for the Coordinator and Exchange (as per the EIP-712 spec). For reference, the chain ID is the unique numerical ID of the network the contracts are deployed on.There are some notable consequences that come with this change, which is why this PR spans so many packages:
chainId
constructor parameter.EIP712Domain(string name,string version,uint256 chainId,address verifyingContractAddress)
@0x/types
,Order
,ZeroExTransaction
, and signed variants have had their structures changed:exchangeAddress
has been removed.domain
field has been added. This field is of the existing typeEIP712DomainWithDefaultSchema
, which has been augmented with a requiredchainId
field.@0x/utils.providerUtils
now has agetChainIdAsync()
function for retrieving the current chain ID given a provider. For testing, you can either use this function or just@0x/order-utils.constants.TESTPRC_NETWORK_ID
.@0x/test-utils.TransactionFactory
now requires achainId
constructor parameter.@0x/order-utils.OrderFactory
,createOrder()
andcreateOrderFromPartial()
now requirechainId
fields/parameters.I've also taken the liberty of breaking up
@0x/contracts-exchange-libs/contracts/src/LibEIP712.sol
into reusable components (LibEIP712
,LibEIP712ExchangeDomain
, andLibEIP712ExchangeDomainConstants
) so there is less code duplication between the Coordinator and Exchange.Testing instructions
Types of changes
Checklist:
[WIP]
if necessary.