From 37b3fc3fbb104596d68a7a9b60a61169db3aa82b Mon Sep 17 00:00:00 2001 From: Oskar Thoren Date: Fri, 5 Feb 2021 19:14:06 +0800 Subject: [PATCH] Debug contract --- contracts/ERC20SimpleSwap.sol | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/contracts/ERC20SimpleSwap.sol b/contracts/ERC20SimpleSwap.sol index 5668f77..426b330 100644 --- a/contracts/ERC20SimpleSwap.sol +++ b/contracts/ERC20SimpleSwap.sol @@ -4,6 +4,8 @@ import "@openzeppelin/contracts/math/Math.sol"; import "@openzeppelin/contracts/cryptography/ECDSA.sol"; import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; +import "hardhat/console.sol"; + /** @title Chequebook contract without waivers @author The Swarm Authors @@ -71,7 +73,10 @@ contract ERC20SimpleSwap { } // compute the EIP712 domain separator. this cannot be constant because it depends on chainId - function domainSeparator(EIP712Domain memory eip712Domain) internal pure returns (bytes32) { + function domainSeparator(EIP712Domain memory eip712Domain) internal returns (bytes32) { + console.log("domainSeparator name", eip712Domain.name); + console.log("domainSeparator version", eip712Domain.version); + console.log("domainSeparator chainId", eip712Domain.chainId); return keccak256(abi.encode( EIP712DOMAIN_TYPEHASH, keccak256(bytes(eip712Domain.name)), @@ -81,12 +86,20 @@ contract ERC20SimpleSwap { } // recover a signature with the EIP712 signing scheme - function recoverEIP712(bytes32 hash, bytes memory sig) internal pure returns (address) { + function recoverEIP712(bytes32 hash, bytes memory sig) internal returns (address) { + console.log("recoverEIP712 hash"); + console.logBytes32(hash); bytes32 digest = keccak256(abi.encodePacked( "\x19\x01", domainSeparator(domain()), hash )); + console.log("recoverEIP712 digest"); + console.logBytes32(digest); + console.log("recoverEIP712 sig"); + console.logBytes(sig); + console.log("ECDSA recover", ECDSA.recover(digest, sig)); + // TODO redo and print return ECDSA.recover(digest, sig); } @@ -145,7 +158,15 @@ contract ERC20SimpleSwap { uint callerPayout, bytes memory issuerSig ) internal { - /* The issuer must have given explicit approval to the cumulativePayout, either by being the caller or by signature*/ + + //var hash = chequeHash(address(this), beneficiary, cumulativePayout); + console.log("_cashChequeInternal"); + console.log("address this", address(this)); + console.log("beneficiary", beneficiary); + console.log("cumulativePayout", cumulativePayout); + // XXX don't work + //console.log("issuerSig", issuerSig); + //console.log("hash", chequeHash(address(this), beneficiary, cumulativePayout)); if (msg.sender != issuer) { require(issuer == recoverEIP712(chequeHash(address(this), beneficiary, cumulativePayout), issuerSig), "SimpleSwap: invalid issuer signature");