Refactor EIP1271Wallet and Validator types to use new EIP1271SignatureError

This commit is contained in:
Amir Bandeali 2019-09-02 11:38:52 -07:00
parent fd4d10e7a4
commit e880447714
2 changed files with 158 additions and 139 deletions

View File

@ -239,7 +239,6 @@ contract MixinSignatureValidator is
order, order,
orderHash orderHash
), ),
orderHash,
signerAddress, signerAddress,
signature signature
); );
@ -295,7 +294,6 @@ contract MixinSignatureValidator is
transaction, transaction,
transactionHash transactionHash
), ),
transactionHash,
signerAddress, signerAddress,
signature signature
); );
@ -473,54 +471,54 @@ contract MixinSignatureValidator is
view view
returns (bool) returns (bool)
{ {
(bool isValid, bytes memory returnData) = _staticCallLegacyWallet( // Backup length of signature
walletAddress, uint256 signatureLength = signature.length;
// Temporarily remove signatureType byte from end of signature
signature.writeLength(signatureLength - 1);
// Encode the call data.
bytes memory callData = abi.encodeWithSelector(
IWallet(address(0)).isValidSignature.selector,
hash, hash,
signature signature
); );
if (!isValid) { // Restore the original signature length
// Static call to verifier failed. signature.writeLength(signatureLength);
LibRichErrors.rrevert(LibExchangeRichErrors.SignatureWalletError( // Static call the verification function.
hash, (bool didSucceed, bytes memory returnData) = walletAddress.staticcall(callData);
walletAddress, // Return the validity of the signature if the call was successful
signature, if (didSucceed && returnData.length == 32) {
returnData return returnData.readBytes4(0) == LEGACY_WALLET_MAGIC_VALUE;
));
} }
// Revert if the call was unsuccessful
LibRichErrors.rrevert(LibExchangeRichErrors.SignatureWalletError(
hash,
walletAddress,
signature,
returnData
));
} }
/// @dev Verifies arbitrary data and a signature via an EIP1271 Wallet /// @dev Verifies arbitrary data and a signature via an EIP1271 Wallet
/// contract, where the wallet address is also the signer address. /// contract, where the wallet address is also the signer address.
/// @param data Arbitrary signed data. /// @param data Arbitrary signed data.
/// @param hash The hash associated with the data.
/// @param walletAddress Contract that will verify the data and signature. /// @param walletAddress Contract that will verify the data and signature.
/// @param signature Proof that the data has been signed by signer. /// @param signature Proof that the data has been signed by signer.
/// @return isValid True if the signature is validated by the Wallet. /// @return isValid True if the signature is validated by the Wallet.
function _validateBytesWithWallet( function _validateBytesWithWallet(
bytes memory data, bytes memory data,
bytes32 hash,
address walletAddress, address walletAddress,
bytes memory signature bytes memory signature
) )
private private
view view
returns (bool) returns (bool isValid)
{ {
(bool isValid, bytes memory returnData) = _staticCallEIP1271WalletWithReducedSignatureLength( isValid = _staticCallEIP1271WalletWithReducedSignatureLength(
walletAddress, walletAddress,
data, data,
signature, signature,
1 // The last byte of the signature (signatureType) is removed before making the staticcall 1 // The last byte of the signature (signatureType) is removed before making the staticcall
); );
if (!isValid) {
// Static call to verifier failed.
LibRichErrors.rrevert(LibExchangeRichErrors.SignatureWalletError(
hash,
walletAddress,
signature,
returnData
));
}
return isValid; return isValid;
} }
@ -539,7 +537,7 @@ contract MixinSignatureValidator is
) )
private private
view view
returns (bool) returns (bool isValid)
{ {
uint256 signatureLength = signature.length; uint256 signatureLength = signature.length;
if (signatureLength < 21) { if (signatureLength < 21) {
@ -560,80 +558,36 @@ contract MixinSignatureValidator is
validatorAddress validatorAddress
)); ));
} }
(bool isValid, bytes memory returnData) = _staticCallEIP1271WalletWithReducedSignatureLength( isValid = _staticCallEIP1271WalletWithReducedSignatureLength(
validatorAddress, validatorAddress,
data, data,
signature, signature,
21 // The last 21 bytes of the signature (validatorAddress + signatureType) are removed before making the staticcall 21 // The last 21 bytes of the signature (validatorAddress + signatureType) are removed before making the staticcall
); );
if (!isValid) {
// Static call to verifier failed.
LibRichErrors.rrevert(LibExchangeRichErrors.SignatureValidatorError(
hash,
signerAddress,
validatorAddress,
signature,
returnData
));
}
return isValid; return isValid;
} }
/// @dev Performs a staticcall to `Wallet.isValidSignature` and validates the output.
/// @param walletAddress Address of Wallet contract.
/// @param hash Any 32 byte hash.
/// @param signature Proof that the hash has been signed by signer. The last byte will be temporarily
/// popped off of the signature before calling `Wallet.isValidSignature`.
/// @return The validity of the signature and the raw returnData of the call.
function _staticCallLegacyWallet(
address walletAddress,
bytes32 hash,
bytes memory signature
)
private
view
returns (bool isValid, bytes memory)
{
// Backup length of signature
uint256 signatureLength = signature.length;
// Temporarily remove signatureType byte from end of signature
signature.writeLength(signatureLength - 1);
// Encode the call data.
bytes memory callData = abi.encodeWithSelector(
IWallet(address(0)).isValidSignature.selector,
hash,
signature
);
// Restore the original signature length
signature.writeLength(signatureLength);
// Static call the verification function.
(bool didSucceed, bytes memory returnData) = walletAddress.staticcall(callData);
// Ensure that the call was successful and that the correct value was returned
isValid = didSucceed && returnData.length <= 32 && returnData.readBytes4(0) == LEGACY_WALLET_MAGIC_VALUE;
return (isValid, returnData);
}
/// @dev Performs a staticcall to and EIP11271 compiant `isValidSignature` function and validates the output. /// @dev Performs a staticcall to and EIP11271 compiant `isValidSignature` function and validates the output.
/// @param staticCallTargetAddress Address of EIP1271Wallet or Validator contract. /// @param verifyingContractAddress Address of EIP1271Wallet or Validator contract.
/// @param data Arbitrary signed data. /// @param data Arbitrary signed data.
/// @param signature Proof that the hash has been signed by signer. Bytes will be temporarily be popped /// @param signature Proof that the hash has been signed by signer. Bytes will be temporarily be popped
/// off of the signature before calling `isValidSignature`. /// off of the signature before calling `isValidSignature`.
/// @param ignoredSignatureByteLen The amount of bytes that will be temporarily popped off the the signature. /// @param ignoredSignatureBytesLen The amount of bytes that will be temporarily popped off the the signature.
/// @return The validity of the signature and the raw returnData of the call. /// @return The validity of the signature and the raw returnData of the call.
function _staticCallEIP1271WalletWithReducedSignatureLength( function _staticCallEIP1271WalletWithReducedSignatureLength(
address staticCallTargetAddress, address verifyingContractAddress,
bytes memory data, bytes memory data,
bytes memory signature, bytes memory signature,
uint256 ignoredSignatureByteLen uint256 ignoredSignatureBytesLen
) )
private private
view view
returns (bool isValid, bytes memory) returns (bool isValid)
{ {
// Backup length of the signature // Backup length of the signature
uint256 signatureLength = signature.length; uint256 signatureLength = signature.length;
// Temporarily remove bytes from signature end // Temporarily remove bytes from signature end
signature.writeLength(signatureLength - ignoredSignatureByteLen); signature.writeLength(signatureLength - ignoredSignatureBytesLen);
bytes memory callData = abi.encodeWithSelector( bytes memory callData = abi.encodeWithSelector(
IEIP1271Wallet(address(0)).isValidSignature.selector, IEIP1271Wallet(address(0)).isValidSignature.selector,
data, data,
@ -642,9 +596,17 @@ contract MixinSignatureValidator is
// Restore original signature length // Restore original signature length
signature.writeLength(signatureLength); signature.writeLength(signatureLength);
// Static call the verification function // Static call the verification function
(bool didSucceed, bytes memory returnData) = staticCallTargetAddress.staticcall(callData); (bool didSucceed, bytes memory returnData) = verifyingContractAddress.staticcall(callData);
// Ensure that the call was successful and that the correct value was returned // Return the validity of the signature if the call was successful
isValid = didSucceed && returnData.length <= 32 && returnData.readBytes4(0) == EIP1271_MAGIC_VALUE; if (didSucceed && returnData.length == 32) {
return (isValid, returnData); return returnData.readBytes4(0) == EIP1271_MAGIC_VALUE;
}
// Revert if the call was unsuccessful
LibRichErrors.rrevert(LibExchangeRichErrors.EIP1271SignatureError(
verifyingContractAddress,
data,
signature,
returnData
));
} }
} }

View File

@ -18,12 +18,13 @@ import {
transactionHashUtils, transactionHashUtils,
} from '@0x/order-utils'; } from '@0x/order-utils';
import { SignatureType, SignedOrder, SignedZeroExTransaction } from '@0x/types'; import { SignatureType, SignedOrder, SignedZeroExTransaction } from '@0x/types';
import { BigNumber, LibBytesRevertErrors, StringRevertError } from '@0x/utils'; import { BigNumber, StringRevertError } from '@0x/utils';
import { LogWithDecodedArgs } from 'ethereum-types'; import { LogWithDecodedArgs } from 'ethereum-types';
import ethUtil = require('ethereumjs-util'); import ethUtil = require('ethereumjs-util');
import { import {
artifacts, artifacts,
IEIP1271DataContract,
TestSignatureValidatorContract, TestSignatureValidatorContract,
TestSignatureValidatorSignatureValidatorApprovalEventArgs, TestSignatureValidatorSignatureValidatorApprovalEventArgs,
TestValidatorWalletContract, TestValidatorWalletContract,
@ -41,6 +42,7 @@ blockchainTests.resets('MixinSignatureValidator', env => {
let signerPrivateKey: Buffer; let signerPrivateKey: Buffer;
let notSignerAddress: string; let notSignerAddress: string;
const eip1271Data = new IEIP1271DataContract(constants.NULL_ADDRESS, env.provider, env.txDefaults);
before(async () => { before(async () => {
chainId = await env.getChainIdAsync(); chainId = await env.getChainIdAsync();
const accounts = await env.getAccountAddressesAsync(); const accounts = await env.getAccountAddressesAsync();
@ -241,10 +243,11 @@ blockchainTests.resets('MixinSignatureValidator', env => {
it('should revert when signer is an EOA and SignatureType=Wallet', async () => { it('should revert when signer is an EOA and SignatureType=Wallet', async () => {
const hashHex = getCurrentHashHex(); const hashHex = getCurrentHashHex();
const signatureHex = hexConcat(SignatureType.Wallet); const signatureHex = hexConcat(SignatureType.Wallet);
const expectedError = new LibBytesRevertErrors.InvalidByteOperationError( const expectedError = new ExchangeRevertErrors.SignatureWalletError(
LibBytesRevertErrors.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsFourRequired, hashHex,
new BigNumber(0), signerAddress,
new BigNumber(4), signatureHex,
constants.NULL_BYTES,
); );
const tx = validateAsync(hashHex, signerAddress, signatureHex); const tx = validateAsync(hashHex, signerAddress, signatureHex);
return expect(tx).to.revertWith(expectedError); return expect(tx).to.revertWith(expectedError);
@ -263,12 +266,13 @@ blockchainTests.resets('MixinSignatureValidator', env => {
}); });
it('should revert when validator returns nothing and SignatureType=Wallet', async () => { it('should revert when validator returns nothing and SignatureType=Wallet', async () => {
const hashHex = getCurrentHashHex(); const hashHex = getCurrentHashHex(validatorWallet.address);
const signatureHex = hexConcat(SignatureType.Wallet); const signatureHex = hexConcat(SignatureType.Wallet);
const expectedError = new LibBytesRevertErrors.InvalidByteOperationError( const expectedError = new ExchangeRevertErrors.SignatureWalletError(
LibBytesRevertErrors.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsFourRequired, hashHex,
new BigNumber(0), validatorWallet.address,
new BigNumber(4), signatureHex,
constants.NULL_BYTES,
); );
const tx = validateAsync( const tx = validateAsync(
hashHex, hashHex,
@ -525,10 +529,13 @@ blockchainTests.resets('MixinSignatureValidator', env => {
it('should revert when validator returns nothing and SignatureType=Validator', async () => { it('should revert when validator returns nothing and SignatureType=Validator', async () => {
const signatureDataHex = generateRandomSignature(); const signatureDataHex = generateRandomSignature();
const signatureHex = hexConcat(signatureDataHex, validatorWallet.address, SignatureType.Validator); const signatureHex = hexConcat(signatureDataHex, validatorWallet.address, SignatureType.Validator);
const expectedError = new LibBytesRevertErrors.InvalidByteOperationError( const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
LibBytesRevertErrors.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsFourRequired, const data = eip1271Data.OrderWithHash.getABIEncodedTransactionData(signedOrder, orderHashHex);
new BigNumber(0), const expectedError = new ExchangeRevertErrors.EIP1271SignatureError(
new BigNumber(4), validatorWallet.address,
data,
signatureHex,
constants.NULL_BYTES,
); );
const tx = validateAsync(signedOrder, signatureHex, ValidatorWalletAction.ReturnNothing, signatureDataHex); const tx = validateAsync(signedOrder, signatureHex, ValidatorWalletAction.ReturnNothing, signatureDataHex);
return expect(tx).to.revertWith(expectedError); return expect(tx).to.revertWith(expectedError);
@ -540,10 +547,10 @@ blockchainTests.resets('MixinSignatureValidator', env => {
const signatureDataHex = generateRandomSignature(); const signatureDataHex = generateRandomSignature();
const signatureHex = hexConcat(signatureDataHex, validatorWallet.address, SignatureType.Validator); const signatureHex = hexConcat(signatureDataHex, validatorWallet.address, SignatureType.Validator);
const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder); const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
const expectedError = new ExchangeRevertErrors.SignatureValidatorError( const data = eip1271Data.OrderWithHash.getABIEncodedTransactionData(signedOrder, orderHashHex);
orderHashHex, const expectedError = new ExchangeRevertErrors.EIP1271SignatureError(
signedOrder.makerAddress,
validatorWallet.address, validatorWallet.address,
data,
signatureHex, signatureHex,
constants.NULL_BYTES, constants.NULL_BYTES,
); );
@ -557,10 +564,10 @@ blockchainTests.resets('MixinSignatureValidator', env => {
const signatureDataHex = generateRandomSignature(); const signatureDataHex = generateRandomSignature();
const signatureHex = hexConcat(signatureDataHex, validatorWallet.address, SignatureType.Validator); const signatureHex = hexConcat(signatureDataHex, validatorWallet.address, SignatureType.Validator);
const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder); const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
const expectedError = new ExchangeRevertErrors.SignatureValidatorError( const data = eip1271Data.OrderWithHash.getABIEncodedTransactionData(signedOrder, orderHashHex);
orderHashHex, const expectedError = new ExchangeRevertErrors.EIP1271SignatureError(
signedOrder.makerAddress,
validatorWallet.address, validatorWallet.address,
data,
signatureHex, signatureHex,
new StringRevertError(validatorWalletRevertReason).encode(), new StringRevertError(validatorWalletRevertReason).encode(),
); );
@ -638,10 +645,13 @@ blockchainTests.resets('MixinSignatureValidator', env => {
signedOrder.makerAddress = validatorWallet.address; signedOrder.makerAddress = validatorWallet.address;
const signatureDataHex = generateRandomSignature(); const signatureDataHex = generateRandomSignature();
const signatureHex = hexConcat(signatureDataHex, SignatureType.EIP1271Wallet); const signatureHex = hexConcat(signatureDataHex, SignatureType.EIP1271Wallet);
const expectedError = new LibBytesRevertErrors.InvalidByteOperationError( const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
LibBytesRevertErrors.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsFourRequired, const data = eip1271Data.OrderWithHash.getABIEncodedTransactionData(signedOrder, orderHashHex);
new BigNumber(0), const expectedError = new ExchangeRevertErrors.EIP1271SignatureError(
new BigNumber(4), validatorWallet.address,
data,
signatureHex,
constants.NULL_BYTES,
); );
const tx = validateAsync(signedOrder, signatureHex, ValidatorWalletAction.ReturnNothing, signatureDataHex); const tx = validateAsync(signedOrder, signatureHex, ValidatorWalletAction.ReturnNothing, signatureDataHex);
return expect(tx).to.revertWith(expectedError); return expect(tx).to.revertWith(expectedError);
@ -653,9 +663,10 @@ blockchainTests.resets('MixinSignatureValidator', env => {
// just does a hash comparison. // just does a hash comparison.
const signatureHex = hexConcat(generateRandomSignature(), SignatureType.EIP1271Wallet); const signatureHex = hexConcat(generateRandomSignature(), SignatureType.EIP1271Wallet);
const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder); const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
const expectedError = new ExchangeRevertErrors.SignatureWalletError( const data = eip1271Data.OrderWithHash.getABIEncodedTransactionData(signedOrder, orderHashHex);
orderHashHex, const expectedError = new ExchangeRevertErrors.EIP1271SignatureError(
validatorWallet.address, validatorWallet.address,
data,
signatureHex, signatureHex,
constants.NULL_BYTES, constants.NULL_BYTES,
); );
@ -667,9 +678,10 @@ blockchainTests.resets('MixinSignatureValidator', env => {
signedOrder.makerAddress = validatorWallet.address; signedOrder.makerAddress = validatorWallet.address;
const signatureHex = hexConcat(SignatureType.EIP1271Wallet); const signatureHex = hexConcat(SignatureType.EIP1271Wallet);
const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder); const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
const expectedError = new ExchangeRevertErrors.SignatureWalletError( const data = eip1271Data.OrderWithHash.getABIEncodedTransactionData(signedOrder, orderHashHex);
orderHashHex, const expectedError = new ExchangeRevertErrors.EIP1271SignatureError(
validatorWallet.address, validatorWallet.address,
data,
signatureHex, signatureHex,
new StringRevertError(validatorWalletRevertReason).encode(), new StringRevertError(validatorWalletRevertReason).encode(),
); );
@ -679,10 +691,14 @@ blockchainTests.resets('MixinSignatureValidator', env => {
it('should revert when signer is an EOA and SignatureType=EIP1271Wallet', async () => { it('should revert when signer is an EOA and SignatureType=EIP1271Wallet', async () => {
const signatureHex = hexConcat(SignatureType.EIP1271Wallet); const signatureHex = hexConcat(SignatureType.EIP1271Wallet);
const expectedError = new LibBytesRevertErrors.InvalidByteOperationError( signedOrder.makerAddress = notSignerAddress;
LibBytesRevertErrors.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsFourRequired, const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
new BigNumber(0), const data = eip1271Data.OrderWithHash.getABIEncodedTransactionData(signedOrder, orderHashHex);
new BigNumber(4), const expectedError = new ExchangeRevertErrors.EIP1271SignatureError(
notSignerAddress,
data,
signatureHex,
constants.NULL_BYTES,
); );
const tx = signatureValidator.isValidOrderSignature.callAsync(signedOrder, signatureHex); const tx = signatureValidator.isValidOrderSignature.callAsync(signedOrder, signatureHex);
return expect(tx).to.revertWith(expectedError); return expect(tx).to.revertWith(expectedError);
@ -690,10 +706,13 @@ blockchainTests.resets('MixinSignatureValidator', env => {
it('should revert when signer is an EOA and SignatureType=Validator', async () => { it('should revert when signer is an EOA and SignatureType=Validator', async () => {
const signatureHex = hexConcat(notSignerAddress, SignatureType.Validator); const signatureHex = hexConcat(notSignerAddress, SignatureType.Validator);
const expectedError = new LibBytesRevertErrors.InvalidByteOperationError( const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
LibBytesRevertErrors.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsFourRequired, const data = eip1271Data.OrderWithHash.getABIEncodedTransactionData(signedOrder, orderHashHex);
new BigNumber(0), const expectedError = new ExchangeRevertErrors.EIP1271SignatureError(
new BigNumber(4), notSignerAddress,
data,
signatureHex,
constants.NULL_BYTES,
); );
// Register an EOA as a validator. // Register an EOA as a validator.
await signatureValidator.setSignatureValidatorApproval.awaitTransactionSuccessAsync( await signatureValidator.setSignatureValidatorApproval.awaitTransactionSuccessAsync(
@ -821,10 +840,16 @@ blockchainTests.resets('MixinSignatureValidator', env => {
it('should revert when validator returns nothing and SignatureType=Validator', async () => { it('should revert when validator returns nothing and SignatureType=Validator', async () => {
const signatureDataHex = generateRandomSignature(); const signatureDataHex = generateRandomSignature();
const signatureHex = hexConcat(signatureDataHex, validatorWallet.address, SignatureType.Validator); const signatureHex = hexConcat(signatureDataHex, validatorWallet.address, SignatureType.Validator);
const expectedError = new LibBytesRevertErrors.InvalidByteOperationError( const transactionHashHex = transactionHashUtils.getTransactionHashHex(signedTransaction);
LibBytesRevertErrors.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsFourRequired, const data = eip1271Data.ZeroExTransactionWithHash.getABIEncodedTransactionData(
new BigNumber(0), signedTransaction,
new BigNumber(4), transactionHashHex,
);
const expectedError = new ExchangeRevertErrors.EIP1271SignatureError(
validatorWallet.address,
data,
signatureHex,
constants.NULL_BYTES,
); );
const tx = validateAsync( const tx = validateAsync(
signedTransaction, signedTransaction,
@ -841,10 +866,13 @@ blockchainTests.resets('MixinSignatureValidator', env => {
const signatureDataHex = generateRandomSignature(); const signatureDataHex = generateRandomSignature();
const signatureHex = hexConcat(signatureDataHex, validatorWallet.address, SignatureType.Validator); const signatureHex = hexConcat(signatureDataHex, validatorWallet.address, SignatureType.Validator);
const transactionHashHex = transactionHashUtils.getTransactionHashHex(signedTransaction); const transactionHashHex = transactionHashUtils.getTransactionHashHex(signedTransaction);
const expectedError = new ExchangeRevertErrors.SignatureValidatorError( const data = eip1271Data.ZeroExTransactionWithHash.getABIEncodedTransactionData(
signedTransaction,
transactionHashHex, transactionHashHex,
signedTransaction.signerAddress, );
const expectedError = new ExchangeRevertErrors.EIP1271SignatureError(
validatorWallet.address, validatorWallet.address,
data,
signatureHex, signatureHex,
constants.NULL_BYTES, constants.NULL_BYTES,
); );
@ -858,10 +886,13 @@ blockchainTests.resets('MixinSignatureValidator', env => {
const signatureDataHex = generateRandomSignature(); const signatureDataHex = generateRandomSignature();
const signatureHex = hexConcat(signatureDataHex, validatorWallet.address, SignatureType.Validator); const signatureHex = hexConcat(signatureDataHex, validatorWallet.address, SignatureType.Validator);
const transactionHashHex = transactionHashUtils.getTransactionHashHex(signedTransaction); const transactionHashHex = transactionHashUtils.getTransactionHashHex(signedTransaction);
const expectedError = new ExchangeRevertErrors.SignatureValidatorError( const data = eip1271Data.ZeroExTransactionWithHash.getABIEncodedTransactionData(
signedTransaction,
transactionHashHex, transactionHashHex,
signedTransaction.signerAddress, );
const expectedError = new ExchangeRevertErrors.EIP1271SignatureError(
validatorWallet.address, validatorWallet.address,
data,
signatureHex, signatureHex,
new StringRevertError(validatorWalletRevertReason).encode(), new StringRevertError(validatorWalletRevertReason).encode(),
); );
@ -939,10 +970,16 @@ blockchainTests.resets('MixinSignatureValidator', env => {
signedTransaction.signerAddress = validatorWallet.address; signedTransaction.signerAddress = validatorWallet.address;
const signatureDataHex = generateRandomSignature(); const signatureDataHex = generateRandomSignature();
const signatureHex = hexConcat(signatureDataHex, SignatureType.EIP1271Wallet); const signatureHex = hexConcat(signatureDataHex, SignatureType.EIP1271Wallet);
const expectedError = new LibBytesRevertErrors.InvalidByteOperationError( const transactionHashHex = transactionHashUtils.getTransactionHashHex(signedTransaction);
LibBytesRevertErrors.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsFourRequired, const data = eip1271Data.ZeroExTransactionWithHash.getABIEncodedTransactionData(
new BigNumber(0), signedTransaction,
new BigNumber(4), transactionHashHex,
);
const expectedError = new ExchangeRevertErrors.EIP1271SignatureError(
validatorWallet.address,
data,
signatureHex,
constants.NULL_BYTES,
); );
const tx = validateAsync( const tx = validateAsync(
signedTransaction, signedTransaction,
@ -959,9 +996,13 @@ blockchainTests.resets('MixinSignatureValidator', env => {
// just does a hash comparison. // just does a hash comparison.
const signatureHex = hexConcat(generateRandomSignature(), SignatureType.EIP1271Wallet); const signatureHex = hexConcat(generateRandomSignature(), SignatureType.EIP1271Wallet);
const transactionHashHex = transactionHashUtils.getTransactionHashHex(signedTransaction); const transactionHashHex = transactionHashUtils.getTransactionHashHex(signedTransaction);
const expectedError = new ExchangeRevertErrors.SignatureWalletError( const data = eip1271Data.ZeroExTransactionWithHash.getABIEncodedTransactionData(
signedTransaction,
transactionHashHex, transactionHashHex,
);
const expectedError = new ExchangeRevertErrors.EIP1271SignatureError(
validatorWallet.address, validatorWallet.address,
data,
signatureHex, signatureHex,
constants.NULL_BYTES, constants.NULL_BYTES,
); );
@ -975,9 +1016,13 @@ blockchainTests.resets('MixinSignatureValidator', env => {
// just does a hash comparison. // just does a hash comparison.
const signatureHex = hexConcat(generateRandomSignature(), SignatureType.EIP1271Wallet); const signatureHex = hexConcat(generateRandomSignature(), SignatureType.EIP1271Wallet);
const transactionHashHex = transactionHashUtils.getTransactionHashHex(signedTransaction); const transactionHashHex = transactionHashUtils.getTransactionHashHex(signedTransaction);
const expectedError = new ExchangeRevertErrors.SignatureWalletError( const data = eip1271Data.ZeroExTransactionWithHash.getABIEncodedTransactionData(
signedTransaction,
transactionHashHex, transactionHashHex,
);
const expectedError = new ExchangeRevertErrors.EIP1271SignatureError(
validatorWallet.address, validatorWallet.address,
data,
signatureHex, signatureHex,
new StringRevertError(validatorWalletRevertReason).encode(), new StringRevertError(validatorWalletRevertReason).encode(),
); );
@ -987,10 +1032,16 @@ blockchainTests.resets('MixinSignatureValidator', env => {
it('should revert when signer is an EOA and SignatureType=EIP1271Wallet', async () => { it('should revert when signer is an EOA and SignatureType=EIP1271Wallet', async () => {
const signatureHex = hexConcat(SignatureType.EIP1271Wallet); const signatureHex = hexConcat(SignatureType.EIP1271Wallet);
const expectedError = new LibBytesRevertErrors.InvalidByteOperationError( const transactionHashHex = transactionHashUtils.getTransactionHashHex(signedTransaction);
LibBytesRevertErrors.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsFourRequired, const data = eip1271Data.ZeroExTransactionWithHash.getABIEncodedTransactionData(
new BigNumber(0), signedTransaction,
new BigNumber(4), transactionHashHex,
);
const expectedError = new ExchangeRevertErrors.EIP1271SignatureError(
signedTransaction.signerAddress,
data,
signatureHex,
constants.NULL_BYTES,
); );
const tx = signatureValidator.isValidTransactionSignature.callAsync(signedTransaction, signatureHex); const tx = signatureValidator.isValidTransactionSignature.callAsync(signedTransaction, signatureHex);
return expect(tx).to.revertWith(expectedError); return expect(tx).to.revertWith(expectedError);
@ -998,10 +1049,16 @@ blockchainTests.resets('MixinSignatureValidator', env => {
it('should revert when signer is an EOA and SignatureType=Validator', async () => { it('should revert when signer is an EOA and SignatureType=Validator', async () => {
const signatureHex = hexConcat(notSignerAddress, SignatureType.Validator); const signatureHex = hexConcat(notSignerAddress, SignatureType.Validator);
const expectedError = new LibBytesRevertErrors.InvalidByteOperationError( const transactionHashHex = transactionHashUtils.getTransactionHashHex(signedTransaction);
LibBytesRevertErrors.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsFourRequired, const data = eip1271Data.ZeroExTransactionWithHash.getABIEncodedTransactionData(
new BigNumber(0), signedTransaction,
new BigNumber(4), transactionHashHex,
);
const expectedError = new ExchangeRevertErrors.EIP1271SignatureError(
notSignerAddress,
data,
signatureHex,
constants.NULL_BYTES,
); );
// Register an EOA as a validator. // Register an EOA as a validator.
await signatureValidator.setSignatureValidatorApproval.awaitTransactionSuccessAsync( await signatureValidator.setSignatureValidatorApproval.awaitTransactionSuccessAsync(