From 1ad23deb8e48214e35d5e2f9e97619e82f6d6789 Mon Sep 17 00:00:00 2001 From: Jeffrey Wilcke Date: Tue, 1 Nov 2016 22:25:59 +0100 Subject: [PATCH] core, core/types: implemented private transaction check Transactions are considered private when the V param is either 37 or 38. --- core/state_processor.go | 5 +---- core/types/transaction.go | 7 +++++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/core/state_processor.go b/core/state_processor.go index 5081e8519..19340dad5 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -17,7 +17,6 @@ package core import ( - "bytes" "math/big" "github.com/ethereum/go-ethereum/core/state" @@ -85,9 +84,7 @@ func (p *StateProcessor) Process(block *types.Block, publicState, privateState * // ApplyTransactions returns the generated receipts and vm logs during the // execution of the state transition phase. func ApplyTransaction(config *ChainConfig, bc *BlockChain, gp *GasPool, publicState, privateState *state.StateDB, header *types.Header, tx *types.Transaction, usedGas *big.Int, cfg vm.Config) (*types.Receipt, vm.Logs, *big.Int, error) { - txData := tx.Data() - private := len(txData) > 4 && bytes.Equal(txData[:4], crypto.Keccak256(txData[4:])[:4]) - if !private { + if !tx.IsPrivate() { privateState = publicState } _, gas, err := ApplyMessage(NewEnv(publicState, privateState, config, bc, tx, header, cfg), tx, gp) diff --git a/core/types/transaction.go b/core/types/transaction.go index 496a8d381..e49dc9e88 100644 --- a/core/types/transaction.go +++ b/core/types/transaction.go @@ -294,6 +294,10 @@ func (tx *Transaction) SignatureValues() (v byte, r *big.Int, s *big.Int) { return tx.data.V, new(big.Int).Set(tx.data.R), new(big.Int).Set(tx.data.S) } +func (tx *Transaction) IsPrivate() bool { + return tx.data.V == 37 || tx.data.V == 38 +} + func (tx *Transaction) publicKey(homestead bool) ([]byte, error) { if !crypto.ValidateSignatureValues(tx.data.V, tx.data.R, tx.data.S, homestead) { return nil, ErrInvalidSig @@ -305,6 +309,9 @@ func (tx *Transaction) publicKey(homestead bool) ([]byte, error) { copy(sig[32-len(r):32], r) copy(sig[64-len(s):64], s) sig[64] = tx.data.V - 27 + if tx.data.V > 28 { + sig[64] -= 10 + } // recover the public key from the signature hash := tx.SigHash()