0

I am trying to understand how eliptic curve work and when i try to get the sender of this transaction: https://etherscan.io/tx/0x14a298c1eea89f42285948b7d51eeac2876ca7406c9784b9b90dd3591d156d64 ( spoiler the sender address is: 0x8d900bfa2353548a4631be870f99939575551b60). I follow the answer from this old question: Hash of the transaction VS Transaction Hash or Transaction ID. And the ecrecover function i use is pyethereum.utils.ecrecover_to_pub.

But when i try to recover back the address, i can't get the sender address.

The function i used is: hash = HexBytes('0xa4060d01d4add248db470b4121616cbe5b2015daf328809000ec9a1d0954d649') ecrecover_to_pub(hash, 27, 0x067940651530790861714b2e8fd8b080361d1ada048189000c07a66848afde46, 0x69b041db7c29dbcc6becf42017ca7ac086b12bd53ec8ee494596f790fb6a0a69).hex()[-40:] which the result address is 0xd124db72eff486dad933df8cc5ec97acb26144ae

i think i have set the v, r, s right because i got the v, r, s using web3.eth.getTransaction('0x14a298c1eea89f42285948b7d51eeac2876ca7406c9784b9b90dd3591d156d64').

The v, r, s from the result function are: 37, 0x067940651530790861714b2e8fd8b080361d1ada048189000c07a66848afde46, 0x69b041db7c29dbcc6becf42017ca7ac086b12bd53ec8ee494596f790fb6a0a69

1

shouldn't you send 37 instead of 27 to ecrecover_to_pub as the value of v?

EDIT: Updating the answer, because in the comments the code is unreadable

simple contract in Solidity returns the correct address:

contract ECRecover {
    function ECR(bytes32 _Msg, uint8 _v, bytes32 _r, bytes32 _s) public pure returns (address) {
        return ecrecover(_Msg, _v, _r, _s);
    }
}

So the problem is with the python code ... from the docs:

ecrecover_to_pub(hash, v, r, s) - recovers the public key that made the signature as a 64-byte binary blob of encode_int32(x) + encode_int32(y). Hashing this and taking the last 20 bytes gives the address that signed a message.

It seems you are not hashing the result before taking the last 20 bytes, so it should be:

sha3(ecrecover_to_pub(hash, 27, 0x067940651530790861714b2e8fd8b080361d1ada048189000c07a66848afde46, 0x69b041db7c29dbcc6becf42017ca7ac086b12bd53ec8ee494596f790fb6a0a69).hex())[-40:]
  • According to the ethereum yellow paper, the fomula (291) and (292) say that the ecrecovet should be 27 if the v is odd and 28 if the v is even. So if u set the v different from that it will return address(0) – haxerl May 19 at 1:34

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.