@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;
|
||||
|
||||
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/RichErrors.sol";
|
||||
import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol";
|
||||
@ -36,14 +37,12 @@ contract MixinSignatureValidator is
|
||||
MixinExchangeRichErrors,
|
||||
ReentrancyGuard,
|
||||
LibOrder,
|
||||
LibEIP1271,
|
||||
ISignatureValidator,
|
||||
MixinTransactions
|
||||
{
|
||||
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 (bytes32 => mapping (address => bool)) public preSigned;
|
||||
|
||||
@ -385,8 +384,8 @@ contract MixinSignatureValidator is
|
||||
// Static call the verification function.
|
||||
(bool didSucceed, bytes memory returnData) = walletAddress.staticcall(callData);
|
||||
// Return data should be the `EIP1271_MAGIC_VALUE`.
|
||||
if (didSucceed && returnData.length == 32) {
|
||||
return bytes4(returnData.readBytes32(0)) == EIP1271_MAGIC_VALUE;
|
||||
if (didSucceed && returnData.length <= 32) {
|
||||
return returnData.readBytes4(0) == EIP1271_MAGIC_VALUE;
|
||||
}
|
||||
// Static call to verifier failed.
|
||||
_rrevert(SignatureWalletError(
|
||||
@ -544,8 +543,8 @@ contract MixinSignatureValidator is
|
||||
// Static call the verification function.
|
||||
(bool didSucceed, bytes memory returnData) = walletAddress.staticcall(callData);
|
||||
// Return data should be the `EIP1271_MAGIC_VALUE`.
|
||||
if (didSucceed && returnData.length == 32) {
|
||||
return bytes4(returnData.readBytes32(0)) == EIP1271_MAGIC_VALUE;
|
||||
if (didSucceed && returnData.length <= 32) {
|
||||
return returnData.readBytes4(0) == EIP1271_MAGIC_VALUE;
|
||||
}
|
||||
// Static call to verifier failed.
|
||||
_rrevert(SignatureOrderWalletError(
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
|
||||
Copyright 2018 ZeroEx Intl.
|
||||
Copyright 2019 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@ -18,12 +18,11 @@
|
||||
|
||||
pragma solidity ^0.5.9;
|
||||
|
||||
import "@0x/contracts-utils/contracts/src/LibEIP1271.sol";
|
||||
|
||||
contract IEIP1271Wallet {
|
||||
|
||||
// Magic bytes returned by EIP1271 wallets on success.
|
||||
bytes4 constant public EIP1271_MAGIC_VALUE = 0x20c13b0b;
|
||||
|
||||
contract IEIP1271Wallet is
|
||||
LibEIP1271
|
||||
{
|
||||
/// @dev Verifies that a signature is valid.
|
||||
/// @param data Arbitrary 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-erc20/contracts/src/interfaces/IERC20Token.sol";
|
||||
import "@0x/contracts-utils/contracts/src/LibBytes.sol";
|
||||
import "@0x/contracts-utils/contracts/src/LibEIP1271.sol";
|
||||
|
||||
|
||||
interface ISimplifiedExchange {
|
||||
@ -33,13 +34,13 @@ interface ISimplifiedExchange {
|
||||
|
||||
|
||||
// solhint-disable no-unused-vars
|
||||
contract TestValidatorWallet {
|
||||
contract TestValidatorWallet is
|
||||
LibEIP1271
|
||||
{
|
||||
using LibBytes for bytes;
|
||||
|
||||
// Revert reason for `Revert` `ValidatorAction`.
|
||||
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 {
|
||||
// Return false (default)
|
||||
@ -60,9 +61,9 @@ contract TestValidatorWallet {
|
||||
/// @dev Internal state to modify.
|
||||
uint256 internal _state = 1;
|
||||
/// @dev What action to execute when a hash is validated .
|
||||
mapping (bytes32=>ValidatorAction) internal _hashActions;
|
||||
mapping (bytes32 => ValidatorAction) internal _hashActions;
|
||||
/// @dev Allowed signers for hash signature types.
|
||||
mapping (bytes32=>address) internal _validSignerForHash;
|
||||
mapping (bytes32 => address) internal _validSignerForHash;
|
||||
|
||||
constructor(address exchange) public {
|
||||
_exchange = ISimplifiedExchange(exchange);
|
||||
@ -281,16 +282,7 @@ contract TestValidatorWallet {
|
||||
returns (LibOrder.Order memory order)
|
||||
{
|
||||
require(data.length > 32, "INVALID_EIP1271_ORDER_DATA_LENGTH");
|
||||
assembly {
|
||||
// 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)))
|
||||
}
|
||||
}
|
||||
return abi.decode(data, (LibOrder.Order));
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user