Skip to content

Commit

Permalink
Updated EIP712 implementation and fixed a non-passing test. (#66)
Browse files Browse the repository at this point in the history
* Fixed expiration time for one test.

* Fixed outdated EIP712 implementation.
  • Loading branch information
itsMarcoSolis authored Jan 31, 2022
1 parent e09e6ec commit 403f866
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 22 deletions.
9 changes: 4 additions & 5 deletions contracts/TestERC1271.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,20 @@ contract TestERC1271 is ERC1271 {
/**
* Check if a signature is valid
*
* @param _data Data signed over
* @param _signature Encoded signature
* @param _hash Hash of the data to be signed
* @param _signature Signature encoded as (bytes32 r, bytes32 s, uint8 v)
* @return magicValue Magic value if valid, zero-value otherwise
*/
function isValidSignature(
bytes memory _data,
bytes32 _hash,
bytes memory _signature)
override
public
view
returns (bytes4 magicValue)
{
bytes32 hash = abi.decode(_data, (bytes32));
(uint8 v, bytes32 r, bytes32 s) = abi.decode(_signature, (uint8, bytes32, bytes32));
if (owner == ecrecover(hash, v, r, s)) {
if (owner == ecrecover(_hash, v, r, s)) {
return MAGICVALUE;
} else {
return SIGINVALID;
Expand Down
4 changes: 2 additions & 2 deletions contracts/exchange/ExchangeCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import "../registry/AuthenticatedProxy.sol";
*/
contract ExchangeCore is ReentrancyGuarded, StaticCaller, EIP712 {

bytes4 constant internal EIP_1271_MAGICVALUE = 0x20c13b0b;
bytes4 constant internal EIP_1271_MAGICVALUE = 0x1626ba7e;
bytes internal personalSignPrefix = "\x19Ethereum Signed Message:\n";

/* Struct definitions. */
Expand Down Expand Up @@ -184,7 +184,7 @@ contract ExchangeCore is ReentrancyGuarded, StaticCaller, EIP712 {

/* (c): Contract-only authentication: EIP/ERC 1271. */
if (isContract) {
if (ERC1271(maker).isValidSignature(abi.encodePacked(calculatedHashToSign), signature) == EIP_1271_MAGICVALUE) {
if (ERC1271(maker).isValidSignature(calculatedHashToSign, signature) == EIP_1271_MAGICVALUE) {
return true;
}
return false;
Expand Down
28 changes: 14 additions & 14 deletions contracts/lib/EIP1271.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ pragma solidity 0.7.5;

abstract contract ERC1271 {

// bytes4(keccak256("isValidSignature(bytes,bytes)")
bytes4 constant internal MAGICVALUE = 0x20c13b0b;
// bytes4(keccak256("isValidSignature(bytes32,bytes)")
bytes4 constant internal MAGICVALUE = 0x1626ba7e;

/**
* @dev Should return whether the signature provided is valid for the provided data
* @param _data Arbitrary length data signed on the behalf of address(this)
* @param _signature Signature byte array associated with _data
* @dev Should return whether the signature provided is valid for the provided hash
* @param _hash Hash of the data to be signed
* @param _signature Signature byte array associated with _hash
*
* MUST return the bytes4 magic value 0x20c13b0b when function passes.
* MUST return the bytes4 magic value 0x1626ba7e when function passes.
* MUST NOT modify state (using STATICCALL for solc < 0.5, view modifier for solc > 0.5)
* MUST allow external calls
*/
*/
function isValidSignature(
bytes memory _data,
bytes memory _signature)
virtual
public
view
returns (bytes4 magicValue);
}
bytes32 _hash,
bytes memory _signature)
virtual
public
view
returns (bytes4 magicValue);
}
2 changes: 1 addition & 1 deletion test/4-wyvern-exchange-basics.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ contract('WyvernExchange',accounts => {

it('does not validate order parameters with expirationTime before now',async () => {
let {exchange,registry} = await withExchangeAndRegistry()
let example = {registry: registry.address,maker: accounts[0],staticTarget: exchange.inst.address,staticSelector: '0x00000000',staticExtradata: '0x',maximumFill: '1',listingTime: '0',expirationTime: '0',salt: '0'}
let example = {registry: registry.address,maker: accounts[0],staticTarget: exchange.inst.address,staticSelector: '0x00000000',staticExtradata: '0x',maximumFill: '1',listingTime: '0',expirationTime: '1',salt: '0'}
assert.isFalse(await exchange.validateOrderParameters(example),'Should not have validated')
})

Expand Down

0 comments on commit 403f866

Please sign in to comment.