diff options
author | Amir Bandeali <abandeali1@gmail.com> | 2018-06-23 07:57:50 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-23 07:57:50 +0800 |
commit | 26cacfa247fcd07368d3a5bfb7a99aa0b47797ef (patch) | |
tree | 5e05c34211343956cfc0413d347eb4773713614c /packages/contracts | |
parent | 1f5848ba8265885ef4644a8103029552782965c8 (diff) | |
parent | 7fcd34eb3656a49eaac684ee3cb1b7d55d9e15e6 (diff) | |
download | dexon-sol-tools-26cacfa247fcd07368d3a5bfb7a99aa0b47797ef.tar dexon-sol-tools-26cacfa247fcd07368d3a5bfb7a99aa0b47797ef.tar.gz dexon-sol-tools-26cacfa247fcd07368d3a5bfb7a99aa0b47797ef.tar.bz2 dexon-sol-tools-26cacfa247fcd07368d3a5bfb7a99aa0b47797ef.tar.lz dexon-sol-tools-26cacfa247fcd07368d3a5bfb7a99aa0b47797ef.tar.xz dexon-sol-tools-26cacfa247fcd07368d3a5bfb7a99aa0b47797ef.tar.zst dexon-sol-tools-26cacfa247fcd07368d3a5bfb7a99aa0b47797ef.zip |
Merge pull request #749 from 0xProject/feature/contracts/transactionHashAsm
Converted `hashZeroExTransaction` to assembly. Saves 1k gas
Diffstat (limited to 'packages/contracts')
-rw-r--r-- | packages/contracts/src/contracts/current/protocol/Exchange/MixinTransactions.sol | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/MixinTransactions.sol b/packages/contracts/src/contracts/current/protocol/Exchange/MixinTransactions.sol index d3d22d48f..20a4a12df 100644 --- a/packages/contracts/src/contracts/current/protocol/Exchange/MixinTransactions.sol +++ b/packages/contracts/src/contracts/current/protocol/Exchange/MixinTransactions.sol @@ -51,17 +51,27 @@ contract MixinTransactions is /// @param signerAddress Address of transaction signer. /// @param data AbiV2 encoded calldata. /// @return EIP712 hash of the Transaction. - function hashZeroExTransaction(uint256 salt, address signerAddress, bytes data) + function hashZeroExTransaction( + uint256 salt, + address signerAddress, + bytes memory data + ) internal pure - returns (bytes32) + returns (bytes32 result) { - return keccak256(abi.encode( - EIP712_ZEROEX_TRANSACTION_SCHEMA_HASH, - salt, - signerAddress, - keccak256(data) - )); + bytes32 schemaHash = EIP712_ZEROEX_TRANSACTION_SCHEMA_HASH; + bytes32 dataHash = keccak256(data); + assembly { + let memPtr := mload(64) + mstore(memPtr, schemaHash) + mstore(add(memPtr, 32), salt) + mstore(add(memPtr, 64), and(signerAddress, 0xffffffffffffffffffffffffffffffffffffffff)) + mstore(add(memPtr, 96), dataHash) + result := keccak256(memPtr, 128) + } + + return result; } /// @dev Executes an exchange method call in the context of signer. |