Forward EC recover err and log it in core/vm

This commit is contained in:
Gustav Simonsson 2015-04-05 18:08:56 +02:00
parent 6e91142dc2
commit 66bfcb864a
2 changed files with 8 additions and 16 deletions

View file

@ -80,9 +80,9 @@ func ecrecoverFunc(in []byte) []byte {
// v needs to be moved to the end
rsv := append(in[64:128], byte(v.Uint64()))
pubKey := crypto.Ecrecover(in[:32], rsv)
// make sure the public key is a valid one
if pubKey == nil {
pubKey, err := crypto.Ecrecover(in[:32], rsv)
if err != nil {
vmlogger.Errorf("EC RECOVER FAIL: ", err)
return nil
}

View file

@ -21,16 +21,11 @@ import (
"github.com/ethereum/go-ethereum/crypto/ecies"
"github.com/ethereum/go-ethereum/crypto/secp256k1"
"github.com/ethereum/go-ethereum/crypto/sha3"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/rlp"
"golang.org/x/crypto/pbkdf2"
"golang.org/x/crypto/ripemd160"
)
var (
cryptologger = logger.NewLogger("CRYPTO")
)
func init() {
// specify the params for the s256 curve
ecies.AddParamsForCurve(S256(), ecies.ECIES_AES128_SHA256)
@ -73,12 +68,8 @@ func Ripemd160(data []byte) []byte {
return ripemd.Sum(nil)
}
func Ecrecover(hash, sig []byte) []byte {
r, err := secp256k1.RecoverPubkey(hash, sig)
if err != nil {
cryptologger.Errorf("EC RECOVER FAIL: ", err)
}
return r
func Ecrecover(hash, sig []byte) ([]byte, error) {
return secp256k1.RecoverPubkey(hash, sig)
}
// New methods using proper ecdsa keys from the stdlib
@ -153,8 +144,9 @@ func GenerateKey() (*ecdsa.PrivateKey, error) {
}
func SigToPub(hash, sig []byte) *ecdsa.PublicKey {
s := Ecrecover(hash, sig)
if s == nil || len(s) != 65 {
s, err := Ecrecover(hash, sig)
// TODO: add logging of error
if err != nil {
return nil
}