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: Update tests for new/consolidated signature…
… types.

`@0x/contracts-exchange`: Update `Whitelist` example for new signature types.
  • Loading branch information
dorothy-zbornak committed Jun 26, 2019
commit 13e0433a08da13f2339e83e1c22376ab933ade1a
18 changes: 7 additions & 11 deletions contracts/exchange/CHANGELOG.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,35 +79,31 @@
"pr": 1868
},
{
"note": "Always check `OrderValidator` and `WalletOrderValidator` signature types on every fill",
"note": "Add `EIP1271Wallet` signature type",
"pr": 1885
},
{
"note": "Rename `WalletOrderValidator` to `OrderWallet` signature type",
"note": "Remove `WalletOrderValidator` and `OrderValidator` signature types",
"pr": 1885
},
{
"note": "Rename `SignatureWalletOrderValidatorError` to `SignatureOrderWalletError`",
"note": "Make the regular `Validator` signature type have EIP1271 behavior",
"pr": 1885
},
{
"note": "Add `IEIP1271Wallet` interface",
"note": "Always check signature types that are validated via contract (not just on first fill).",
"pr": 1885
},
{
"note": "Add `EIP1271Wallet` and `EIP1271OrderWallet` to `SignatureType`",
"note": "Remove unecessary rich revert error types.",
"pr": 1885
},
{
"note": "Always check `OrderValidator`, `OrderWallet`, `EIP1271OrderWallet` signature types on every fill",
"pr": 1885
},
{
"note": "Add `validatorAddress` field to `SignatureValidatorError` and `SignatureOrderValidatorError` rich reverts",
"note": "Add `IEIP1271Wallet` interface",
"pr": 1885
},
{
"note": "Add separate `SignatureOrderValidatorNotApprovedError` for `OrderValidator` signatures",
"note": "Add `validatorAddress` field to `SignatureValidatorError` rich reverts",
"pr": 1885
}
]
Expand Down
22 changes: 14 additions & 8 deletions contracts/exchange/contracts/examples/Whitelist.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ import "../src/interfaces/IExchange.sol";
import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol";
import "@0x/contracts-exchange-libs/contracts/src/LibZeroExTransaction.sol";
import "@0x/contracts-utils/contracts/src/Ownable.sol";
import "@0x/contracts-utils/contracts/src/LibEIP1271.sol";


contract Whitelist is
Ownable
Ownable,
LibEIP1271
{
// Mapping of address => whitelist status.
mapping (address => bool) public isWhitelisted;
Expand Down Expand Up @@ -59,24 +61,28 @@ contract Whitelist is
isWhitelisted[target] = isApproved;
}

/// @dev Verifies signer is same as signer of current Ethereum transaction.
/// @dev Verifies a ZeroExTransaction's signer is same as signer of current Ethereum transaction.
/// NOTE: This function can currently be used to validate signatures coming from outside of this contract.
/// Extra safety checks can be added for a production contract.
/// @param signerAddress Address that should have signed the given hash.
/// @param data The abi-encoded ZeroExTransaction.
/// @param signature Proof of signing.
/// @return Validity of order signature.
/// @return magicValue `EIP1271_MAGIC_VALUE` if the signature is authorized.
// solhint-disable no-unused-vars
function isValidSignature(
bytes32 hash,
address signerAddress,
bytes calldata data,
bytes calldata signature
)
external
view
returns (bool isValid)
returns (bytes4 magicValue)
{
// Decode the ZeroExTransaction.
LibZeroExTransaction.ZeroExTransaction memory transaction =
abi.decode(data, (LibZeroExTransaction.ZeroExTransaction));
// solhint-disable-next-line avoid-tx-origin
return signerAddress == tx.origin;
if (transaction.signerAddress == tx.origin) {
magicValue = EIP1271_MAGIC_VALUE;
}
}
// solhint-enable no-unused-vars

Expand Down
4 changes: 2 additions & 2 deletions contracts/exchange/contracts/test/TestValidatorWallet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,10 @@ contract TestValidatorWallet is
view
returns (bytes32 hash)
{
// HACK(dorothy-zbornak): First we want the hash, which is the second
// First we want the hash, which is the second
// encoded parameter. We will initially treat all fields as inline
// `bytes32`s and ignore the first one to extract it.
(,hash) = abi.decode(data, (bytes32, bytes32));
(, hash) = abi.decode(data, (bytes32, bytes32));
// Now we can figure out what the data type is from a previous call to
// `prepare()`.
DataType dataType = _hashDataTypes[hash];
Expand Down
27 changes: 14 additions & 13 deletions contracts/exchange/test/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
constants,
ERC20BalancesByOwner,
getLatestBlockTimestampAsync,
hexConcat,
increaseTimeAndMineBlockAsync,
OrderFactory,
OrderStatus,
Expand All @@ -36,7 +37,6 @@ import { BigNumber, providerUtils, StringRevertError } from '@0x/utils';
import { Web3Wrapper } from '@0x/web3-wrapper';
import * as chai from 'chai';
import { LogWithDecodedArgs } from 'ethereum-types';
import ethUtil = require('ethereumjs-util');
import * as _ from 'lodash';

import { Erc1155Wrapper } from '../../erc1155/lib/src';
Expand Down Expand Up @@ -267,21 +267,22 @@ describe('Exchange core', () => {
constants.INITIAL_ERC20_BALANCE,
);
// Approve the validator.
await exchange.setSignatureValidatorApproval.awaitTransactionSuccessAsync(validatorWallet.address, true, {
from: makerAddress,
});
await exchange.setSignatureValidatorApproval.awaitTransactionSuccessAsync(
validatorWallet.address,
true,
{
from: makerAddress,
},
);
signedOrder = await orderFactory.newSignedOrderAsync({
makerFee: constants.ZERO_AMOUNT,
takerFee: constants.ZERO_AMOUNT,
});
});

it('should revert if `Validator` signature type rejects during a second fill', async () => {
const signature = Buffer.concat([
ethUtil.toBuffer(validatorWallet.address),
ethUtil.toBuffer([SignatureType.Validator]),
]);
signedOrder.signature = ethUtil.bufferToHex(signature);
const signatureHex = hexConcat(validatorWallet.address, SignatureType.Validator);
signedOrder.signature = signatureHex;
const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
// Allow the signature check for the first fill.
await validatorWallet.prepare.awaitTransactionSuccessAsync(
Expand Down Expand Up @@ -312,9 +313,9 @@ describe('Exchange core', () => {
});

it('should revert if `Wallet` signature type rejects during a second fill', async () => {
const signature = Buffer.concat([ethUtil.toBuffer([SignatureType.Wallet])]);
const signatureHex = hexConcat(SignatureType.Wallet);
signedOrder.makerAddress = validatorWallet.address;
signedOrder.signature = ethUtil.bufferToHex(signature);
signedOrder.signature = signatureHex;
const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
// Allow the signature check for the first fill.
await validatorWallet.prepare.awaitTransactionSuccessAsync(
Expand Down Expand Up @@ -345,9 +346,9 @@ describe('Exchange core', () => {
});

it('should revert if `EIP1271Wallet` signature type rejects during a second fill', async () => {
const signature = Buffer.concat([ethUtil.toBuffer([SignatureType.EIP1271Wallet])]);
const signatureHex = hexConcat(SignatureType.EIP1271Wallet);
signedOrder.makerAddress = validatorWallet.address;
signedOrder.signature = ethUtil.bufferToHex(signature);
signedOrder.signature = signatureHex;
const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
// Allow the signature check for the first fill.
await validatorWallet.prepare.awaitTransactionSuccessAsync(
Expand Down
Loading