Vyper: VIP: Builtin ecrecovery function

Created on 23 Nov 2017  路  7Comments  路  Source: vyperlang/vyper

Preamble

VIP: 495
Title: Builtin ecrecovery function.
Author: Jacques Wagener
Type: Standard Track
Status: Draft
Created: 23-11-2017

Simple Summary

Adding ecrecovery function to help with verifying address message signatures.

Abstract

Adding ecrecovery function to help with verifying compact address message signatures.

Motivation

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

Specification

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

Backwards Compatibility

No problem, as it's a new function.

Copyright

Copyright and related rights waived via CC0

Discussion

Most helpful comment

For people who use it before it gets built-in, there are an implementation and a simple test.

All 7 comments

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 :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fubuloubu picture fubuloubu  路  3Comments

lsaether picture lsaether  路  4Comments

jacqueswww picture jacqueswww  路  4Comments

pipermerriam picture pipermerriam  路  3Comments

ben-kaufman picture ben-kaufman  路  3Comments