aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/crypto.go
diff options
context:
space:
mode:
authorGustav Simonsson <gustav.simonsson@gmail.com>2015-11-27 22:40:29 +0800
committerJeffrey Wilcke <geffobscura@gmail.com>2016-02-18 17:08:11 +0800
commit371871d685d54b916aef28de689d6f0af7822083 (patch)
treee704b02ba2ffd2d1164001885fba15106b0f7d94 /crypto/crypto.go
parentaa36a6ae4f24f07e2c470a21c93ff37ad5861982 (diff)
downloaddexon-371871d685d54b916aef28de689d6f0af7822083.tar.gz
dexon-371871d685d54b916aef28de689d6f0af7822083.tar.zst
dexon-371871d685d54b916aef28de689d6f0af7822083.zip
parmas, crypto, core, core/vm: homestead consensus protocol changes
* change gas cost for contract creating txs * invalidate signature with s value greater than secp256k1 N / 2 * OOG contract creation if not enough gas to store code * new difficulty adjustment algorithm * new DELEGATECALL op code
Diffstat (limited to 'crypto/crypto.go')
-rw-r--r--crypto/crypto.go13
1 files changed, 11 insertions, 2 deletions
diff --git a/crypto/crypto.go b/crypto/crypto.go
index 7d7623753..850be4da6 100644
--- a/crypto/crypto.go
+++ b/crypto/crypto.go
@@ -163,12 +163,21 @@ func GenerateKey() (*ecdsa.PrivateKey, error) {
return ecdsa.GenerateKey(secp256k1.S256(), rand.Reader)
}
-func ValidateSignatureValues(v byte, r, s *big.Int) bool {
+func ValidateSignatureValues(v byte, r, s *big.Int, homestead bool) bool {
if r.Cmp(common.Big1) < 0 || s.Cmp(common.Big1) < 0 {
return false
}
vint := uint32(v)
- if r.Cmp(secp256k1.N) < 0 && s.Cmp(secp256k1.N) < 0 && (vint == 27 || vint == 28) {
+ // reject upper range of s values (ECDSA malleability)
+ // see discussion in secp256k1/libsecp256k1/include/secp256k1.h
+ if homestead && s.Cmp(secp256k1.HalfN) > 0 {
+ return false
+ }
+ // Frontier: allow s to be in full N range
+ if s.Cmp(secp256k1.N) >= 0 {
+ return false
+ }
+ if r.Cmp(secp256k1.N) < 0 && (vint == 27 || vint == 28) {
return true
} else {
return false