Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Always validate callback signatures & add support for EIP-1271 signatures #1885

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
05c6024
Update generated wrappers for coordinator and exchange.
dorothy-zbornak Mar 26, 2019
d835071
`@0x/base-contract`: Make `PromiseWithTransactionHash` fully compatib…
dorothy-zbornak Jun 19, 2019
4e86c53
`@0x/contracts-exchange`: Always check `OrderValidator` and `WalletOr…
dorothy-zbornak Jun 21, 2019
b1439cd
`@0x/utils`: Add `toStringTag` symbol to `RevertError`
dorothy-zbornak Jun 21, 2019
a9e1a26
`@0x/contracts-exchange`: Update changelog
dorothy-zbornak Jun 21, 2019
ce6f447
`@0x/order-utils`: Add `validator` field to `SignatureOrderValidatorE…
dorothy-zbornak Jun 21, 2019
18cc4b7
`@0x/contracts-exchange`: Have `TestValidatorWallet` always accept `W…
dorothy-zbornak Jun 21, 2019
cad5dd8
`@0x/types`: Rename `WalletOrderValidator` to `OrderWallet` in `Signa…
dorothy-zbornak Jun 22, 2019
89ca1e0
`@0x/order-utils`: Rename `SignatureWalletOrderValidatorError` to `Si…
dorothy-zbornak Jun 22, 2019
577a721
`@0x/contracts-exchange`: Rename `WalletOrderValidator` to `OrderWall…
dorothy-zbornak Jun 22, 2019
81f6265
Run prettier/linter
dorothy-zbornak Jun 22, 2019
56dbaa5
Update changelogs
dorothy-zbornak Jun 22, 2019
0e9d1cf
Rebase against 3.0
dorothy-zbornak Jun 24, 2019
d5623cf
`@0x/contracts-utils`: Add LibEIP1271.sol
dorothy-zbornak Jun 25, 2019
e3c4442
`@0x/contracts-exchange`: Fix comments in `test/signature_validator.ts`
dorothy-zbornak Jun 25, 2019
c6761b2
`@0x/contracts-exchange`: Refactor out `EIP1271_MAGIC_VALUE` into a `…
dorothy-zbornak Jun 25, 2019
6093a73
`@0x/contracts-exchange`: Add comments about preserving signatures in…
dorothy-zbornak Jun 25, 2019
1186820
Fix linter errors
dorothy-zbornak Jun 25, 2019
24b21ed
`@0x/contracts-exchange`: Consolidate signature types.
dorothy-zbornak Jun 25, 2019
acdcb1b
`@0x/contracts-exchange`: Fix linearization issues.
dorothy-zbornak Jun 25, 2019
c0aa42b
`@0x/types`: Consolidate signature types.
dorothy-zbornak Jun 25, 2019
c08a618
`@0x/order-utils`: Remove unused exchange revert errors
dorothy-zbornak Jun 25, 2019
721de3c
`@0x/contracts-exchange`: Add `isValidHashSignature()` back.
dorothy-zbornak Jun 26, 2019
51638fc
`@0x/contracts-exchange`: Remove `isValidOrderSignature()` from `IWal…
dorothy-zbornak Jun 26, 2019
1f28d67
`@0x/contracts-test-utils`: Add `hexConcat()` in `hex_utils.ts`.
dorothy-zbornak Jun 26, 2019
13e0433
`@0x/contracts-exchange`: Update tests for new/consolidated signature…
dorothy-zbornak Jun 26, 2019
3ab8eab
`@0x/contracts-exchange`: Update CHANGELOG
dorothy-zbornak Jun 26, 2019
8e9c185
`@0x/order-utils`: Update CHANGELOG
dorothy-zbornak Jun 26, 2019
a099f05
`@0x/contracts-exchange`: Run `contracts:gen`
dorothy-zbornak Jun 26, 2019
e7bde04
`@0x/contracts-exchange`: Make `assertValidFill` and `calculateMatche…
dorothy-zbornak Jun 26, 2019
a966abd
`@0x/contracts-exchange`: Cosmetic changes to contracts.
dorothy-zbornak Jun 26, 2019
c2f4d45
`@0x/contracts-exchange`: Make `assertValidFill()` internal again.
dorothy-zbornak Jul 1, 2019
896cd51
`@0x/contracts-exchange`: REALLY make `assertValidFill()` internal ag…
dorothy-zbornak Jul 1, 2019
d85e9c7
`@0x/contracts-exchange`: Use named return values in `MixinSignatureV…
dorothy-zbornak Jul 1, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
@0x/contracts-exchange: Fix linearization issues.
  • Loading branch information
dorothy-zbornak committed Jun 25, 2019
commit acdcb1ba94cac028981a7f4af9a27a78b0507904
2 changes: 1 addition & 1 deletion contracts/exchange/contracts/src/Exchange.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import "./MixinTransferSimulator.sol";


// solhint-disable no-empty-blocks
// MixinAssetProxyDispatcher, MixinExchangeCore, MixinExchangeRichErrors,
// MixinAssetProxyDispatcher, MixinExchangeCore, MixinExchangeRichErrors,
// and MixinTransactions are all inherited via the other Mixins that are
// used.
contract Exchange is
Expand Down
64 changes: 0 additions & 64 deletions contracts/exchange/contracts/src/MixinCommon.sol

This file was deleted.

10 changes: 3 additions & 7 deletions contracts/exchange/contracts/src/MixinExchangeCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,23 @@
pragma solidity ^0.5.9;
pragma experimental ABIEncoderV2;

import "@0x/contracts-utils/contracts/src/ReentrancyGuard.sol";
import "@0x/contracts-utils/contracts/src/LibBytes.sol";
import "@0x/contracts-exchange-libs/contracts/src/LibExchangeSelectors.sol";
import "@0x/contracts-exchange-libs/contracts/src/LibFillResults.sol";
import "@0x/contracts-exchange-libs/contracts/src/LibMath.sol";
import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol";
import "./interfaces/IExchangeCore.sol";
import "./MixinAssetProxyDispatcher.sol";
import "./MixinExchangeRichErrors.sol";
import "./MixinCommon.sol";
import "./MixinSignatureValidator.sol";


contract MixinExchangeCore is
IExchangeCore,
LibExchangeSelectors,
LibMath,
LibFillResults,
LibOrder,
ReentrancyGuard,
MixinCommon,
MixinAssetProxyDispatcher
MixinAssetProxyDispatcher,
MixinSignatureValidator
{
using LibBytes for bytes;

Expand Down
12 changes: 6 additions & 6 deletions contracts/exchange/contracts/src/MixinSignatureValidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ import "./interfaces/IWallet.sol";
import "./interfaces/IEIP1271Wallet.sol";
import "./interfaces/ISignatureValidator.sol";
import "./MixinExchangeRichErrors.sol";
import "./MixinCommon.sol";
import "./MixinTransactions.sol";


contract MixinSignatureValidator is
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is out of scope for this PR, but I think it could be good to abstract a lot of this logic into a generic library like libSignatureValidator that can be used across our packages.

ISignatureValidator,
MixinExchangeRichErrors,
ReentrancyGuard,
LibEIP1271,
LibOrder,
LibZeroExTransaction,
LibEIP1271,
ReentrancyGuard,
MixinCommon,
MixinExchangeRichErrors
ISignatureValidator,
MixinTransactions
{
using LibBytes for bytes;

Expand Down
8 changes: 4 additions & 4 deletions contracts/exchange/contracts/src/MixinTransactions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ pragma experimental ABIEncoderV2;

import "@0x/contracts-exchange-libs/contracts/src/LibZeroExTransaction.sol";
import "./interfaces/ITransactions.sol";
import "./interfaces/ISignatureValidator.sol";
import "./MixinExchangeRichErrors.sol";
import "./MixinSignatureValidator.sol";


contract MixinTransactions is
ITransactions,
LibZeroExTransaction,
MixinExchangeRichErrors,
MixinSignatureValidator
LibZeroExTransaction,
ISignatureValidator,
ITransactions
{
// Mapping of transaction hash => executed
// This prevents transactions from being executed more than once.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,26 @@ contract ISignatureValidator {
public
pure
returns (bool needsRegularValidation);

// Defined in MixinSignatureValidator
function _isValidOrderWithHashSignature(
LibOrder.Order memory order,
bytes32 orderHash,
address signerAddress,
bytes memory signature
)
internal
view
returns (bool isValid);

// Defined in MixinSignatureValidator
function _isValidTransactionWithHashSignature(
LibZeroExTransaction.ZeroExTransaction memory transaction,
bytes32 transactionHash,
address signerAddress,
bytes memory signature
)
internal
view
returns (bool isValid);
}
10 changes: 10 additions & 0 deletions contracts/exchange/contracts/src/interfaces/ITransactions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,14 @@ contract ITransactions {
)
public
returns (bytes[] memory);

/// @dev The current function will be called in the context of this address (either 0x transaction signer or `msg.sender`).
/// If calling a fill function, this address will represent the taker.
/// If calling a cancel function, this address will represent the maker.
/// @return Signer of 0x transaction if entry point is `executeTransaction`.
/// `msg.sender` if entry point is any other function.
function _getCurrentContextAddress()
internal
view
returns (address);
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,23 +89,6 @@ contract LibExchangeRichErrorDecoder is
validatorAddress = _readErrorParameterAsAddress(encoded, 1);
}

/// @dev Decompose an ABI-encoded SignatureOrderValidatorNotApprovedError.
/// @param encoded ABI-encoded revert error.
/// @return signerAddress The expected signer of the hash.
/// @return validatorAddress The expected validator.
function decodeSignatureOrderValidatorNotApprovedError(bytes memory encoded)
public
pure
returns (
address signerAddress,
address validatorAddress
)
{
_assertSelectorBytes(encoded, SIGNATURE_ORDER_VALIDATOR_NOT_APPROVED_ERROR_SELECTOR);
signerAddress = _readErrorParameterAsAddress(encoded, 0);
validatorAddress = _readErrorParameterAsAddress(encoded, 1);
}

/// @dev Decompose an ABI-encoded SignatureWalletError.
/// @param encoded ABI-encoded revert error.
/// @return errorCode The error code.
Expand All @@ -129,54 +112,6 @@ contract LibExchangeRichErrorDecoder is
errorData = _readErrorParameterAsBytes(encoded, 3);
}

/// @dev Decompose an ABI-encoded SignatureOrderValidatorError.
/// @param encoded ABI-encoded revert error.
/// @return errorCode The error code.
/// @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 decodeSignatureOrderValidatorError(bytes memory encoded)
public
pure
returns (
bytes32 hash,
address signerAddress,
address validatorAddress,
bytes memory signature,
bytes memory errorData
)
{
_assertSelectorBytes(encoded, SIGNATURE_ORDER_VALIDATOR_ERROR_SELECTOR);
hash = _readErrorParameterAsBytes32(encoded, 0);
signerAddress = _readErrorParameterAsAddress(encoded, 1);
validatorAddress = _readErrorParameterAsAddress(encoded, 2);
signature = _readErrorParameterAsBytes(encoded, 3);
errorData = _readErrorParameterAsBytes(encoded, 4);
}

/// @dev Decompose an ABI-encoded SignatureOrderWalletError.
/// @param encoded ABI-encoded revert error.
/// @return errorCode The error code.
/// @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 decodeSignatureOrderWalletError(bytes memory encoded)
public
pure
returns (
bytes32 hash,
address signerAddress,
bytes memory signature,
bytes memory errorData
)
{
_assertSelectorBytes(encoded, SIGNATURE_ORDER_WALLET_ERROR_SELECTOR);
hash = _readErrorParameterAsBytes32(encoded, 0);
signerAddress = _readErrorParameterAsAddress(encoded, 1);
signature = _readErrorParameterAsBytes(encoded, 2);
errorData = _readErrorParameterAsBytes(encoded, 3);
}

/// @dev Decompose an ABI-encoded OrderStatusError.
/// @param encoded ABI-encoded revert error.
/// @return orderHash The order hash.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ contract TestValidatorWallet is
/// @dev The data type of a hash.
mapping (bytes32 => DataType) internal _hashDataTypes;
/// @dev keccak256 of the expected signature data for a hash.
mapping (bytes32 => DataType) internal _hashSignatureHashes;
mapping (bytes32 => bytes32) internal _hashSignatureHashes;

constructor(address exchange) public {
_exchange = ISimplifiedExchange(exchange);
Expand Down