aboutsummaryrefslogtreecommitdiffstats
path: root/core/vm/contracts.go
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2015-06-09 22:21:23 +0800
committerJeffrey Wilcke <jeffrey@ethereum.org>2015-06-09 22:21:23 +0800
commitc71ab2a6a33685af5097aad86105cab6f5a5e131 (patch)
tree30d3a5478ad7f79d99cd824051a92eed3a153e0c /core/vm/contracts.go
parent365576620a8230a193570e81e7f296d17b13fede (diff)
parent6e3b58e491c822cc6e4aa822c31c6dee034e3df9 (diff)
downloadgo-tangerine-c71ab2a6a33685af5097aad86105cab6f5a5e131.tar.gz
go-tangerine-c71ab2a6a33685af5097aad86105cab6f5a5e131.tar.zst
go-tangerine-c71ab2a6a33685af5097aad86105cab6f5a5e131.zip
Merge pull request #1219 from Gustav-Simonsson/precompiled_ec_recover_padding
Precompiled ec recover padding
Diffstat (limited to 'core/vm/contracts.go')
-rw-r--r--core/vm/contracts.go20
1 files changed, 12 insertions, 8 deletions
diff --git a/core/vm/contracts.go b/core/vm/contracts.go
index 742017dd2..90e356b1d 100644
--- a/core/vm/contracts.go
+++ b/core/vm/contracts.go
@@ -67,21 +67,25 @@ func ripemd160Func(in []byte) []byte {
const ecRecoverInputLength = 128
func ecrecoverFunc(in []byte) []byte {
+ in = common.RightPadBytes(in, 128)
// "in" is (hash, v, r, s), each 32 bytes
// but for ecrecover we want (r, s, v)
- if len(in) < ecRecoverInputLength {
- return nil
- }
+ r := common.BytesToBig(in[64:96])
+ s := common.BytesToBig(in[96:128])
// Treat V as a 256bit integer
- v := new(big.Int).Sub(common.Bytes2Big(in[32:64]), big.NewInt(27))
- // Ethereum requires V to be either 0 or 1 => (27 || 28)
- if !(v.Cmp(Zero) == 0 || v.Cmp(One) == 0) {
+ vbig := common.Bytes2Big(in[32:64])
+ v := byte(vbig.Uint64())
+
+ if !crypto.ValidateSignatureValues(v, r, s) {
+ glog.V(logger.Error).Infof("EC RECOVER FAIL: v, r or s value invalid")
return nil
}
- // v needs to be moved to the end
- rsv := append(in[64:128], byte(v.Uint64()))
+ // v needs to be at the end and normalized for libsecp256k1
+ vbignormal := new(big.Int).Sub(vbig, big.NewInt(27))
+ vnormal := byte(vbignormal.Uint64())
+ rsv := append(in[64:128], vnormal)
pubKey, err := crypto.Ecrecover(in[:32], rsv)
// make sure the public key is a valid one
if err != nil {