Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
32e1b104
Commit
32e1b104
authored
Jun 01, 2015
by
Gustav Simonsson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add EC signature validations before call to libsecp256k1
parent
5b14fdb9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
22 deletions
+29
-22
transaction_pool.go
core/transaction_pool.go
+0
-6
transaction.go
core/types/transaction.go
+15
-16
crypto.go
crypto/crypto.go
+14
-0
No files found.
core/transaction_pool.go
View file @
32e1b104
...
@@ -112,12 +112,6 @@ func (pool *TxPool) ValidateTransaction(tx *types.Transaction) error {
...
@@ -112,12 +112,6 @@ func (pool *TxPool) ValidateTransaction(tx *types.Transaction) error {
return
ErrInvalidSender
return
ErrInvalidSender
}
}
// Validate curve param
v
,
_
,
_
:=
tx
.
Curve
()
if
v
>
28
||
v
<
27
{
return
fmt
.
Errorf
(
"tx.v != (28 || 27) => %v"
,
v
)
}
if
!
pool
.
currentState
()
.
HasAccount
(
from
)
{
if
!
pool
.
currentState
()
.
HasAccount
(
from
)
{
return
ErrNonExistentAccount
return
ErrNonExistentAccount
}
}
...
...
core/types/transaction.go
View file @
32e1b104
...
@@ -8,7 +8,6 @@ import (
...
@@ -8,7 +8,6 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto/secp256k1"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rlp"
...
@@ -93,9 +92,9 @@ func (self *Transaction) SetNonce(AccountNonce uint64) {
...
@@ -93,9 +92,9 @@ func (self *Transaction) SetNonce(AccountNonce uint64) {
}
}
func
(
self
*
Transaction
)
From
()
(
common
.
Address
,
error
)
{
func
(
self
*
Transaction
)
From
()
(
common
.
Address
,
error
)
{
pubkey
:=
self
.
PublicKey
()
pubkey
,
err
:=
self
.
PublicKey
()
if
len
(
pubkey
)
==
0
||
pubkey
[
0
]
!=
4
{
if
err
!=
nil
{
return
common
.
Address
{},
err
ors
.
New
(
"invalid public key"
)
return
common
.
Address
{},
err
}
}
var
addr
common
.
Address
var
addr
common
.
Address
...
@@ -110,34 +109,34 @@ func (tx *Transaction) To() *common.Address {
...
@@ -110,34 +109,34 @@ func (tx *Transaction) To() *common.Address {
return
tx
.
Recipient
return
tx
.
Recipient
}
}
func
(
tx
*
Transaction
)
Curve
()
(
v
byte
,
r
[]
byte
,
s
[]
byte
)
{
func
(
tx
*
Transaction
)
GetSignatureValues
()
(
v
byte
,
r
[]
byte
,
s
[]
byte
)
{
v
=
byte
(
tx
.
V
)
v
=
byte
(
tx
.
V
)
r
=
common
.
LeftPadBytes
(
tx
.
R
.
Bytes
(),
32
)
r
=
common
.
LeftPadBytes
(
tx
.
R
.
Bytes
(),
32
)
s
=
common
.
LeftPadBytes
(
tx
.
S
.
Bytes
(),
32
)
s
=
common
.
LeftPadBytes
(
tx
.
S
.
Bytes
(),
32
)
return
return
}
}
func
(
tx
*
Transaction
)
Signature
(
key
[]
byte
)
[]
byte
{
func
(
tx
*
Transaction
)
PublicKey
()
([]
byte
,
error
)
{
hash
:=
tx
.
Hash
()
if
!
crypto
.
ValidateSignatureValues
(
tx
.
V
,
tx
.
R
,
tx
.
S
)
{
sig
,
_
:=
secp256k1
.
Sign
(
hash
[
:
],
key
)
return
nil
,
errors
.
New
(
"invalid v, r, s values"
)
return
sig
}
}
func
(
tx
*
Transaction
)
PublicKey
()
[]
byte
{
hash
:=
tx
.
Hash
()
hash
:=
tx
.
Hash
()
v
,
r
,
s
:=
tx
.
Curve
()
v
,
r
,
s
:=
tx
.
GetSignatureValues
()
sig
:=
append
(
r
,
s
...
)
sig
:=
append
(
r
,
s
...
)
sig
=
append
(
sig
,
v
-
27
)
sig
=
append
(
sig
,
v
-
27
)
//pubkey := crypto.Ecrecover(append(hash[:], sig...))
//pubkey, _ := secp256k1.RecoverPubkey(hash[:], sig)
p
,
err
:=
crypto
.
SigToPub
(
hash
[
:
],
sig
)
p
,
err
:=
crypto
.
SigToPub
(
hash
[
:
],
sig
)
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
V
(
logger
.
Error
)
.
Infof
(
"Could not get pubkey from signature: "
,
err
)
glog
.
V
(
logger
.
Error
)
.
Infof
(
"Could not get pubkey from signature: "
,
err
)
return
nil
return
nil
,
err
}
}
pubkey
:=
crypto
.
FromECDSAPub
(
p
)
pubkey
:=
crypto
.
FromECDSAPub
(
p
)
return
pubkey
if
len
(
pubkey
)
==
0
||
pubkey
[
0
]
!=
4
{
return
nil
,
errors
.
New
(
"invalid public key"
)
}
return
pubkey
,
nil
}
}
func
(
tx
*
Transaction
)
SetSignatureValues
(
sig
[]
byte
)
error
{
func
(
tx
*
Transaction
)
SetSignatureValues
(
sig
[]
byte
)
error
{
...
...
crypto/crypto.go
View file @
32e1b104
...
@@ -10,6 +10,7 @@ import (
...
@@ -10,6 +10,7 @@ import (
"fmt"
"fmt"
"io"
"io"
"io/ioutil"
"io/ioutil"
"math/big"
"os"
"os"
"encoding/hex"
"encoding/hex"
...
@@ -151,6 +152,19 @@ func GenerateKey() (*ecdsa.PrivateKey, error) {
...
@@ -151,6 +152,19 @@ func GenerateKey() (*ecdsa.PrivateKey, error) {
return
ecdsa
.
GenerateKey
(
S256
(),
rand
.
Reader
)
return
ecdsa
.
GenerateKey
(
S256
(),
rand
.
Reader
)
}
}
func
ValidateSignatureValues
(
v
byte
,
r
,
s
*
big
.
Int
)
bool
{
secp256k1n
:=
common
.
String2Big
(
"0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"
)
vint
:=
uint32
(
v
)
if
r
.
Cmp
(
common
.
Big0
)
==
0
||
s
.
Cmp
(
common
.
Big0
)
==
0
{
return
false
}
if
r
.
Cmp
(
secp256k1n
)
<
0
&&
s
.
Cmp
(
secp256k1n
)
<
0
&&
(
vint
==
27
||
vint
==
28
)
{
return
true
}
else
{
return
false
}
}
func
SigToPub
(
hash
,
sig
[]
byte
)
(
*
ecdsa
.
PublicKey
,
error
)
{
func
SigToPub
(
hash
,
sig
[]
byte
)
(
*
ecdsa
.
PublicKey
,
error
)
{
s
,
err
:=
Ecrecover
(
hash
,
sig
)
s
,
err
:=
Ecrecover
(
hash
,
sig
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment