Skip to content

Commit

Permalink
Merge pull request ethereum#5 from obscuren/private-tx
Browse files Browse the repository at this point in the history
core, core/types: implemented private transaction check
  • Loading branch information
obscuren authored Nov 2, 2016
2 parents b11a387 + 1ad23de commit 9392153
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 1 addition & 4 deletions core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package core

import (
"bytes"
"math/big"

"github.com/ethereum/go-ethereum/core/state"
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions core/types/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down

0 comments on commit 9392153

Please sign in to comment.