Optimize approval hashing

This commit is contained in:
Amir Bandeali
2019-03-01 10:51:22 -08:00
parent 69c6f50dfb
commit 558ce4713c
2 changed files with 19 additions and 16 deletions

View File

@@ -25,13 +25,14 @@ contract LibCoordinatorApproval is
LibEIP712Domain
{
// Hash for the EIP712 Coordinator approval message
bytes32 constant internal EIP712_COORDINATOR_APPROVAL_SCHEMA_HASH = keccak256(abi.encodePacked(
"CoordinatorApproval(",
"bytes32 transactionHash,",
"bytes transactionSignature,",
"uint256 approvalExpirationTimeSeconds",
")"
));
// keccak256(abi.encodePacked(
// "CoordinatorApproval(",
// "bytes32 transactionHash,",
// "bytes transactionSignature,",
// "uint256 approvalExpirationTimeSeconds",
// ")"
// ));
bytes32 constant internal EIP712_COORDINATOR_APPROVAL_SCHEMA_HASH = 0x9f6a55727f39e17015e248e6457fbf0b18270e56c53093ff432d3db5703e191e;
struct CoordinatorApproval {
bytes32 transactionHash; // EIP712 hash of the transaction, using the domain separator of this contract.
@@ -60,8 +61,7 @@ contract LibCoordinatorApproval is
returns (bytes32 result)
{
bytes32 schemaHash = EIP712_COORDINATOR_APPROVAL_SCHEMA_HASH;
bytes32 transactionSignatureHash = keccak256(approval.transactionSignature);
// TODO(abandeali1): optimize by loading from memory in assembly
bytes memory transactionSignature = approval.transactionSignature;
bytes32 transactionHash = approval.transactionHash;
uint256 approvalExpirationTimeSeconds = approval.approvalExpirationTimeSeconds;
@@ -74,6 +74,9 @@ contract LibCoordinatorApproval is
// ));
assembly {
// Compute hash of transaction signature
let transactionSignatureHash := keccak256(add(transactionSignature, 32), mload(transactionSignature))
// Load free memory pointer
let memPtr := mload(64)

View File

@@ -25,13 +25,13 @@ contract LibZeroExTransaction is
LibEIP712Domain
{
// Hash for the EIP712 0x transaction schema
// keccak256(abi.encodePacked(
// "ZeroExTransaction(",
// "uint256 salt,",
// "address signerAddress,",
// "bytes data",
// ")"
// ));
// keccak256(abi.encodePacked(
// "ZeroExTransaction(",
// "uint256 salt,",
// "address signerAddress,",
// "bytes data",
// ")"
// ));
bytes32 constant internal EIP712_ZEROEX_TRANSACTION_SCHEMA_HASH = 0x213c6f636f3ea94e701c0adf9b2624aa45a6c694f9a292c094f9a81c24b5df4c;
struct ZeroExTransaction {