diff options
author | Remco Bloemen <remco@wicked.ventures> | 2018-06-19 18:55:04 +0800 |
---|---|---|
committer | Remco Bloemen <remco@wicked.ventures> | 2018-06-19 18:55:04 +0800 |
commit | 9a2e023a514e9204a1c91ee7d9032b61fbd157de (patch) | |
tree | dd5918b3d13ebfbd879bb4bf753fa1257ea9eb21 /packages/contracts/src | |
parent | 560a55bfd1a05bda0d4fb4b97d76e9ea0d9301a7 (diff) | |
download | dexon-sol-tools-9a2e023a514e9204a1c91ee7d9032b61fbd157de.tar dexon-sol-tools-9a2e023a514e9204a1c91ee7d9032b61fbd157de.tar.gz dexon-sol-tools-9a2e023a514e9204a1c91ee7d9032b61fbd157de.tar.bz2 dexon-sol-tools-9a2e023a514e9204a1c91ee7d9032b61fbd157de.tar.lz dexon-sol-tools-9a2e023a514e9204a1c91ee7d9032b61fbd157de.tar.xz dexon-sol-tools-9a2e023a514e9204a1c91ee7d9032b61fbd157de.tar.zst dexon-sol-tools-9a2e023a514e9204a1c91ee7d9032b61fbd157de.zip |
Assembler orderHash function
Diffstat (limited to 'packages/contracts/src')
-rw-r--r-- | packages/contracts/src/contracts/current/protocol/Exchange/libs/LibOrder.sol | 40 |
1 files changed, 22 insertions, 18 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 b21de6927..cf9df2c3d 100644 --- a/packages/contracts/src/contracts/current/protocol/Exchange/libs/LibOrder.sol +++ b/packages/contracts/src/contracts/current/protocol/Exchange/libs/LibOrder.sol @@ -97,24 +97,28 @@ contract LibOrder is function hashOrder(Order memory order) internal pure - returns (bytes32) + returns (bytes32 result) { - // 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), - bytes32(order.takerAddress), - bytes32(order.feeRecipientAddress), - bytes32(order.senderAddress), - order.makerAssetAmount, - order.takerAssetAmount, - order.makerFee, - order.takerFee, - order.expirationTimeSeconds, - order.salt, - keccak256(order.makerAssetData), - keccak256(order.takerAssetData) - )); + bytes32 schemaHash = EIP712_ORDER_SCHEMA_HASH; + bytes32 makerAssetDataHash = keccak256(order.makerAssetData); + bytes32 takerAssetDataHash = keccak256(order.takerAssetData); + assembly { + // Backup + let temp1 := mload(sub(order, 32)) + let temp2 := mload(add(order, 320)) + let temp3 := mload(add(order, 352)) + + // Hash in place + mstore(sub(order, 32), schemaHash) + mstore(add(order, 320), makerAssetDataHash) + mstore(add(order, 352), takerAssetDataHash) + result := keccak256(sub(order, 32), 416) + + // Restore + mstore(sub(order, 32), temp1) + mstore(add(order, 320), temp2) + mstore(add(order, 352), temp3) + } + return result; } } |