Debug contract

This commit is contained in:
Oskar Thoren 2021-02-05 19:14:06 +08:00
parent f2d957affc
commit 37b3fc3fbb
No known key found for this signature in database
GPG Key ID: BDB55C8C0EF29911
1 changed files with 24 additions and 3 deletions

View File

@ -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");