@0x/contracts-exchange
: Refactor out EIP1271_MAGIC_VALUE
into a LibEIP1271
contract and inherit from that.
`@0x/contracts-exchange`: Use `LibBytes.readBytes4()` to validate EIP1271 return values and be more permissive of shorter return values. `@0x/contracts-exchange`: Use `abi.decode()` for `EIP1271OrderWallet` in `TestSignatureValidator.sol`. `@0x/contracts-exchange`: Correct minor formatting changes in contracts.
This commit is contained in:
parent
5dfb65b084
commit
0eb5c825a5
@ -20,6 +20,7 @@ pragma solidity ^0.5.9;
|
|||||||
pragma experimental ABIEncoderV2;
|
pragma experimental ABIEncoderV2;
|
||||||
|
|
||||||
import "@0x/contracts-utils/contracts/src/LibBytes.sol";
|
import "@0x/contracts-utils/contracts/src/LibBytes.sol";
|
||||||
|
import "@0x/contracts-utils/contracts/src/LibEIP1271.sol";
|
||||||
import "@0x/contracts-utils/contracts/src/ReentrancyGuard.sol";
|
import "@0x/contracts-utils/contracts/src/ReentrancyGuard.sol";
|
||||||
import "@0x/contracts-utils/contracts/src/RichErrors.sol";
|
import "@0x/contracts-utils/contracts/src/RichErrors.sol";
|
||||||
import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol";
|
import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol";
|
||||||
@ -36,14 +37,12 @@ contract MixinSignatureValidator is
|
|||||||
MixinExchangeRichErrors,
|
MixinExchangeRichErrors,
|
||||||
ReentrancyGuard,
|
ReentrancyGuard,
|
||||||
LibOrder,
|
LibOrder,
|
||||||
|
LibEIP1271,
|
||||||
ISignatureValidator,
|
ISignatureValidator,
|
||||||
MixinTransactions
|
MixinTransactions
|
||||||
{
|
{
|
||||||
using LibBytes for bytes;
|
using LibBytes for bytes;
|
||||||
|
|
||||||
// Magic bytes returned by EIP1271 wallets on success.
|
|
||||||
bytes4 constant public EIP1271_MAGIC_VALUE = 0x20c13b0b;
|
|
||||||
|
|
||||||
// Mapping of hash => signer => signed
|
// Mapping of hash => signer => signed
|
||||||
mapping (bytes32 => mapping (address => bool)) public preSigned;
|
mapping (bytes32 => mapping (address => bool)) public preSigned;
|
||||||
|
|
||||||
@ -385,8 +384,8 @@ contract MixinSignatureValidator is
|
|||||||
// Static call the verification function.
|
// Static call the verification function.
|
||||||
(bool didSucceed, bytes memory returnData) = walletAddress.staticcall(callData);
|
(bool didSucceed, bytes memory returnData) = walletAddress.staticcall(callData);
|
||||||
// Return data should be the `EIP1271_MAGIC_VALUE`.
|
// Return data should be the `EIP1271_MAGIC_VALUE`.
|
||||||
if (didSucceed && returnData.length == 32) {
|
if (didSucceed && returnData.length <= 32) {
|
||||||
return bytes4(returnData.readBytes32(0)) == EIP1271_MAGIC_VALUE;
|
return returnData.readBytes4(0) == EIP1271_MAGIC_VALUE;
|
||||||
}
|
}
|
||||||
// Static call to verifier failed.
|
// Static call to verifier failed.
|
||||||
_rrevert(SignatureWalletError(
|
_rrevert(SignatureWalletError(
|
||||||
@ -544,8 +543,8 @@ contract MixinSignatureValidator is
|
|||||||
// Static call the verification function.
|
// Static call the verification function.
|
||||||
(bool didSucceed, bytes memory returnData) = walletAddress.staticcall(callData);
|
(bool didSucceed, bytes memory returnData) = walletAddress.staticcall(callData);
|
||||||
// Return data should be the `EIP1271_MAGIC_VALUE`.
|
// Return data should be the `EIP1271_MAGIC_VALUE`.
|
||||||
if (didSucceed && returnData.length == 32) {
|
if (didSucceed && returnData.length <= 32) {
|
||||||
return bytes4(returnData.readBytes32(0)) == EIP1271_MAGIC_VALUE;
|
return returnData.readBytes4(0) == EIP1271_MAGIC_VALUE;
|
||||||
}
|
}
|
||||||
// Static call to verifier failed.
|
// Static call to verifier failed.
|
||||||
_rrevert(SignatureOrderWalletError(
|
_rrevert(SignatureOrderWalletError(
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
|
|
||||||
Copyright 2018 ZeroEx Intl.
|
Copyright 2019 ZeroEx Intl.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@ -18,12 +18,11 @@
|
|||||||
|
|
||||||
pragma solidity ^0.5.9;
|
pragma solidity ^0.5.9;
|
||||||
|
|
||||||
|
import "@0x/contracts-utils/contracts/src/LibEIP1271.sol";
|
||||||
|
|
||||||
contract IEIP1271Wallet {
|
contract IEIP1271Wallet is
|
||||||
|
LibEIP1271
|
||||||
// Magic bytes returned by EIP1271 wallets on success.
|
{
|
||||||
bytes4 constant public EIP1271_MAGIC_VALUE = 0x20c13b0b;
|
|
||||||
|
|
||||||
/// @dev Verifies that a signature is valid.
|
/// @dev Verifies that a signature is valid.
|
||||||
/// @param data Arbitrary data.
|
/// @param data Arbitrary data.
|
||||||
/// @param signature Signature of `data`.
|
/// @param signature Signature of `data`.
|
||||||
|
@ -22,6 +22,7 @@ pragma experimental ABIEncoderV2;
|
|||||||
import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol";
|
import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol";
|
||||||
import "@0x/contracts-erc20/contracts/src/interfaces/IERC20Token.sol";
|
import "@0x/contracts-erc20/contracts/src/interfaces/IERC20Token.sol";
|
||||||
import "@0x/contracts-utils/contracts/src/LibBytes.sol";
|
import "@0x/contracts-utils/contracts/src/LibBytes.sol";
|
||||||
|
import "@0x/contracts-utils/contracts/src/LibEIP1271.sol";
|
||||||
|
|
||||||
|
|
||||||
interface ISimplifiedExchange {
|
interface ISimplifiedExchange {
|
||||||
@ -33,13 +34,13 @@ interface ISimplifiedExchange {
|
|||||||
|
|
||||||
|
|
||||||
// solhint-disable no-unused-vars
|
// solhint-disable no-unused-vars
|
||||||
contract TestValidatorWallet {
|
contract TestValidatorWallet is
|
||||||
|
LibEIP1271
|
||||||
|
{
|
||||||
using LibBytes for bytes;
|
using LibBytes for bytes;
|
||||||
|
|
||||||
// Revert reason for `Revert` `ValidatorAction`.
|
// Revert reason for `Revert` `ValidatorAction`.
|
||||||
string constant public REVERT_REASON = "you shall not pass";
|
string constant public REVERT_REASON = "you shall not pass";
|
||||||
// Magic bytes returned by EIP1271 wallets on success.
|
|
||||||
bytes4 constant public EIP1271_MAGIC_VALUE = 0x20c13b0b;
|
|
||||||
|
|
||||||
enum ValidatorAction {
|
enum ValidatorAction {
|
||||||
// Return false (default)
|
// Return false (default)
|
||||||
@ -281,16 +282,7 @@ contract TestValidatorWallet {
|
|||||||
returns (LibOrder.Order memory order)
|
returns (LibOrder.Order memory order)
|
||||||
{
|
{
|
||||||
require(data.length > 32, "INVALID_EIP1271_ORDER_DATA_LENGTH");
|
require(data.length > 32, "INVALID_EIP1271_ORDER_DATA_LENGTH");
|
||||||
assembly {
|
return abi.decode(data, (LibOrder.Order));
|
||||||
// Skip past the length to find the first parameter.
|
|
||||||
let argsStart := add(data, 32)
|
|
||||||
order := add(argsStart, mload(argsStart))
|
|
||||||
// Destructively point the asset data fields to absolute locations.
|
|
||||||
for {let o := 0x140} lt(o, 0x1C0) {o := add(o, 0x20)} {
|
|
||||||
let arg := add(order, o)
|
|
||||||
mstore(arg, add(argsStart, add(mload(arg), 0x20)))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user