From ad9d04d6baa1357be10a1d58fd68a457ce7be299 Mon Sep 17 00:00:00 2001 From: Chetan Sarva Date: Mon, 14 Nov 2016 23:48:10 -0500 Subject: [PATCH] Fix SetPrivate and validation * Builds on the fix in c828292fa2c009e2865b1f0d521a080499a234d8; * SetPrivate() must be called after the tx has been signed and * just before inserting into txpool. * Added 37 & 38 as valid V values in validation routine --- crypto/crypto.go | 2 +- internal/ethapi/api.go | 23 ++++++++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/crypto/crypto.go b/crypto/crypto.go index e611bd8f4..6d8709a4a 100644 --- a/crypto/crypto.go +++ b/crypto/crypto.go @@ -181,7 +181,7 @@ func ValidateSignatureValues(v byte, r, s *big.Int, homestead bool) bool { if s.Cmp(secp256k1.N) >= 0 { return false } - if r.Cmp(secp256k1.N) < 0 && (vint == 27 || vint == 28) { + if r.Cmp(secp256k1.N) < 0 && (vint == 27 || vint == 28 || vint == 37 || vint == 38) { return true } else { return false diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 77a2a5747..e7dbd2af0 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -275,7 +275,8 @@ func (s *PrivateAccountAPI) SendTransaction(ctx context.Context, args SendTxArgs var tx *types.Transaction data := common.FromHex(args.Data) - if len(args.PrivateFor) > 0 { + isPrivate := len(args.PrivateFor) > 0 + if isPrivate { data, err = private.P.Send(data, args.PrivateFrom, args.PrivateFor) if err != nil { return common.Hash{}, err @@ -286,16 +287,13 @@ func (s *PrivateAccountAPI) SendTransaction(ctx context.Context, args SendTxArgs } else { tx = types.NewTransaction(args.Nonce.Uint64(), *args.To, args.Value.BigInt(), args.Gas.BigInt(), args.GasPrice.BigInt(), data) } - if len(args.PrivateFor) > 0 { - tx.SetPrivate() - } signature, err := s.am.SignWithPassphrase(args.From, passwd, tx.SigHash().Bytes()) if err != nil { return common.Hash{}, err } - return submitTransaction(ctx, s.b, tx, signature) + return submitTransaction(ctx, s.b, tx, signature, isPrivate) } // signHash is a helper function that calculates a hash for the given message that can be @@ -1035,12 +1033,17 @@ func prepareSendTxArgs(ctx context.Context, args SendTxArgs, b Backend) (SendTxA } // submitTransaction is a helper function that submits tx to txPool and creates a log entry. -func submitTransaction(ctx context.Context, b Backend, tx *types.Transaction, signature []byte) (common.Hash, error) { +func submitTransaction(ctx context.Context, b Backend, tx *types.Transaction, signature []byte, isPrivate bool) (common.Hash, error) { signedTx, err := tx.WithSignature(signature) if err != nil { return common.Hash{}, err } + // mark private after creating signed copy + if isPrivate { + signedTx.SetPrivate() + } + if err := b.SendTx(ctx, signedTx); err != nil { return common.Hash{}, err } @@ -1075,7 +1078,8 @@ func (s *PublicTransactionPoolAPI) SendTransaction(ctx context.Context, args Sen var tx *types.Transaction data := common.FromHex(args.Data) - if len(args.PrivateFor) > 0 { + isPrivate := len(args.PrivateFor) > 0 + if isPrivate { data, err = private.P.Send(data, args.PrivateFrom, args.PrivateFor) if err != nil { return common.Hash{}, err @@ -1086,16 +1090,13 @@ func (s *PublicTransactionPoolAPI) SendTransaction(ctx context.Context, args Sen } else { tx = types.NewTransaction(args.Nonce.Uint64(), *args.To, args.Value.BigInt(), args.Gas.BigInt(), args.GasPrice.BigInt(), data) } - if len(args.PrivateFor) > 0 { - tx.SetPrivate() - } signature, err := s.b.AccountManager().SignEthereum(args.From, tx.SigHash().Bytes()) if err != nil { return common.Hash{}, err } - return submitTransaction(ctx, s.b, tx, signature) + return submitTransaction(ctx, s.b, tx, signature, isPrivate) } // SendRawTransaction will add the signed transaction to the transaction pool.