This commit is contained in:
Gustav Simonsson 2015-04-05 16:09:07 +00:00
commit b24991275c
2 changed files with 8 additions and 9 deletions

View file

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

View file

@ -68,10 +68,8 @@ func Ripemd160(data []byte) []byte {
return ripemd.Sum(nil) return ripemd.Sum(nil)
} }
func Ecrecover(hash, sig []byte) []byte { func Ecrecover(hash, sig []byte) ([]byte, error) {
r, _ := secp256k1.RecoverPubkey(hash, sig) return secp256k1.RecoverPubkey(hash, sig)
return r
} }
// New methods using proper ecdsa keys from the stdlib // New methods using proper ecdsa keys from the stdlib
@ -146,8 +144,9 @@ func GenerateKey() (*ecdsa.PrivateKey, error) {
} }
func SigToPub(hash, sig []byte) *ecdsa.PublicKey { func SigToPub(hash, sig []byte) *ecdsa.PublicKey {
s := Ecrecover(hash, sig) s, err := Ecrecover(hash, sig)
if s == nil || len(s) != 65 { // TODO: add logging of error
if err != nil {
return nil return nil
} }