VIP: 495
Title: Builtin ecrecovery function.
Author: Jacques Wagener
Type: Standard Track
Status: Draft
Created: 23-11-2017
Adding ecrecovery function to help with verifying address message signatures.
Adding ecrecovery function to help with verifying compact address message signatures.
Currently viper has a builtin ecrecover function, which works on three 32 bytes length words r, s, v when called. However with a lot of existing solidity contracts, are using the compact signature format, which packs the same into 66bytes instead of 96bytes. This proposal is to implement a builtin function named ecrecovery which handles the 66byte compact version.
Solidity implementation: https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/contracts/ECRecovery.sol
owner: address
def __init__():
self.owner = msg.sender
# 3x 32 bytes ecrecover usage.
@public
def sigdata_verify(h: bytes32, sigdata: num256[3]) -> bool:
if ecrecover(h, sigdata[0], sigdata[1], sigdata[2]) == self.owner:
return True
else:
return False
# compact signature usage.
@public
def sig_verify(h: bytes32, sig: bytes <= 66) -> bool:
r = extract32(sig, 0, type=num256)
s = extract32(sig, 32, type=num256)
sliced = slice(sig, start=64, len=1)
v = as_num256(bytes_to_num(sliced))
if ecrecover(h, r, s, v) == self.owner:
return True
else:
return False
With builtin ecrecovery function a signature verfiy would look as follows:
def sig_verify(h: bytes32, sig: bytes <= 66) -> bool:
if ecrecovery(h, sig) == self.owner:
return True
else:
return False
No problem, as it's a new function.
Copyright and related rights waived via CC0
Another idea that this triggered is that we start maintaining a 'Solidity to Viper' section in the documentation, which we could then place patterns like these. However I really like the idea of having 'batteries' included. :smile: https://github.com/ethereum/viper/issues/482 could be an example of this.
I'm on this 馃憤
Suggest deprecating this proposal in favor of #1020, which would be more extensible for future signature types, as well as more broadly useful for recovery of transaction signatures.
Perhaps the name ecrecovery is too close to ecrecover / not clear from the name what the difference is. Suggest the function be named something along the lines of ecrecover_packed.
Valid point, I agree we should pick something clearer.
For people who use it before it gets built-in, there are an implementation and a simple test.
Thanks @nrryuya ! As always - much appreciated :)
Most helpful comment
For people who use it before it gets built-in, there are an implementation and a simple test.