Skip to content

Instantly share code, notes, and snippets.

@jstoxrocky
Created December 23, 2017 14:43
Show Gist options
  • Save jstoxrocky/39f8abfa87079eb70bb2348adef89bac to your computer and use it in GitHub Desktop.
Save jstoxrocky/39f8abfa87079eb70bb2348adef89bac to your computer and use it in GitHub Desktop.
def ecrecover(h, v, r, s):
"""
Function recreating solidity's ecrecover
Args:
h: The Keccak hash of the msg
v: The "v" parameter derived from the signed message (ethereum.utils.ecsign)
r: The "r" parameter derived from the signed message (ethereum.utils.ecsign)
s: The "s" parameter derived from the signed message (ethereum.utils.ecsign)
Returns:
Address of the message signer as a hexidecimal string
"""
pub = ecrecover_to_pub(h, v, r, s)
addr = keccak(pub)[-20:]
addr = encode_hex(addr)
addr = to_checksum_address(addr)
return addr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment