0

can someone help me with this ecrecover issue? The code below is a truffle test. The recoverSigner function just calls ecrecover, but the return is always '0x'. Recovering with ethereumjs-util works fine.

Geth v1.8.17 (clique private network) Truffle v4.1.14 Solidity v0.4.24

//Front-end
const msg = new Buffer('hello')
const sig = web3.eth.sign(web3.eth.accounts[0], '0x' + msg.toString('hex'))

//Back-end
const res = ethUtil.fromRpcSig(sig)
const prefix = new Buffer("\x19Ethereum Signed Message:\n")
const prefixedMsg = ethUtil.keccak256(Buffer.concat([prefix, New Buffer(String(msg.length)), msg]))
const pubKey  = ethUtil.ecrecover(prefixedMsg, res.v, res.r, res.s)
const addrBuf = ethUtil.pubToAddress(pubKey)
const addrEthJS = ethUtil.bufferToHex(addrBuf)
assert.equal(accounts[0], addrEthJS) // Ok!

//Ethereum Network
let addrSolidity = await instance.recoverSigner(ethUtil.bufferToHex(prefixedMsg), res.v, ethUtil.bufferToHex(res.r), ethUtil.bufferToHex(res.s))
assert.equal(accounts[0], addrSolidity) // Fail! recoverSigner returns '0X'
0

0x means you pass not valid parameters.

Take a look the answer solidity ecrecovery and ethereumjs ecsign return different address

  • Thank You for you answer. There was a failure in 6 of the 8 tests at the repo indicated on the link. The 2 success cases were in the ecrecover3 function. All others returned '0x'. – Robert Oct 20 '18 at 1:21
  • @Robert not sure about what tests you are talking, I see only one test there – Aquila Oct 20 '18 at 10:33
  • I was talking about github.com/davidmichaelakers/ecrecover test cases. – Robert Oct 20 '18 at 18:17
  • @Robert it causes because you have different versions of compiler and packages. I think the answer in similar question should work for you. Take a look section UPDATE 2: Working solution – Aquila Oct 21 '18 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.