aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorAmir Bandeali <abandeali1@gmail.com>2018-08-08 07:27:02 +0800
committerAmir Bandeali <abandeali1@gmail.com>2018-08-09 02:15:38 +0800
commit149c07dfd2ef2e2102d66ebbdaf1268a1938f4af (patch)
tree22b847c74e8cf74ca627db10eaff1d1e7dcc4302 /packages
parent3d6cf503645386734bb552e09df2c6709e2ed45c (diff)
downloaddexon-sol-tools-149c07dfd2ef2e2102d66ebbdaf1268a1938f4af.tar
dexon-sol-tools-149c07dfd2ef2e2102d66ebbdaf1268a1938f4af.tar.gz
dexon-sol-tools-149c07dfd2ef2e2102d66ebbdaf1268a1938f4af.tar.bz2
dexon-sol-tools-149c07dfd2ef2e2102d66ebbdaf1268a1938f4af.tar.lz
dexon-sol-tools-149c07dfd2ef2e2102d66ebbdaf1268a1938f4af.tar.xz
dexon-sol-tools-149c07dfd2ef2e2102d66ebbdaf1268a1938f4af.tar.zst
dexon-sol-tools-149c07dfd2ef2e2102d66ebbdaf1268a1938f4af.zip
Use asm for hashEIP712Message, increment free memory pointer after asm hashing functions
Diffstat (limited to 'packages')
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/MixinTransactions.sol12
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/libs/LibEIP712.sol25
2 files changed, 28 insertions, 9 deletions
diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/MixinTransactions.sol b/packages/contracts/src/2.0.0/protocol/Exchange/MixinTransactions.sol
index 0814638db..b5de1a5de 100644
--- a/packages/contracts/src/2.0.0/protocol/Exchange/MixinTransactions.sol
+++ b/packages/contracts/src/2.0.0/protocol/Exchange/MixinTransactions.sol
@@ -131,11 +131,15 @@ contract MixinTransactions is
// ));
assembly {
+ // Load free memory pointer
let memPtr := mload(64)
- mstore(memPtr, schemaHash)
- mstore(add(memPtr, 32), salt)
- mstore(add(memPtr, 64), and(signerAddress, 0xffffffffffffffffffffffffffffffffffffffff))
- mstore(add(memPtr, 96), dataHash)
+
+ mstore(memPtr, schemaHash) // hash of schema
+ mstore(add(memPtr, 32), salt) // salt
+ mstore(add(memPtr, 64), and(signerAddress, 0xffffffffffffffffffffffffffffffffffffffff)) // signerAddress
+ mstore(add(memPtr, 96), dataHash) // hash of data
+
+ // Compute hash
result := keccak256(memPtr, 128)
}
diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/libs/LibEIP712.sol b/packages/contracts/src/2.0.0/protocol/Exchange/libs/LibEIP712.sol
index c9e45189d..b02f7632e 100644
--- a/packages/contracts/src/2.0.0/protocol/Exchange/libs/LibEIP712.sol
+++ b/packages/contracts/src/2.0.0/protocol/Exchange/libs/LibEIP712.sol
@@ -61,11 +61,26 @@ contract LibEIP712 {
view
returns (bytes32 result)
{
- result = keccak256(abi.encodePacked(
- EIP191_HEADER,
- EIP712_DOMAIN_HASH,
- hashStruct
- ));
+ bytes32 eip712DomainHash = EIP712_DOMAIN_HASH;
+
+ // Assembly for more efficient computing:
+ // keccak256(abi.encodePacked(
+ // EIP191_HEADER,
+ // EIP712_DOMAIN_HASH,
+ // hashStruct
+ // ));
+
+ assembly {
+ // Load free memory pointer
+ let memPtr := mload(64)
+
+ mstore(memPtr, 0x1901000000000000000000000000000000000000000000000000000000000000) // EIP191 header
+ mstore(add(memPtr, 2), eip712DomainHash) // EIP712 domain hash
+ mstore(add(memPtr, 34), hashStruct) // Hash of struct
+
+ // Compute hash
+ result := keccak256(memPtr, 66)
+ }
return result;
}
}