diff options
author | Jacob Evans <jacob@dekz.net> | 2018-05-08 13:31:56 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-05-25 07:00:22 +0800 |
commit | 65676c22f92996feb0e3cb98daa3d8ce7b3854e9 (patch) | |
tree | 640f76ff3186b3360bad2806272b6aa4f5974f2a /packages | |
parent | bc550c3265cfcb92785d90c075a120d8c90d15f7 (diff) | |
download | dexon-sol-tools-65676c22f92996feb0e3cb98daa3d8ce7b3854e9.tar dexon-sol-tools-65676c22f92996feb0e3cb98daa3d8ce7b3854e9.tar.gz dexon-sol-tools-65676c22f92996feb0e3cb98daa3d8ce7b3854e9.tar.bz2 dexon-sol-tools-65676c22f92996feb0e3cb98daa3d8ce7b3854e9.tar.lz dexon-sol-tools-65676c22f92996feb0e3cb98daa3d8ce7b3854e9.tar.xz dexon-sol-tools-65676c22f92996feb0e3cb98daa3d8ce7b3854e9.tar.zst dexon-sol-tools-65676c22f92996feb0e3cb98daa3d8ce7b3854e9.zip |
Update order hash to match latest eip712
Diffstat (limited to 'packages')
4 files changed, 57 insertions, 34 deletions
diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/libs/LibOrder.sol b/packages/contracts/src/contracts/current/protocol/Exchange/libs/LibOrder.sol index 7d8328c67..34ea62ef1 100644 --- a/packages/contracts/src/contracts/current/protocol/Exchange/libs/LibOrder.sol +++ b/packages/contracts/src/contracts/current/protocol/Exchange/libs/LibOrder.sol @@ -21,19 +21,21 @@ pragma solidity ^0.4.24; contract LibOrder { bytes32 constant ORDER_SCHEMA_HASH = keccak256( - "address exchangeAddress", - "address makerAddress", - "address takerAddress", - "address feeRecipientAddress", - "address senderAddress", - "uint256 makerAssetAmount", - "uint256 takerAssetAmount", - "uint256 makerFee", - "uint256 takerFee", - "uint256 expirationTimeSeconds", - "uint256 salt", - "bytes makerAssetData", - "bytes takerAssetData" + "Order(", + "address exchangeAddress,", + "address makerAddress,", + "address takerAddress,", + "address feeRecipientAddress,", + "address senderAddress,", + "uint256 makerAssetAmount,", + "uint256 takerAssetAmount,", + "uint256 makerFee,", + "uint256 takerFee,", + "uint256 expirationTimeSeconds,", + "uint256 salt,", + "bytes makerAssetData,", + "bytes takerAssetData,", + ")" ); struct Order { @@ -84,8 +86,8 @@ contract LibOrder { order.takerFee, order.expirationTimeSeconds, order.salt, - order.makerAssetData, - order.takerAssetData + keccak256(order.makerAssetData), + keccak256(order.takerAssetData) ) ); return orderHash; diff --git a/packages/contracts/src/contracts/current/test/TestLibs/TestLibs.sol b/packages/contracts/src/contracts/current/test/TestLibs/TestLibs.sol index b8fc90af1..ed0c282af 100644 --- a/packages/contracts/src/contracts/current/test/TestLibs/TestLibs.sol +++ b/packages/contracts/src/contracts/current/test/TestLibs/TestLibs.sol @@ -69,6 +69,14 @@ contract TestLibs is return orderHash; } + function publicGetOrderSchemaHash() + public + view + returns (bytes32) + { + return ORDER_SCHEMA_HASH; + } + function publicAddFillResults(FillResults memory totalFillResults, FillResults memory singleFillResults) public pure diff --git a/packages/contracts/src/utils/order_utils.ts b/packages/contracts/src/utils/order_utils.ts index 8adc6b735..688259b6c 100644 --- a/packages/contracts/src/utils/order_utils.ts +++ b/packages/contracts/src/utils/order_utils.ts @@ -1,7 +1,5 @@ import { BigNumber } from '@0xproject/utils'; -import { Web3Wrapper } from '@0xproject/web3-wrapper'; import ethUtil = require('ethereumjs-util'); -import * as _ from 'lodash'; import { crypto } from './crypto'; import { CancelOrder, MatchOrder, OrderStruct, SignatureType, SignedOrder, UnsignedOrder } from './types'; @@ -39,22 +37,31 @@ export const orderUtils = { }; return orderStruct; }, - getOrderHashBuff(order: SignedOrder | UnsignedOrder): Buffer { + getOrderSchemaHex(): string { const orderSchemaHashBuff = crypto.solSHA3([ - 'address exchangeAddress', - 'address makerAddress', - 'address takerAddress', - 'address feeRecipientAddress', - 'address senderAddress', - 'uint256 makerAssetAmount', - 'uint256 takerAssetAmount', - 'uint256 makerFee', - 'uint256 takerFee', - 'uint256 expirationTimeSeconds', - 'uint256 salt', - 'bytes makerAssetData', - 'bytes takerAssetData', + 'Order(', + 'address exchangeAddress,', + 'address makerAddress,', + 'address takerAddress,', + 'address feeRecipientAddress,', + 'address senderAddress,', + 'uint256 makerAssetAmount,', + 'uint256 takerAssetAmount,', + 'uint256 makerFee,', + 'uint256 takerFee,', + 'uint256 expirationTimeSeconds,', + 'uint256 salt,', + 'bytes makerAssetData,', + 'bytes takerAssetData,', + ')', ]); + const schemaHashHex = `0x${orderSchemaHashBuff.toString('hex')}`; + return schemaHashHex; + }, + getOrderHashBuff(order: SignedOrder | UnsignedOrder): Buffer { + const makerAssetDataHash = crypto.solSHA3([ethUtil.toBuffer(order.makerAssetData)]); + const takerAssetDataHash = crypto.solSHA3([ethUtil.toBuffer(order.takerAssetData)]); + const orderParamsHashBuff = crypto.solSHA3([ order.exchangeAddress, order.makerAddress, @@ -67,11 +74,11 @@ export const orderUtils = { order.takerFee, order.expirationTimeSeconds, order.salt, - ethUtil.toBuffer(order.makerAssetData), - ethUtil.toBuffer(order.takerAssetData), + makerAssetDataHash, + takerAssetDataHash, ]); - const orderSchemaHashHex = `0x${orderSchemaHashBuff.toString('hex')}`; const orderParamsHashHex = `0x${orderParamsHashBuff.toString('hex')}`; + const orderSchemaHashHex = orderUtils.getOrderSchemaHex(); const orderHashBuff = crypto.solSHA3([new BigNumber(orderSchemaHashHex), new BigNumber(orderParamsHashHex)]); return orderHashBuff; }, diff --git a/packages/contracts/test/exchange/libs.ts b/packages/contracts/test/exchange/libs.ts index 5c530a9b1..f4a6d04a3 100644 --- a/packages/contracts/test/exchange/libs.ts +++ b/packages/contracts/test/exchange/libs.ts @@ -56,6 +56,12 @@ describe('Exchange libs', () => { }); describe('LibOrder', () => { + describe('getOrderSchema', () => { + it('should output the correct orderHash', async () => { + const orderSchema = await libs.publicGetOrderSchemaHash.callAsync(); + expect(orderUtils.getOrderSchemaHex()).to.be.equal(orderSchema); + }); + }); describe('getOrderHash', () => { it('should output the correct orderHash', async () => { const orderHashHex = await libs.publicGetOrderHash.callAsync(signedOrder); |