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

View File

@ -56,21 +56,20 @@ contract LibExchangeRichErrorDecoder {
/// @return signerAddress The expected signer of the hash. /// @return signerAddress The expected signer of the hash.
/// @return signature The full signature bytes. /// @return signature The full signature bytes.
/// @return errorData The revert data thrown by the validator contract. /// @return errorData The revert data thrown by the validator contract.
function decodeSignatureValidatorError(bytes memory encoded) function decodeEIP1271SignatureError(bytes memory encoded)
public public
pure pure
returns ( returns (
bytes32 hash, address verifyingContractAddress,
address signerAddress, bytes memory data,
address validatorAddress,
bytes memory signature, bytes memory signature,
bytes memory errorData bytes memory errorData
) )
{ {
_assertSelectorBytes(encoded, LibExchangeRichErrors.SignatureValidatorErrorSelector()); _assertSelectorBytes(encoded, LibExchangeRichErrors.EIP1271SignatureErrorSelector());
(hash, signerAddress, validatorAddress, signature, errorData) = abi.decode( (verifyingContractAddress, data, signature, errorData) = abi.decode(
encoded.sliceDestructive(4, encoded.length), 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 orderHash = orderUtils.generatePseudoRandomOrderHash();
const signer = addressUtils.generatePseudoRandomAddress(); const signer = addressUtils.generatePseudoRandomAddress();
const validator = addressUtils.generatePseudoRandomAddress(); const validator = addressUtils.generatePseudoRandomAddress();
const data = hexRandom(ERROR_DATA_LENGTH);
const signature = hexRandom(SIGNATURE_LENGTH); const signature = hexRandom(SIGNATURE_LENGTH);
const errorData = hexRandom(ERROR_DATA_LENGTH); const errorData = hexRandom(ERROR_DATA_LENGTH);
createDecodeTest(ExchangeRevertErrors.SignatureError, [errorCode, orderHash, signer, signature]); createDecodeTest(ExchangeRevertErrors.SignatureError, [errorCode, orderHash, signer, signature]);
createDecodeTest(ExchangeRevertErrors.SignatureValidatorNotApprovedError, [signer, validator]); createDecodeTest(ExchangeRevertErrors.SignatureValidatorNotApprovedError, [signer, validator]);
createDecodeTest(ExchangeRevertErrors.SignatureValidatorError, [ createDecodeTest(ExchangeRevertErrors.EIP1271SignatureError, [validator, data, signature, errorData]);
orderHash,
signer,
validator,
signature,
errorData,
]);
createDecodeTest(ExchangeRevertErrors.SignatureWalletError, [orderHash, signer, 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 { export class EIP1271SignatureError extends RevertError {
constructor(hash?: string, signer?: string, validator?: string, signature?: string, errorData?: string) { constructor(verifyingContractAddress?: string, data?: string, signature?: string, errorData?: string) {
super( super(
'SignatureValidatorError', 'EIP1271SignatureError',
'SignatureValidatorError(bytes32 hash, address signer, address validator, bytes signature, bytes errorData)', 'EIP1271SignatureError(address verifyingContractAddress, bytes data, bytes signature, bytes errorData)',
{ {
hash, verifyingContractAddress,
signer, data,
validator,
signature, signature,
errorData, errorData,
}, },
@ -266,7 +265,7 @@ const types = [
SignatureError, SignatureError,
SignatureValidatorNotApprovedError, SignatureValidatorNotApprovedError,
SignatureWalletError, SignatureWalletError,
SignatureValidatorError, EIP1271SignatureError,
InvalidSenderError, InvalidSenderError,
InvalidTakerError, InvalidTakerError,
InvalidMakerError, InvalidMakerError,