diff --git a/contracts/exchange/contracts/src/MixinSignatureValidator.sol b/contracts/exchange/contracts/src/MixinSignatureValidator.sol index caa2d5680d..f3c13106af 100644 --- a/contracts/exchange/contracts/src/MixinSignatureValidator.sol +++ b/contracts/exchange/contracts/src/MixinSignatureValidator.sol @@ -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( diff --git a/contracts/exchange/contracts/src/interfaces/IEIP1271Wallet.sol b/contracts/exchange/contracts/src/interfaces/IEIP1271Wallet.sol index 4ede553bdd..03968d55e9 100644 --- a/contracts/exchange/contracts/src/interfaces/IEIP1271Wallet.sol +++ b/contracts/exchange/contracts/src/interfaces/IEIP1271Wallet.sol @@ -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`. diff --git a/contracts/exchange/contracts/test/TestValidatorWallet.sol b/contracts/exchange/contracts/test/TestValidatorWallet.sol index 3c24541d82..022661b6f0 100644 --- a/contracts/exchange/contracts/test/TestValidatorWallet.sol +++ b/contracts/exchange/contracts/test/TestValidatorWallet.sol @@ -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)); } }