Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion accounts/keystore/keystore.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func (ks *KeyStore) SignTx(a accounts.Account, tx *types.Transaction, chainID *b
return nil, ErrLocked
}
// Depending on the presence of the chain ID, sign with EIP155 or homestead
if chainID != nil && !isQuorum {
if chainID != nil && !tx.IsPrivate() {
return types.SignTx(tx, types.NewEIP155Signer(chainID), unlockedKey.PrivateKey)
}
return types.SignTx(tx, types.HomesteadSigner{}, unlockedKey.PrivateKey)
Expand Down
3 changes: 2 additions & 1 deletion core/types/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ func (tx *Transaction) Protected() bool {
func isProtectedV(V *big.Int) bool {
if V.BitLen() <= 8 {
v := V.Uint64()
return v != 27 && v != 28
// 27 / 28 are pre eip 155 -- ie unprotected.
return !(v == 27 || v == 28)
}
// anything not 27 or 28 are considered unprotected
return true
Expand Down
12 changes: 8 additions & 4 deletions core/types/transaction_signing.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ type sigCache struct {

// MakeSigner returns a Signer based on the given chain config and block number.
func MakeSigner(config *params.ChainConfig, blockNumber *big.Int) Signer {
if config.IsQuorum {
return HomesteadSigner{}
}
var signer Signer
switch {
case config.IsEIP155(blockNumber):
Expand Down Expand Up @@ -128,6 +125,9 @@ func (s EIP155Signer) Equal(s2 Signer) bool {
var big8 = big.NewInt(8)

func (s EIP155Signer) Sender(tx *Transaction) (common.Address, error) {
if tx.IsPrivate() {
return HomesteadSigner{}.Sender(tx)
}
if !tx.Protected() {
return HomesteadSigner{}.Sender(tx)
}
Expand All @@ -136,12 +136,16 @@ func (s EIP155Signer) Sender(tx *Transaction) (common.Address, error) {
}
V := new(big.Int).Sub(tx.data.V, s.chainIdMul)
V.Sub(V, big8)
return recoverPlain(s.Hash(tx), tx.data.R, tx.data.S, V, true, false)
return recoverPlain(s.Hash(tx), tx.data.R, tx.data.S, V, true, tx.IsPrivate())
}

// WithSignature returns a new transaction with the given signature. This signature
// needs to be in the [R || S || V] format where V is 0 or 1.
func (s EIP155Signer) SignatureValues(tx *Transaction, sig []byte) (R, S, V *big.Int, err error) {
if tx.IsPrivate() {
return HomesteadSigner{}.SignatureValues(tx, sig)
}

R, S, V, err = HomesteadSigner{}.SignatureValues(tx, sig)
if err != nil {
return nil, nil, nil, err
Expand Down
25 changes: 12 additions & 13 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ import (
"bytes"
"encoding/hex"
"encoding/json"
"net/http"
"sync"

"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/common"
Expand All @@ -45,8 +48,6 @@ import (
"github.com/ethereum/go-ethereum/rpc"
"github.com/syndtr/goleveldb/leveldb"
"github.com/syndtr/goleveldb/leveldb/util"
"net/http"
"sync"
)

const (
Expand Down Expand Up @@ -378,7 +379,7 @@ func (s *PrivateAccountAPI) SendTransaction(ctx context.Context, args SendTxArgs
tx := args.toTransaction()

var chainID *big.Int
if config := s.b.ChainConfig(); config.IsEIP155(s.b.CurrentBlock().Number()) {
if config := s.b.ChainConfig(); config.IsEIP155(s.b.CurrentBlock().Number()) && !isPrivate {
chainID = config.ChainId
}
signed, err := wallet.SignTxWithPassphrase(account, passwd, tx, chainID)
Expand Down Expand Up @@ -834,7 +835,7 @@ type RPCTransaction struct {
// representation, with the given location metadata set (if available).
func newRPCTransaction(tx *types.Transaction, blockHash common.Hash, blockNumber uint64, index uint64) *RPCTransaction {
var signer types.Signer = types.HomesteadSigner{}
if tx.Protected() {
if tx.Protected() & !tx.IsPrivate() {
signer = types.NewEIP155Signer(tx.ChainId())
}
from, _ := types.Sender(signer, tx)
Expand Down Expand Up @@ -1004,7 +1005,7 @@ func (s *PublicTransactionPoolAPI) GetTransactionReceipt(hash common.Hash) (map[
receipt, _, _, _ := core.GetReceipt(s.b.ChainDb(), hash) // Old receipts don't have the lookup data available

var signer types.Signer = types.HomesteadSigner{}
if tx.Protected() {
if tx.Protected() && !tx.IsPrivate() {
signer = types.NewEIP155Signer(tx.ChainId())
}
from, _ := types.Sender(signer, tx)
Expand Down Expand Up @@ -1050,10 +1051,9 @@ func (s *PublicTransactionPoolAPI) sign(addr common.Address, tx *types.Transacti
}
// Request the wallet to sign the transaction
var chainID *big.Int
isQuorum := false
if config := s.b.ChainConfig(); config.IsEIP155(s.b.CurrentBlock().Number()) {
isQuorum := tx.IsPrivate()
if config := s.b.ChainConfig(); config.IsEIP155(s.b.CurrentBlock().Number()) && !tx.IsPrivate() {
chainID = config.ChainId
isQuorum = true
}
return wallet.SignTx(account, tx, chainID, isQuorum)
}
Expand Down Expand Up @@ -1168,10 +1168,9 @@ func (s *PublicTransactionPoolAPI) SendTransaction(ctx context.Context, args Sen
tx := args.toTransaction()

var chainID *big.Int
isQuorum := false
if config := s.b.ChainConfig(); config.IsEIP155(s.b.CurrentBlock().Number()) {
isQuorum := tx.IsPrivate()
if config := s.b.ChainConfig(); config.IsEIP155(s.b.CurrentBlock().Number()) && !isPrivate {
chainID = config.ChainId
isQuorum = true
}
signed, err := wallet.SignTx(account, tx, chainID, isQuorum)
if err != nil {
Expand Down Expand Up @@ -1256,7 +1255,7 @@ func (s *PublicTransactionPoolAPI) PendingTransactions() ([]*RPCTransaction, err
transactions := make([]*RPCTransaction, 0, len(pending))
for _, tx := range pending {
var signer types.Signer = types.HomesteadSigner{}
if tx.Protected() {
if tx.Protected() && !tx.IsPrivate() {
signer = types.NewEIP155Signer(tx.ChainId())
}
from, _ := types.Sender(signer, tx)
Expand Down Expand Up @@ -1284,7 +1283,7 @@ func (s *PublicTransactionPoolAPI) Resend(ctx context.Context, sendArgs SendTxAr

for _, p := range pending {
var signer types.Signer = types.HomesteadSigner{}
if p.Protected() {
if p.Protected() && !p.IsPrivate() {
signer = types.NewEIP155Signer(p.ChainId())
}
wantSigHash := signer.Hash(matchTx)
Expand Down