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
b533aaa7
Commit
b533aaa7
authored
Jul 06, 2015
by
Jeffrey Wilcke
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1409 from fjl/fix-tx-hash
core/types, xeth: separate tx hash and tx signature hash
parents
35add89c
ec9620fb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
9 deletions
+17
-9
transaction.go
core/types/transaction.go
+13
-5
transaction_test.go
core/types/transaction_test.go
+3
-3
xeth.go
xeth/xeth.go
+1
-1
No files found.
core/types/transaction.go
View file @
b533aaa7
...
...
@@ -116,11 +116,21 @@ func (tx *Transaction) To() *common.Address {
}
}
// Hash hashes the RLP encoding of tx.
// It uniquely identifies the transaction.
func
(
tx
*
Transaction
)
Hash
()
common
.
Hash
{
if
hash
:=
tx
.
hash
.
Load
();
hash
!=
nil
{
return
hash
.
(
common
.
Hash
)
}
v
:=
rlpHash
([]
interface
{}{
v
:=
rlpHash
(
tx
)
tx
.
hash
.
Store
(
v
)
return
v
}
// SigHash returns the hash to be signed by the sender.
// It does not uniquely identify the transaction.
func
(
tx
*
Transaction
)
SigHash
()
common
.
Hash
{
return
rlpHash
([]
interface
{}{
tx
.
data
.
AccountNonce
,
tx
.
data
.
Price
,
tx
.
data
.
GasLimit
,
...
...
@@ -128,8 +138,6 @@ func (tx *Transaction) Hash() common.Hash {
tx
.
data
.
Amount
,
tx
.
data
.
Payload
,
})
tx
.
hash
.
Store
(
v
)
return
v
}
func
(
tx
*
Transaction
)
Size
()
common
.
StorageSize
{
...
...
@@ -180,7 +188,7 @@ func (tx *Transaction) publicKey() ([]byte, error) {
sig
[
64
]
=
tx
.
data
.
V
-
27
// recover the public key from the signature
hash
:=
tx
.
Hash
()
hash
:=
tx
.
Sig
Hash
()
pub
,
err
:=
crypto
.
Ecrecover
(
hash
[
:
],
sig
)
if
err
!=
nil
{
glog
.
V
(
logger
.
Error
)
.
Infof
(
"Could not get pubkey from signature: "
,
err
)
...
...
@@ -204,7 +212,7 @@ func (tx *Transaction) WithSignature(sig []byte) (*Transaction, error) {
}
func
(
tx
*
Transaction
)
SignECDSA
(
prv
*
ecdsa
.
PrivateKey
)
(
*
Transaction
,
error
)
{
h
:=
tx
.
Hash
()
h
:=
tx
.
Sig
Hash
()
sig
,
err
:=
crypto
.
Sign
(
h
[
:
],
prv
)
if
err
!=
nil
{
return
nil
,
err
...
...
core/types/transaction_test.go
View file @
b533aaa7
...
...
@@ -34,11 +34,11 @@ var (
)
)
func
TestTransactionHash
(
t
*
testing
.
T
)
{
if
emptyTx
.
Hash
()
!=
common
.
HexToHash
(
"c775b99e7ad12f50d819fcd602390467e28141316969f4b57f0626f74fe3b386"
)
{
func
TestTransaction
Sig
Hash
(
t
*
testing
.
T
)
{
if
emptyTx
.
Sig
Hash
()
!=
common
.
HexToHash
(
"c775b99e7ad12f50d819fcd602390467e28141316969f4b57f0626f74fe3b386"
)
{
t
.
Errorf
(
"empty transaction hash mismatch, got %x"
,
emptyTx
.
Hash
())
}
if
rightvrsTx
.
Hash
()
!=
common
.
HexToHash
(
"fe7a79529ed5f7c3375d06b26b186a8644e0e16c373d7a12be41c62d6042b77a"
)
{
if
rightvrsTx
.
Sig
Hash
()
!=
common
.
HexToHash
(
"fe7a79529ed5f7c3375d06b26b186a8644e0e16c373d7a12be41c62d6042b77a"
)
{
t
.
Errorf
(
"RightVRS transaction hash mismatch, got %x"
,
rightvrsTx
.
Hash
())
}
}
...
...
xeth/xeth.go
View file @
b533aaa7
...
...
@@ -977,7 +977,7 @@ func (self *XEth) Transact(fromStr, toStr, nonceStr, valueStr, gasStr, gasPriceS
}
func
(
self
*
XEth
)
sign
(
tx
*
types
.
Transaction
,
from
common
.
Address
,
didUnlock
bool
)
(
*
types
.
Transaction
,
error
)
{
hash
:=
tx
.
Hash
()
hash
:=
tx
.
Sig
Hash
()
sig
,
err
:=
self
.
doSign
(
from
,
hash
,
didUnlock
)
if
err
!=
nil
{
return
tx
,
err
...
...
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