Create EIP1271SignatureError rich revert

This commit is contained in:
Amir Bandeali 2019-09-02 11:37:39 -07:00
parent 9974e10069
commit fd4d10e7a4
4 changed files with 28 additions and 37 deletions

View File

@ -71,9 +71,9 @@ library LibExchangeRichErrors {
bytes4 internal constant SIGNATURE_VALIDATOR_NOT_APPROVED_ERROR_SELECTOR =
0xa15c0d06;
// bytes4(keccak256("SignatureValidatorError(bytes32,address,address,bytes,bytes)"))
bytes4 internal constant SIGNATURE_VALIDATOR_ERROR_SELECTOR =
0xa23838b8;
// bytes4(keccak256("EIP1271SignatureError(address,bytes,bytes,bytes)"))
bytes4 internal constant EIP1271_SIGNATURE_ERROR_SELECTOR =
0x5bd0428d;
// bytes4(keccak256("SignatureWalletError(bytes32,address,bytes,bytes)"))
bytes4 internal constant SIGNATURE_WALLET_ERROR_SELECTOR =
@ -164,12 +164,12 @@ library LibExchangeRichErrors {
return SIGNATURE_VALIDATOR_NOT_APPROVED_ERROR_SELECTOR;
}
function SignatureValidatorErrorSelector()
function EIP1271SignatureErrorSelector()
internal
pure
returns (bytes4)
{
return SIGNATURE_VALIDATOR_ERROR_SELECTOR;
return EIP1271_SIGNATURE_ERROR_SELECTOR;
}
function SignatureWalletErrorSelector()
@ -363,10 +363,9 @@ library LibExchangeRichErrors {
);
}
function SignatureValidatorError(
bytes32 hash,
address signerAddress,
address validatorAddress,
function EIP1271SignatureError(
address verifyingContractAddress,
bytes memory data,
bytes memory signature,
bytes memory errorData
)
@ -375,10 +374,9 @@ library LibExchangeRichErrors {
returns (bytes memory)
{
return abi.encodeWithSelector(
SIGNATURE_VALIDATOR_ERROR_SELECTOR,
hash,
signerAddress,
validatorAddress,
EIP1271_SIGNATURE_ERROR_SELECTOR,
verifyingContractAddress,
data,
signature,
errorData
);
@ -386,7 +384,7 @@ library LibExchangeRichErrors {
function SignatureWalletError(
bytes32 hash,
address signerAddress,
address walletAddress,
bytes memory signature,
bytes memory errorData
)
@ -397,7 +395,7 @@ library LibExchangeRichErrors {
return abi.encodeWithSelector(
SIGNATURE_WALLET_ERROR_SELECTOR,
hash,
signerAddress,
walletAddress,
signature,
errorData
);

View File

@ -56,21 +56,20 @@ contract LibExchangeRichErrorDecoder {
/// @return signerAddress The expected signer of the hash.
/// @return signature The full signature bytes.
/// @return errorData The revert data thrown by the validator contract.
function decodeSignatureValidatorError(bytes memory encoded)
function decodeEIP1271SignatureError(bytes memory encoded)
public
pure
returns (
bytes32 hash,
address signerAddress,
address validatorAddress,
address verifyingContractAddress,
bytes memory data,
bytes memory signature,
bytes memory errorData
)
{
_assertSelectorBytes(encoded, LibExchangeRichErrors.SignatureValidatorErrorSelector());
(hash, signerAddress, validatorAddress, signature, errorData) = abi.decode(
_assertSelectorBytes(encoded, LibExchangeRichErrors.EIP1271SignatureErrorSelector());
(verifyingContractAddress, data, signature, errorData) = abi.decode(
encoded.sliceDestructive(4, encoded.length),
(bytes32, address, address, bytes, bytes)
(address, bytes, bytes, bytes)
);
}

View File

@ -61,17 +61,12 @@ blockchainTests.resets('LibExchangeRichErrorDecoder', ({ provider, txDefaults })
const orderHash = orderUtils.generatePseudoRandomOrderHash();
const signer = addressUtils.generatePseudoRandomAddress();
const validator = addressUtils.generatePseudoRandomAddress();
const data = hexRandom(ERROR_DATA_LENGTH);
const signature = hexRandom(SIGNATURE_LENGTH);
const errorData = hexRandom(ERROR_DATA_LENGTH);
createDecodeTest(ExchangeRevertErrors.SignatureError, [errorCode, orderHash, signer, signature]);
createDecodeTest(ExchangeRevertErrors.SignatureValidatorNotApprovedError, [signer, validator]);
createDecodeTest(ExchangeRevertErrors.SignatureValidatorError, [
orderHash,
signer,
validator,
signature,
errorData,
]);
createDecodeTest(ExchangeRevertErrors.EIP1271SignatureError, [validator, data, signature, errorData]);
createDecodeTest(ExchangeRevertErrors.SignatureWalletError, [orderHash, signer, signature, errorData]);
})();

View File

@ -88,15 +88,14 @@ export class SignatureWalletError extends RevertError {
}
}
export class SignatureValidatorError extends RevertError {
constructor(hash?: string, signer?: string, validator?: string, signature?: string, errorData?: string) {
export class EIP1271SignatureError extends RevertError {
constructor(verifyingContractAddress?: string, data?: string, signature?: string, errorData?: string) {
super(
'SignatureValidatorError',
'SignatureValidatorError(bytes32 hash, address signer, address validator, bytes signature, bytes errorData)',
'EIP1271SignatureError',
'EIP1271SignatureError(address verifyingContractAddress, bytes data, bytes signature, bytes errorData)',
{
hash,
signer,
validator,
verifyingContractAddress,
data,
signature,
errorData,
},
@ -266,7 +265,7 @@ const types = [
SignatureError,
SignatureValidatorNotApprovedError,
SignatureWalletError,
SignatureValidatorError,
EIP1271SignatureError,
InvalidSenderError,
InvalidTakerError,
InvalidMakerError,