Skip to content

Instantly share code, notes, and snippets.

@vkobel
Created July 6, 2017 13:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vkobel/c23ac4e6a8a094dcd8759ebabcfc70ab to your computer and use it in GitHub Desktop.
Save vkobel/c23ac4e6a8a094dcd8759ebabcfc70ab to your computer and use it in GitHub Desktop.
Ethereum Solidity - example contract that shows how to use the ecrecover function to works along with eth_sign
pragma solidity ^0.4.11;
contract EcRecover {
function verify(bytes32 hash, uint8 v, bytes32 r, bytes32 s) returns (address) {
bytes32 prefixedHash = sha3("\x19Ethereum Signed Message:\n32", hash);
return ecrecover(prefixedHash, v, r, s);
}
}
@vkobel
Copy link
Author

vkobel commented Jul 6, 2017

The trick is that eth_sign is prefixing its hash with the string "\x19Ethereum Signed Message:\n32".
32 is the length of the hash (fixed in this case).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment