diff options
author | Jacob Evans <jacob@dekz.net> | 2018-06-19 11:30:13 +0800 |
---|---|---|
committer | Jacob Evans <jacob@dekz.net> | 2018-06-19 15:32:17 +0800 |
commit | 560a55bfd1a05bda0d4fb4b97d76e9ea0d9301a7 (patch) | |
tree | db144ad73789e2e8196a377507e9f38690c64d2f /packages/contracts | |
parent | 190eafc30e2e444ed15b76217a6162ec04b33f73 (diff) | |
download | dexon-sol-tools-560a55bfd1a05bda0d4fb4b97d76e9ea0d9301a7.tar.gz dexon-sol-tools-560a55bfd1a05bda0d4fb4b97d76e9ea0d9301a7.tar.zst dexon-sol-tools-560a55bfd1a05bda0d4fb4b97d76e9ea0d9301a7.zip |
Optimize and remove redundant encodePacked
Diffstat (limited to 'packages/contracts')
4 files changed, 23 insertions, 13 deletions
diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/MixinTransactions.sol b/packages/contracts/src/contracts/current/protocol/Exchange/MixinTransactions.sol index 9bdaa0f8f..f1332363c 100644 --- a/packages/contracts/src/contracts/current/protocol/Exchange/MixinTransactions.sol +++ b/packages/contracts/src/contracts/current/protocol/Exchange/MixinTransactions.sol @@ -53,14 +53,14 @@ contract MixinTransactions is /// @return EIP712 hash of the Transaction. function hashZeroExTransaction(uint256 salt, address signer, bytes data) internal - view + pure returns (bytes32) { - return keccak256(abi.encodePacked( + return keccak256(abi.encode( EIP712_ZEROEX_TRANSACTION_SCHEMA_HASH, salt, - bytes32(signer), - keccak256(abi.encodePacked(data)) + signer, + keccak256(data) )); } diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/libs/LibEIP712.sol b/packages/contracts/src/contracts/current/protocol/Exchange/libs/LibEIP712.sol index 991137f32..b983347a4 100644 --- a/packages/contracts/src/contracts/current/protocol/Exchange/libs/LibEIP712.sol +++ b/packages/contracts/src/contracts/current/protocol/Exchange/libs/LibEIP712.sol @@ -22,6 +22,12 @@ contract LibEIP712 { // EIP191 header for EIP712 prefix string constant EIP191_HEADER = "\x19\x01"; + // EIP712 Domain Name value + string constant EIP712_DOMAIN_NAME = "0x Protocol"; + + // EIP712 Domain Version value + string constant EIP712_DOMAIN_VERSION = "2"; + // Hash of the EIP712 Domain Separator Schema bytes32 public constant EIP712_DOMAIN_SEPARATOR_SCHEMA_HASH = keccak256(abi.encodePacked( "EIP712Domain(", @@ -35,16 +41,19 @@ contract LibEIP712 { bytes32 public EIP712_DOMAIN_HASH; constructor () - public + public { - EIP712_DOMAIN_HASH = keccak256(abi.encodePacked( + EIP712_DOMAIN_HASH = keccak256(abi.encode( EIP712_DOMAIN_SEPARATOR_SCHEMA_HASH, - keccak256(abi.encodePacked("0x Protocol")), - keccak256(abi.encodePacked("2")), - bytes32(address(this)) + keccak256(bytes(EIP712_DOMAIN_NAME)), + keccak256(bytes(EIP712_DOMAIN_VERSION)), + address(this) )); } + /// @dev Calculates EIP712 encoding for a hash struct in this EIP712 Domain. + /// @param hashStruct The EIP712 hash struct. + /// @return EIP712 hash applied to this EIP712 Domain. function hashEIP712Message(bytes32 hashStruct) internal view 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 04374f1d0..b21de6927 100644 --- a/packages/contracts/src/contracts/current/protocol/Exchange/libs/LibOrder.sol +++ b/packages/contracts/src/contracts/current/protocol/Exchange/libs/LibOrder.sol @@ -99,6 +99,8 @@ contract LibOrder is pure returns (bytes32) { + // Note: changing this to abi.encode results in an error on 0.4.24 + // UnimplementedFeatureError: Variable inaccessible, too deep inside stack (17) return keccak256(abi.encodePacked( EIP712_ORDER_SCHEMA_HASH, bytes32(order.makerAddress), @@ -111,8 +113,8 @@ contract LibOrder is order.takerFee, order.expirationTimeSeconds, order.salt, - keccak256(abi.encodePacked(order.makerAssetData)), - keccak256(abi.encodePacked(order.takerAssetData)) + keccak256(order.makerAssetData), + keccak256(order.takerAssetData) )); } } diff --git a/packages/contracts/src/utils/transaction_factory.ts b/packages/contracts/src/utils/transaction_factory.ts index c0a32b83a..19ef4e1bf 100644 --- a/packages/contracts/src/utils/transaction_factory.ts +++ b/packages/contracts/src/utils/transaction_factory.ts @@ -1,4 +1,4 @@ -import { crypto, EIP712Schema, EIP712Types, EIP712Utils, generatePseudoRandomSalt } from '@0xproject/order-utils'; +import { EIP712Schema, EIP712Types, EIP712Utils, generatePseudoRandomSalt } from '@0xproject/order-utils'; import { SignatureType } from '@0xproject/types'; import * as ethUtil from 'ethereumjs-util'; @@ -24,7 +24,6 @@ export class TransactionFactory { this._signerBuff = ethUtil.privateToAddress(this._privateKey); } public newSignedTransaction(data: string, signatureType: SignatureType = SignatureType.EthSign): SignedTransaction { - const executeTransactionSchemaHashBuff = EIP712Utils.compileSchema(EIP712_ZEROEX_TRANSACTION_SCHEMA); const salt = generatePseudoRandomSalt(); const signer = `0x${this._signerBuff.toString('hex')}`; const executeTransactionData = { |