aboutsummaryrefslogtreecommitdiffstats
path: root/core/vm
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2017-01-05 18:35:23 +0800
committerFelix Lange <fjl@users.noreply.github.com>2017-01-05 18:35:23 +0800
commit08eea0f0e417c5f6ff864ae4633cc3e0a12aa405 (patch)
treef3a76e0c2511e18a874742cf801d35073b62c2f2 /core/vm
parent0fac8cba479a7cd90c17307b8795a0f836877c2e (diff)
downloaddexon-08eea0f0e417c5f6ff864ae4633cc3e0a12aa405.tar
dexon-08eea0f0e417c5f6ff864ae4633cc3e0a12aa405.tar.gz
dexon-08eea0f0e417c5f6ff864ae4633cc3e0a12aa405.tar.bz2
dexon-08eea0f0e417c5f6ff864ae4633cc3e0a12aa405.tar.lz
dexon-08eea0f0e417c5f6ff864ae4633cc3e0a12aa405.tar.xz
dexon-08eea0f0e417c5f6ff864ae4633cc3e0a12aa405.tar.zst
dexon-08eea0f0e417c5f6ff864ae4633cc3e0a12aa405.zip
accounts, core, crypto, internal: use normalised V during signature handling (#3455)
To address increasing complexity in code that handles signatures, this PR discards all notion of "different" signature types at the library level. Both the crypto and accounts package is reduced to only be able to produce plain canonical secp256k1 signatures. This makes the crpyto APIs much cleaner, simpler and harder to abuse.
Diffstat (limited to 'core/vm')
-rw-r--r--core/vm/contracts.go14
1 files changed, 4 insertions, 10 deletions
diff --git a/core/vm/contracts.go b/core/vm/contracts.go
index b45f14724..5cd0d0bb1 100644
--- a/core/vm/contracts.go
+++ b/core/vm/contracts.go
@@ -89,21 +89,15 @@ func ecrecoverFunc(in []byte) []byte {
r := common.BytesToBig(in[64:96])
s := common.BytesToBig(in[96:128])
- // Treat V as a 256bit integer
- vbig := common.Bytes2Big(in[32:64])
- v := byte(vbig.Uint64())
+ v := in[63] - 27
// tighter sig s values in homestead only apply to tx sigs
- if !crypto.ValidateSignatureValues(v, r, s, false) {
+ if common.Bytes2Big(in[32:63]).BitLen() > 0 || !crypto.ValidateSignatureValues(v, r, s, false) {
glog.V(logger.Detail).Infof("ECRECOVER error: v, r or s value invalid")
return nil
}
-
- // 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)
+ // v needs to be at the end for libsecp256k1
+ pubKey, err := crypto.Ecrecover(in[:32], append(in[64:128], v))
// make sure the public key is a valid one
if err != nil {
glog.V(logger.Detail).Infoln("ECRECOVER error: ", err)