Skip to content

Commit adb065a

Browse files
committed
[release/1.4.9] Revert "test, cmd/evm, core, core/vm: illegal code hash implementation"
This reverts commit a9c94cb.
1 parent c793cb3 commit adb065a

File tree

11 files changed

+29
-95
lines changed

11 files changed

+29
-95
lines changed

cmd/evm/main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ type ruleSet struct{}
220220

221221
func (ruleSet) IsHomestead(*big.Int) bool { return true }
222222

223-
func (self *VMEnv) MarkCodeHash(common.Hash) {}
224223
func (self *VMEnv) RuleSet() vm.RuleSet { return ruleSet{} }
225224
func (self *VMEnv) Vm() vm.Vm { return self.evm }
226225
func (self *VMEnv) Db() vm.Database { return self.state }

cmd/utils/flags.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,6 @@ var (
163163
}
164164
// Miner settings
165165
// TODO: refactor CPU vs GPU mining flags
166-
IllegalCodeHashesFlag = cli.StringFlag{
167-
Name: "illegal-code-hashes",
168-
Usage: "Comma separated list of code-hashes to ignore any interaction from",
169-
}
170166
MiningEnabledFlag = cli.BoolFlag{
171167
Name: "mine",
172168
Usage: "Enable mining",
@@ -644,16 +640,6 @@ func MakePasswordList(ctx *cli.Context) []string {
644640
return lines
645641
}
646642

647-
// ParseIllegalCodeHashes parses a comma separated list of hashes.
648-
func ParseIllegalCodeHashes(ctx *cli.Context) map[common.Hash]struct{} {
649-
splittedHexHashes := strings.Split(ctx.GlobalString(IllegalCodeHashesFlag.Name), ",")
650-
illegalCodeHashes := make(map[common.Hash]struct{})
651-
for _, hexHash := range splittedHexHashes {
652-
illegalCodeHashes[common.HexToHash(strings.TrimSpace(hexHash))] = struct{}{}
653-
}
654-
return illegalCodeHashes
655-
}
656-
657643
// MakeSystemNode sets up a local node, configures the services to launch and
658644
// assembles the P2P protocol stack.
659645
func MakeSystemNode(name, version string, relconf release.Config, extra []byte, ctx *cli.Context) *node.Node {
@@ -690,8 +676,6 @@ func MakeSystemNode(name, version string, relconf release.Config, extra []byte,
690676
}
691677
// Configure the Ethereum service
692678
accman := MakeAccountManager(ctx)
693-
// parse the illegal code hashes and set them to the core package.
694-
core.IllegalCodeHashes = ParseIllegalCodeHashes(ctx)
695679

696680
// initialise new random number generator
697681
rand := rand.New(rand.NewSource(time.Now().UnixNano()))

core/execution.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,6 @@ func exec(env vm.Environment, caller vm.ContractRef, address, codeAddr *common.A
8585
createAccount = true
8686
}
8787

88-
// mark the code hash if the execution is a call, callcode or delegate.
89-
if value.Cmp(common.Big0) > 0 {
90-
env.MarkCodeHash(env.Db().GetCodeHash(caller.Address()))
91-
}
92-
9388
snapshotPreTransfer := env.MakeSnapshot()
9489
var (
9590
from = env.Db().GetAccount(caller.Address())

core/state/statedb.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ type StateDB struct {
5151
txIndex int
5252
logs map[common.Hash]vm.Logs
5353
logSize uint
54-
55-
reducedDao bool
5654
}
5755

5856
// Create a new state from a given trie
@@ -163,14 +161,6 @@ func (self *StateDB) GetCode(addr common.Address) []byte {
163161
return nil
164162
}
165163

166-
func (self *StateDB) GetCodeHash(addr common.Address) common.Hash {
167-
stateObject := self.GetStateObject(addr)
168-
if stateObject != nil {
169-
return common.BytesToHash(stateObject.codeHash)
170-
}
171-
return common.Hash{}
172-
}
173-
174164
func (self *StateDB) GetState(a common.Address, b common.Hash) common.Hash {
175165
stateObject := self.GetStateObject(a)
176166
if stateObject != nil {

core/state_processor.go

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717
package core
1818

1919
import (
20-
"errors"
2120
"math/big"
2221

23-
"github.com/ethereum/go-ethereum/common"
2422
"github.com/ethereum/go-ethereum/core/state"
2523
"github.com/ethereum/go-ethereum/core/types"
2624
"github.com/ethereum/go-ethereum/core/vm"
@@ -30,15 +28,8 @@ import (
3028
)
3129

3230
var (
33-
big8 = big.NewInt(8)
34-
big32 = big.NewInt(32)
35-
illegalCodeHashErr = errors.New("core: Illegal code-hash found during execution")
36-
// XXX remove me
37-
daoHash = common.HexToHash("7278d050619a624f84f51987149ddb439cdaadfba5966f7cfaea7ad44340a4ba")
38-
whitelist = map[common.Address]bool{
39-
common.HexToAddress("Da4a4626d3E16e094De3225A751aAb7128e96526"): true, // multisig
40-
common.HexToAddress("2ba9D006C1D72E67A70b5526Fc6b4b0C0fd6D334"): true, // attack contract
41-
}
31+
big8 = big.NewInt(8)
32+
big32 = big.NewInt(32)
4233
)
4334

4435
// StateProcessor is a basic Processor, which takes care of transitioning
@@ -95,20 +86,11 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
9586
// ApplyTransactions returns the generated receipts and vm logs during the
9687
// execution of the state transition phase.
9788
func ApplyTransaction(config *ChainConfig, bc *BlockChain, gp *GasPool, statedb *state.StateDB, header *types.Header, tx *types.Transaction, usedGas *big.Int, cfg vm.Config) (*types.Receipt, vm.Logs, *big.Int, error) {
98-
env := NewEnv(statedb, config, bc, tx, header, cfg)
99-
_, gas, err := ApplyMessage(env, tx, gp)
89+
_, gas, err := ApplyMessage(NewEnv(statedb, config, bc, tx, header, cfg), tx, gp)
10090
if err != nil {
10191
return nil, nil, nil, err
10292
}
10393

104-
for _, codeHash := range env.CodeHashes {
105-
_, illegalHash := IllegalCodeHashes[codeHash]
106-
to := tx.To()
107-
if illegalHash && to != nil && !whitelist[*to] {
108-
return nil, nil, nil, illegalCodeHashErr
109-
}
110-
}
111-
11294
// Update the state with pending changes
11395
usedGas.Add(usedGas, gas)
11496
receipt := types.NewReceipt(statedb.IntermediateRoot().Bytes(), usedGas)

core/vm/environment.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ type Environment interface {
7373
DelegateCall(me ContractRef, addr common.Address, data []byte, gas, price *big.Int) ([]byte, error)
7474
// Create a new contract
7575
Create(me ContractRef, data []byte, gas, price, value *big.Int) ([]byte, common.Address, error)
76-
// Mark the code hash that was executed
77-
MarkCodeHash(hash common.Hash)
7876
}
7977

8078
// Vm is the basic interface for an implementation of the EVM.
@@ -98,7 +96,6 @@ type Database interface {
9896

9997
GetCode(common.Address) []byte
10098
SetCode(common.Address, []byte)
101-
GetCodeHash(common.Address) common.Hash
10299

103100
AddRefund(*big.Int)
104101
GetRefund() *big.Int

core/vm/jit_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,10 @@ func NewEnv(noJit, forceJit bool) *Env {
175175
return env
176176
}
177177

178-
func (self *Env) MarkCodeHash(common.Hash) {}
179-
func (self *Env) RuleSet() RuleSet { return ruleSet{new(big.Int)} }
180-
func (self *Env) Vm() Vm { return self.evm }
181-
func (self *Env) Origin() common.Address { return common.Address{} }
182-
func (self *Env) BlockNumber() *big.Int { return big.NewInt(0) }
178+
func (self *Env) RuleSet() RuleSet { return ruleSet{new(big.Int)} }
179+
func (self *Env) Vm() Vm { return self.evm }
180+
func (self *Env) Origin() common.Address { return common.Address{} }
181+
func (self *Env) BlockNumber() *big.Int { return big.NewInt(0) }
183182
func (self *Env) AddStructLog(log StructLog) {
184183
}
185184
func (self *Env) StructLogs() []StructLog {

core/vm/runtime/env.go

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ import (
2727

2828
// Env is a basic runtime environment required for running the EVM.
2929
type Env struct {
30-
ruleSet vm.RuleSet
31-
depth int
32-
state *state.StateDB
33-
illegalHashes []common.Hash
30+
ruleSet vm.RuleSet
31+
depth int
32+
state *state.StateDB
3433

3534
origin common.Address
3635
coinbase common.Address
@@ -50,15 +49,14 @@ type Env struct {
5049
// NewEnv returns a new vm.Environment
5150
func NewEnv(cfg *Config, state *state.StateDB) vm.Environment {
5251
env := &Env{
53-
ruleSet: cfg.RuleSet,
54-
illegalHashes: cfg.illegalHashes,
55-
state: state,
56-
origin: cfg.Origin,
57-
coinbase: cfg.Coinbase,
58-
number: cfg.BlockNumber,
59-
time: cfg.Time,
60-
difficulty: cfg.Difficulty,
61-
gasLimit: cfg.GasLimit,
52+
ruleSet: cfg.RuleSet,
53+
state: state,
54+
origin: cfg.Origin,
55+
coinbase: cfg.Coinbase,
56+
number: cfg.BlockNumber,
57+
time: cfg.Time,
58+
difficulty: cfg.Difficulty,
59+
gasLimit: cfg.GasLimit,
6260
}
6361
env.evm = vm.New(env, vm.Config{
6462
Debug: cfg.Debug,
@@ -81,8 +79,6 @@ func (self *Env) AddStructLog(log vm.StructLog) {
8179
self.logs = append(self.logs, log)
8280
}
8381

84-
func (self *Env) MarkCodeHash(hash common.Hash) {}
85-
8682
func (self *Env) RuleSet() vm.RuleSet { return self.ruleSet }
8783
func (self *Env) Vm() vm.Vm { return self.evm }
8884
func (self *Env) Origin() common.Address { return self.origin }

core/vm/runtime/runtime.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,17 @@ func (ruleSet) IsHomestead(*big.Int) bool { return true }
3535
// Config is a basic type specifying certain configuration flags for running
3636
// the EVM.
3737
type Config struct {
38-
RuleSet vm.RuleSet
39-
Difficulty *big.Int
40-
Origin common.Address
41-
Coinbase common.Address
42-
BlockNumber *big.Int
43-
Time *big.Int
44-
GasLimit *big.Int
45-
GasPrice *big.Int
46-
Value *big.Int
47-
DisableJit bool // "disable" so it's enabled by default
48-
Debug bool
49-
illegalHashes []common.Hash
38+
RuleSet vm.RuleSet
39+
Difficulty *big.Int
40+
Origin common.Address
41+
Coinbase common.Address
42+
BlockNumber *big.Int
43+
Time *big.Int
44+
GasLimit *big.Int
45+
GasPrice *big.Int
46+
Value *big.Int
47+
DisableJit bool // "disable" so it's enabled by default
48+
Debug bool
5049

5150
State *state.StateDB
5251
GetHashFn func(n uint64) common.Hash

core/vm_env.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ import (
2525
"github.com/ethereum/go-ethereum/core/vm"
2626
)
2727

28-
var IllegalCodeHashes map[common.Hash]struct{}
29-
3028
// GetHashFn returns a function for which the VM env can query block hashes through
3129
// up to the limit defined by the Yellow Paper and uses the given block chain
3230
// to query for information.
@@ -49,8 +47,6 @@ type VMEnv struct {
4947
depth int // Current execution depth
5048
msg Message // Message appliod
5149

52-
CodeHashes []common.Hash // code hashes collected during execution
53-
5450
header *types.Header // Header information
5551
chain *BlockChain // Blockchain handle
5652
logs []vm.StructLog // Logs for the custom structured logger
@@ -76,8 +72,6 @@ func NewEnv(state *state.StateDB, chainConfig *ChainConfig, chain *BlockChain, m
7672
return env
7773
}
7874

79-
func (self *VMEnv) MarkCodeHash(hash common.Hash) { self.CodeHashes = append(self.CodeHashes, hash) }
80-
8175
func (self *VMEnv) RuleSet() vm.RuleSet { return self.chainConfig }
8276
func (self *VMEnv) Vm() vm.Vm { return self.evm }
8377
func (self *VMEnv) Origin() common.Address { f, _ := self.msg.From(); return f }

0 commit comments

Comments
 (0)