core, core/types: implemented private transaction check

Transactions are considered private when the V param is either 37 or 38.
This commit is contained in:
Jeffrey Wilcke 2016-11-01 22:25:59 +01:00
parent e7815c59f0
commit 1ad23deb8e
2 changed files with 8 additions and 4 deletions

View File

@ -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)

View File

@ -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()