Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Repro for Geth 1.8.x `eth.call` regression
#!/usr/bin/env node
const Child_process = require('child_process')
const Web3 = require('web3')
const Assert = require('assert')
const SOL = `
contract BS {
function isValidSignature(
address signer,
bytes32 hash,
uint8 v,
bytes32 r,
bytes32 s)
public
constant
returns (bool)
{
return signer == ecrecover(
keccak256("\\x19Ethereum Signed Message:\\n32", hash),
v,
r,
s
);
}
function ecRecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) public constant returns(address) {
return ecrecover(hash,v,r,s);
}
function keccak(bytes32 hash) public constant returns(bytes32) {
return keccak256(hash);
}
function keccakX(bytes32 hash) public constant returns(bytes32) {
return keccak256("\\x19Ethereum Signed Message:\\n32", hash);
}
}`
async function run () {
// Compile bs.sol first
const child = Child_process.spawnSync("solc",['-', '--combined-json', 'abi,bin'],
{input: SOL, encoding: "utf8"})
Assert.strictEqual(child.status, 0, child.output[2])
const contracts = Object.values(JSON.parse(child.output[1]).contracts)
const web3 = new Web3('http://localhost:8545')
const addresses = await web3.eth.personal.getAccounts()
Assert.ok(addresses[0], "Need address[0] for deployment")
console.log("Deploying with", addresses[0])
const balance = await web3.eth.getBalance(addresses[0])
Assert.ok(balance > 0, "Need some ether for deployment")
const abi = JSON.parse(contracts[0].abi)
const contract = await new web3.eth.Contract(abi, null)
.deploy({data: "0x"+contracts[0].bin})
.send({from: addresses[0], gas: 1000000})
contract.setProvider(web3.currentProvider)
const maker = "0xc1b70e056bc09c33d7d0f668bd49e69c6d1a74d0"
const rnd = "0x7e568cb5eedc46ac087c6a291e108dd621f1569893269b478caf31658ce0568a"
console.log("Test keccak256 call")
const result = await contract.methods.keccak(rnd).call()
const hash = web3.utils.keccak256(rnd)
Assert.strictEqual(hash, result)
console.log("Test keccak256 call with multiple args")
const result2 = await contract.methods.keccakX(rnd).call()
const hash2 = web3.utils.soliditySha3("\x19Ethereum Signed Message:\n32", rnd)
Assert.strictEqual(hash2, result2)
const [h,v,r,s] = [
"0x7e568cb5eedc46ac087c6a291e108dd621f1569893269b478caf31658ce0568a",
"0x1b",
"0xd01a67d067f3725e592851a3ceb4203c95da65ba99e76de1d2cfd5a94084272e",
"0x3eeb83a3d715689a2187cdc11fbde44dff6a27b77d71a86a1c68fa04374d2362"]
console.log("Test ecrecover transaction")
const tx = await contract.methods.ecRecover(h,v,r,s).send({from:addresses[0]})
Assert.equal(tx.status, 1)
console.log("Test ecrecover call")
const result3 = await contract.methods.ecRecover(h,v,r,s).call()
Assert.strictEqual("0xF23978a1fE45225D5E28C6730a5BD82D7e37865f", result3)
console.log("Test keccak256+ecrecover call")
const result4 = await contract.methods.isValidSignature(maker,h,v,r,s).call()
Assert.strictEqual(true, result4)
console.log("Success.")
}
run().catch(err => {
console.error(err.stack)
process.exitCode = 1
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment