-
Notifications
You must be signed in to change notification settings - Fork 466
Add OrderValidator and WalletOrderValidator signature strategies to Exchange #1774
Add OrderValidator and WalletOrderValidator signature strategies to Exchange #1774
Conversation
…rt to contracts and refactor signature validation functions.
…InappropriateSignature`.
…atureType.OrderValidator`.
…revert. Fix rebase issues. Rename `IValidator.isValidOrder` to `IValidator.isValidOrderSignature`.
cd846b1
to
6965358
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At some point we should also add the Wallet
equivalent of this signature type, but that can be in a separate PR.
/// @return True if the address recovered from the provided signature matches the input signer address. | ||
function validateOrderValidatorSignature( | ||
Order memory order, | ||
bytes32 orderHash, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
orderHash
and signerAddress
both feel redundant to me since they can be derived from the order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see an argument for keeping orderHash
since it prevents duplication of the hash calculation, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, signerAddress
can definitely go.
I see this as potentially supplanting the SignatureType.Validator
scheme, so it's likely validators will want the orderHash
anyway.
// Read the validator address from the signature. | ||
address validatorAddress = signature.readAddress(signatureLength - 21); | ||
// Ensure signer has approved validator. | ||
if (!allowedValidators[signerAddress][validatorAddress]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the same mapping for both types of validators could be a bit of a security flaw. What if a user wants to use one of the validation functions but not the other? This is probably also an argument for separating the interfaces into 2 different contracts (I know I said otherwise earlier - sorry for the thrash).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in new version.
I can do that in this one. The work is fairly similar. Stay tuned. 📺 |
… scheme into its own interface and registry.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few small nits, then looks good to me!
/// @param signature Proof of signing. | ||
/// @return Validity of signature. | ||
function isValidOrderSignature( | ||
LibOrder.Order calldata order, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm surprised this actually compiles. Will have to check out the most recent version of Solidity :)
address signerAddress, | ||
bytes memory signature | ||
) | ||
public |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is never actually used internally, right? We should make it external
if not.
/// @param hash Any 32 byte hash. | ||
/// @param signerAddress Address that should have signed the given hash. | ||
/// @param hash Any 32-byte hash. | ||
/// @param signerAddress Address that should have signed the.Signat given hash. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo
bytes32 hash, | ||
address signerAddress, | ||
bytes memory signature | ||
) | ||
public | ||
view | ||
returns (bool isValid) | ||
{ | ||
SignatureType signatureType = readValidSignatureType(hash, signerAddress, signature); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I'd default to putting any function calls with >2 arguments onto multiple lines.
view | ||
returns (bool isValid) | ||
{ | ||
SignatureType signatureType = readValidSignatureType(orderHash, signerAddress, signature); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
…instead of `public`.
…public` because passing `calldata` to internal functions isn't supported.
…xchange (#1774) * In `@0x/contracts-exchange`: Add `SignatureType.OrderValidator` support to contracts and refactor signature validation functions. * In `@0x/types`: Add `SignatureType.OrderValidator` and `RevertReason.InappropriateSignature`. * In `@0x/contracts-exchange`: Fix contracts and update tests for `SignatureType.OrderValidator`. * Ran prettier/linter * Update changelogs * In `@0x/order-utils`: Add `SignatureOrderValidatorError` to `ExchangeRevertErrors`. * In `@0x/contracts-exchange`: Add `SignatureOrderValidatorError` rich revert. Fix rebase issues. Rename `IValidator.isValidOrder` to `IValidator.isValidOrderSignature`. * In `@0x/contracts-exchange`: Add revert test cases for `OrderValidator` signature type. * In `@0x/order-utils`: Update changelog. * In `@0x/contracts-exchange`: Split off `SignatureType.OrderValidator` scheme into its own interface and registry. * In `@0x/types`: Add `SignatureType.WalletOrderValidator`. * In `@0x/order-utils`: Add `SignatureWalletOrderValidatorError`. * In `@0x/contracts-exchange`: Add `SignatureType.WalletOrderValidator` support. * Ran prettier * In `@0x/types`: Remove `RevertReason.WalletOrderValidator`. * Update/fix changelogs in `@0x/contracts-exchange`, `@0x/order-utils`, and `@0x/types`. * In `@0x/contracts-exchange`: Make `isValidOrderSignature` `external` instead of `public`. * In `@0x/contracts-exchange`: Change `isValidOrderSignature` back to `public` because passing `calldata` to internal functions isn't supported.
…xchange (#1774) * In `@0x/contracts-exchange`: Add `SignatureType.OrderValidator` support to contracts and refactor signature validation functions. * In `@0x/types`: Add `SignatureType.OrderValidator` and `RevertReason.InappropriateSignature`. * In `@0x/contracts-exchange`: Fix contracts and update tests for `SignatureType.OrderValidator`. * Ran prettier/linter * Update changelogs * In `@0x/order-utils`: Add `SignatureOrderValidatorError` to `ExchangeRevertErrors`. * In `@0x/contracts-exchange`: Add `SignatureOrderValidatorError` rich revert. Fix rebase issues. Rename `IValidator.isValidOrder` to `IValidator.isValidOrderSignature`. * In `@0x/contracts-exchange`: Add revert test cases for `OrderValidator` signature type. * In `@0x/order-utils`: Update changelog. * In `@0x/contracts-exchange`: Split off `SignatureType.OrderValidator` scheme into its own interface and registry. * In `@0x/types`: Add `SignatureType.WalletOrderValidator`. * In `@0x/order-utils`: Add `SignatureWalletOrderValidatorError`. * In `@0x/contracts-exchange`: Add `SignatureType.WalletOrderValidator` support. * Ran prettier * In `@0x/types`: Remove `RevertReason.WalletOrderValidator`. * Update/fix changelogs in `@0x/contracts-exchange`, `@0x/order-utils`, and `@0x/types`. * In `@0x/contracts-exchange`: Make `isValidOrderSignature` `external` instead of `public`. * In `@0x/contracts-exchange`: Change `isValidOrderSignature` back to `public` because passing `calldata` to internal functions isn't supported.
…xchange (#1774) * In `@0x/contracts-exchange`: Add `SignatureType.OrderValidator` support to contracts and refactor signature validation functions. * In `@0x/types`: Add `SignatureType.OrderValidator` and `RevertReason.InappropriateSignature`. * In `@0x/contracts-exchange`: Fix contracts and update tests for `SignatureType.OrderValidator`. * Ran prettier/linter * Update changelogs * In `@0x/order-utils`: Add `SignatureOrderValidatorError` to `ExchangeRevertErrors`. * In `@0x/contracts-exchange`: Add `SignatureOrderValidatorError` rich revert. Fix rebase issues. Rename `IValidator.isValidOrder` to `IValidator.isValidOrderSignature`. * In `@0x/contracts-exchange`: Add revert test cases for `OrderValidator` signature type. * In `@0x/order-utils`: Update changelog. * In `@0x/contracts-exchange`: Split off `SignatureType.OrderValidator` scheme into its own interface and registry. * In `@0x/types`: Add `SignatureType.WalletOrderValidator`. * In `@0x/order-utils`: Add `SignatureWalletOrderValidatorError`. * In `@0x/contracts-exchange`: Add `SignatureType.WalletOrderValidator` support. * Ran prettier * In `@0x/types`: Remove `RevertReason.WalletOrderValidator`. * Update/fix changelogs in `@0x/contracts-exchange`, `@0x/order-utils`, and `@0x/types`. * In `@0x/contracts-exchange`: Make `isValidOrderSignature` `external` instead of `public`. * In `@0x/contracts-exchange`: Change `isValidOrderSignature` back to `public` because passing `calldata` to internal functions isn't supported.
…xchange (#1774) * In `@0x/contracts-exchange`: Add `SignatureType.OrderValidator` support to contracts and refactor signature validation functions. * In `@0x/types`: Add `SignatureType.OrderValidator` and `RevertReason.InappropriateSignature`. * In `@0x/contracts-exchange`: Fix contracts and update tests for `SignatureType.OrderValidator`. * Ran prettier/linter * Update changelogs * In `@0x/order-utils`: Add `SignatureOrderValidatorError` to `ExchangeRevertErrors`. * In `@0x/contracts-exchange`: Add `SignatureOrderValidatorError` rich revert. Fix rebase issues. Rename `IValidator.isValidOrder` to `IValidator.isValidOrderSignature`. * In `@0x/contracts-exchange`: Add revert test cases for `OrderValidator` signature type. * In `@0x/order-utils`: Update changelog. * In `@0x/contracts-exchange`: Split off `SignatureType.OrderValidator` scheme into its own interface and registry. * In `@0x/types`: Add `SignatureType.WalletOrderValidator`. * In `@0x/order-utils`: Add `SignatureWalletOrderValidatorError`. * In `@0x/contracts-exchange`: Add `SignatureType.WalletOrderValidator` support. * Ran prettier * In `@0x/types`: Remove `RevertReason.WalletOrderValidator`. * Update/fix changelogs in `@0x/contracts-exchange`, `@0x/order-utils`, and `@0x/types`. * In `@0x/contracts-exchange`: Make `isValidOrderSignature` `external` instead of `public`. * In `@0x/contracts-exchange`: Change `isValidOrderSignature` back to `public` because passing `calldata` to internal functions isn't supported.
…xchange (#1774) * In `@0x/contracts-exchange`: Add `SignatureType.OrderValidator` support to contracts and refactor signature validation functions. * In `@0x/types`: Add `SignatureType.OrderValidator` and `RevertReason.InappropriateSignature`. * In `@0x/contracts-exchange`: Fix contracts and update tests for `SignatureType.OrderValidator`. * Ran prettier/linter * Update changelogs * In `@0x/order-utils`: Add `SignatureOrderValidatorError` to `ExchangeRevertErrors`. * In `@0x/contracts-exchange`: Add `SignatureOrderValidatorError` rich revert. Fix rebase issues. Rename `IValidator.isValidOrder` to `IValidator.isValidOrderSignature`. * In `@0x/contracts-exchange`: Add revert test cases for `OrderValidator` signature type. * In `@0x/order-utils`: Update changelog. * In `@0x/contracts-exchange`: Split off `SignatureType.OrderValidator` scheme into its own interface and registry. * In `@0x/types`: Add `SignatureType.WalletOrderValidator`. * In `@0x/order-utils`: Add `SignatureWalletOrderValidatorError`. * In `@0x/contracts-exchange`: Add `SignatureType.WalletOrderValidator` support. * Ran prettier * In `@0x/types`: Remove `RevertReason.WalletOrderValidator`. * Update/fix changelogs in `@0x/contracts-exchange`, `@0x/order-utils`, and `@0x/types`. * In `@0x/contracts-exchange`: Make `isValidOrderSignature` `external` instead of `public`. * In `@0x/contracts-exchange`: Change `isValidOrderSignature` back to `public` because passing `calldata` to internal functions isn't supported.
…xchange (#1774) * In `@0x/contracts-exchange`: Add `SignatureType.OrderValidator` support to contracts and refactor signature validation functions. * In `@0x/types`: Add `SignatureType.OrderValidator` and `RevertReason.InappropriateSignature`. * In `@0x/contracts-exchange`: Fix contracts and update tests for `SignatureType.OrderValidator`. * Ran prettier/linter * Update changelogs * In `@0x/order-utils`: Add `SignatureOrderValidatorError` to `ExchangeRevertErrors`. * In `@0x/contracts-exchange`: Add `SignatureOrderValidatorError` rich revert. Fix rebase issues. Rename `IValidator.isValidOrder` to `IValidator.isValidOrderSignature`. * In `@0x/contracts-exchange`: Add revert test cases for `OrderValidator` signature type. * In `@0x/order-utils`: Update changelog. * In `@0x/contracts-exchange`: Split off `SignatureType.OrderValidator` scheme into its own interface and registry. * In `@0x/types`: Add `SignatureType.WalletOrderValidator`. * In `@0x/order-utils`: Add `SignatureWalletOrderValidatorError`. * In `@0x/contracts-exchange`: Add `SignatureType.WalletOrderValidator` support. * Ran prettier * In `@0x/types`: Remove `RevertReason.WalletOrderValidator`. * Update/fix changelogs in `@0x/contracts-exchange`, `@0x/order-utils`, and `@0x/types`. * In `@0x/contracts-exchange`: Make `isValidOrderSignature` `external` instead of `public`. * In `@0x/contracts-exchange`: Change `isValidOrderSignature` back to `public` because passing `calldata` to internal functions isn't supported.
Description
This adds support for two new order signature strategies to the Exchange:
SignatureType.OrderValidator
andSignatureType.WalletOrderValidator
.The new signature callbacks are similar to the existing
Validator
andWallet
strategies, but instead of passing just abytes32 orderHash
to the validator'sisValidSignature()
, we also pass anOrder order
struct to the validating contract'sisValidOrderSignature()
function (see IWallet and IOrderValidator).Here is a sample validator contract for use with either
SignatureType.OrderValidator
orSignatureType.WalletOrderValidator
(they have identical function signatures):Other notes:
SignatureType.Validator
andSignatureType.Wallet
, the validator contract is called viastaticall()
and will fail if the validator contract attempts to update state.OrderValidator
s must be registered for a maker ahead of time viasetOrderValidatorApproval()
, which is distinct fromsetSignatureValidatorApproval()
used byValidator
.isValidSignature()
has been supplanted byisValidHashSignature()
andisValidOrderSignature()
.isValidHashSignature()
, so they do not support the new signature strategies (which wouldn't make sense anyway).Testing instructions
Types of changes
Checklist:
[WIP]
if necessary.