diff options
author | Greg Hysen <greg.hysen@gmail.com> | 2018-06-22 06:16:26 +0800 |
---|---|---|
committer | Greg Hysen <greg.hysen@gmail.com> | 2018-06-22 09:49:17 +0800 |
commit | 2d8e9eda56f1455d5d5de61924c9c061e64756f5 (patch) | |
tree | 1e2b096f5ca20d3035a3759433db1d02e838fb96 /packages/contracts/src | |
parent | 7c0fdc7ecf170e17aa27cb88a2b62a02ea49ca41 (diff) | |
download | dexon-sol-tools-2d8e9eda56f1455d5d5de61924c9c061e64756f5.tar dexon-sol-tools-2d8e9eda56f1455d5d5de61924c9c061e64756f5.tar.gz dexon-sol-tools-2d8e9eda56f1455d5d5de61924c9c061e64756f5.tar.bz2 dexon-sol-tools-2d8e9eda56f1455d5d5de61924c9c061e64756f5.tar.lz dexon-sol-tools-2d8e9eda56f1455d5d5de61924c9c061e64756f5.tar.xz dexon-sol-tools-2d8e9eda56f1455d5d5de61924c9c061e64756f5.tar.zst dexon-sol-tools-2d8e9eda56f1455d5d5de61924c9c061e64756f5.zip |
Converted `hashZeroExTransaction` to assembly. Saves 1k gas
Diffstat (limited to 'packages/contracts/src')
-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..86f7c7b72 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), signerAddress) + mstore(add(memPtr, 96), dataHash) + result := keccak256(memPtr, 128) + } + + return result; } /// @dev Executes an exchange method call in the context of signer. |