From e5b7e29113fb7c87f41e492abb1fd81247f0db46 Mon Sep 17 00:00:00 2001 From: Amir Bandeali Date: Wed, 23 May 2018 10:08:06 -0700 Subject: Add signer to txHash, allow approveValidator to be used with executeTransaction --- .../current/protocol/Exchange/MixinSignatureValidator.sol | 7 +++++-- .../contracts/current/protocol/Exchange/MixinTransactions.sol | 1 + packages/contracts/src/utils/transaction_factory.ts | 9 ++++----- 3 files changed, 10 insertions(+), 7 deletions(-) (limited to 'packages/contracts') diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol b/packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol index 8ef961a81..e2d4808c3 100644 --- a/packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol +++ b/packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol @@ -19,6 +19,7 @@ pragma solidity ^0.4.24; import "./mixins/MSignatureValidator.sol"; +import "./mixins/MTransactions.sol"; import "./interfaces/ISigner.sol"; import "./interfaces/IValidator.sol"; import "./libs/LibExchangeErrors.sol"; @@ -27,7 +28,8 @@ import "../../utils/LibBytes/LibBytes.sol"; contract MixinSignatureValidator is LibBytes, LibExchangeErrors, - MSignatureValidator + MSignatureValidator, + MTransactions { // Mapping of hash => signer => signed @@ -63,7 +65,8 @@ contract MixinSignatureValidator is ) external { - allowedValidators[msg.sender][validator] = approval; + address signer = getCurrentContextAddress(); + allowedValidators[signer][validator] = approval; } /// @dev Verifies that a hash has been signed by the given signer. diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/MixinTransactions.sol b/packages/contracts/src/contracts/current/protocol/Exchange/MixinTransactions.sol index 12bba1ef2..d153dfa5c 100644 --- a/packages/contracts/src/contracts/current/protocol/Exchange/MixinTransactions.sol +++ b/packages/contracts/src/contracts/current/protocol/Exchange/MixinTransactions.sol @@ -56,6 +56,7 @@ contract MixinTransactions is // Calculate transaction hash bytes32 transactionHash = keccak256( address(this), + signer, salt, data ); diff --git a/packages/contracts/src/utils/transaction_factory.ts b/packages/contracts/src/utils/transaction_factory.ts index 941bff96d..65cdb3f89 100644 --- a/packages/contracts/src/utils/transaction_factory.ts +++ b/packages/contracts/src/utils/transaction_factory.ts @@ -7,26 +7,25 @@ import { signingUtils } from './signing_utils'; import { SignatureType, SignedTransaction } from './types'; export class TransactionFactory { - private _signer: string; + private _signerBuff: Buffer; private _exchangeAddress: string; private _privateKey: Buffer; constructor(privateKey: Buffer, exchangeAddress: string) { this._privateKey = privateKey; this._exchangeAddress = exchangeAddress; - const signerBuff = ethUtil.privateToAddress(this._privateKey); - this._signer = `0x${signerBuff.toString('hex')}`; + this._signerBuff = ethUtil.privateToAddress(this._privateKey); } public newSignedTransaction( data: string, signatureType: SignatureType = SignatureType.Ecrecover, ): SignedTransaction { const salt = generatePseudoRandomSalt(); - const txHash = crypto.solSHA3([this._exchangeAddress, salt, ethUtil.toBuffer(data)]); + const txHash = crypto.solSHA3([this._exchangeAddress, this._signerBuff, salt, ethUtil.toBuffer(data)]); const signature = signingUtils.signMessage(txHash, this._privateKey, signatureType); const signedTx = { exchangeAddress: this._exchangeAddress, salt, - signer: this._signer, + signer: `0x${this._signerBuff.toString('hex')}`, data, signature: `0x${signature.toString('hex')}`, }; -- cgit v1.2.3