aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorJacob Evans <dekz@dekz.net>2018-06-20 08:25:31 +0800
committerGitHub <noreply@github.com>2018-06-20 08:25:31 +0800
commitebbcbeedd24934dbf4139ea5b74691a2254c2e81 (patch)
treedd5918b3d13ebfbd879bb4bf753fa1257ea9eb21 /packages
parent560a55bfd1a05bda0d4fb4b97d76e9ea0d9301a7 (diff)
parent9a2e023a514e9204a1c91ee7d9032b61fbd157de (diff)
downloaddexon-sol-tools-ebbcbeedd24934dbf4139ea5b74691a2254c2e81.tar
dexon-sol-tools-ebbcbeedd24934dbf4139ea5b74691a2254c2e81.tar.gz
dexon-sol-tools-ebbcbeedd24934dbf4139ea5b74691a2254c2e81.tar.bz2
dexon-sol-tools-ebbcbeedd24934dbf4139ea5b74691a2254c2e81.tar.lz
dexon-sol-tools-ebbcbeedd24934dbf4139ea5b74691a2254c2e81.tar.xz
dexon-sol-tools-ebbcbeedd24934dbf4139ea5b74691a2254c2e81.tar.zst
dexon-sol-tools-ebbcbeedd24934dbf4139ea5b74691a2254c2e81.zip
Merge pull request #730 from 0xProject/bug/contracts/eip712-191-prefix-asm-orderhash
Assembler orderHash function
Diffstat (limited to 'packages')
-rw-r--r--packages/contracts/src/contracts/current/protocol/Exchange/libs/LibOrder.sol40
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;
}
}