aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/types/transaction.go23
-rw-r--r--core/types/transaction_test.go12
2 files changed, 23 insertions, 12 deletions
diff --git a/core/types/transaction.go b/core/types/transaction.go
index 9c6e77be9..7b53cac2c 100644
--- a/core/types/transaction.go
+++ b/core/types/transaction.go
@@ -153,16 +153,21 @@ func (tx *Transaction) UnmarshalJSON(input []byte) error {
if err := dec.UnmarshalJSON(input); err != nil {
return err
}
- var V byte
- if isProtectedV(dec.V) {
- chainID := deriveChainId(dec.V).Uint64()
- V = byte(dec.V.Uint64() - 35 - 2*chainID)
- } else {
- V = byte(dec.V.Uint64() - 27)
- }
- if !crypto.ValidateSignatureValues(V, dec.R, dec.S, false) {
- return ErrInvalidSig
+
+ withSignature := dec.V.Sign() != 0 || dec.R.Sign() != 0 || dec.S.Sign() != 0
+ if withSignature {
+ var V byte
+ if isProtectedV(dec.V) {
+ chainID := deriveChainId(dec.V).Uint64()
+ V = byte(dec.V.Uint64() - 35 - 2*chainID)
+ } else {
+ V = byte(dec.V.Uint64() - 27)
+ }
+ if !crypto.ValidateSignatureValues(V, dec.R, dec.S, false) {
+ return ErrInvalidSig
+ }
}
+
*tx = Transaction{data: dec}
return nil
}
diff --git a/core/types/transaction_test.go b/core/types/transaction_test.go
index b390f45c6..f38d8e717 100644
--- a/core/types/transaction_test.go
+++ b/core/types/transaction_test.go
@@ -185,6 +185,7 @@ func TestTransactionJSON(t *testing.T) {
}
signer := NewEIP155Signer(common.Big1)
+ transactions := make([]*Transaction, 0, 50)
for i := uint64(0); i < 25; i++ {
var tx *Transaction
switch i % 2 {
@@ -193,20 +194,25 @@ func TestTransactionJSON(t *testing.T) {
case 1:
tx = NewContractCreation(i, common.Big0, 1, common.Big2, []byte("abcdef"))
}
+ transactions = append(transactions, tx)
- tx, err := SignTx(tx, signer, key)
+ signedTx, err := SignTx(tx, signer, key)
if err != nil {
t.Fatalf("could not sign transaction: %v", err)
}
+ transactions = append(transactions, signedTx)
+ }
+
+ for _, tx := range transactions {
data, err := json.Marshal(tx)
if err != nil {
- t.Errorf("json.Marshal failed: %v", err)
+ t.Fatalf("json.Marshal failed: %v", err)
}
var parsedTx *Transaction
if err := json.Unmarshal(data, &parsedTx); err != nil {
- t.Errorf("json.Unmarshal failed: %v", err)
+ t.Fatalf("json.Unmarshal failed: %v", err)
}
// compare nonce, price, gaslimit, recipient, amount, payload, V, R, S