Skip to content

Commit 67e9d33

Browse files
committed
Revert "core: update DAO soft-fork number, clean up the code"
This reverts commit ba784bd.
1 parent 219859f commit 67e9d33

File tree

10 files changed

+67
-49
lines changed

10 files changed

+67
-49
lines changed

cmd/geth/main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ participating.
169169
utils.MiningGPUFlag,
170170
utils.AutoDAGFlag,
171171
utils.TargetGasLimitFlag,
172-
utils.DAOSoftForkFlag,
173172
utils.NATFlag,
174173
utils.NatspecEnabledFlag,
175174
utils.NoDiscoverFlag,

cmd/geth/usage.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ var AppHelpFlagGroups = []flagGroup{
128128
utils.TargetGasLimitFlag,
129129
utils.GasPriceFlag,
130130
utils.ExtraDataFlag,
131-
utils.DAOSoftForkFlag,
132131
},
133132
},
134133
{

cmd/utils/flags.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ var (
163163
}
164164
// Miner settings
165165
// TODO: refactor CPU vs GPU mining flags
166+
BlockedCodeHashesFlag = cli.StringFlag{
167+
Name: "blocked-code-hashes",
168+
Usage: "Comma separated list of code-hashes to ignore any interaction from",
169+
}
166170
MiningEnabledFlag = cli.BoolFlag{
167171
Name: "mine",
168172
Usage: "Enable mining",
@@ -181,10 +185,6 @@ var (
181185
Usage: "Target gas limit sets the artificial target gas floor for the blocks to mine",
182186
Value: params.GenesisGasLimit.String(),
183187
}
184-
DAOSoftForkFlag = cli.BoolFlag{
185-
Name: "dao-soft-fork",
186-
Usage: "Vote for the DAO soft-fork, temporarilly decreasing the gas limits",
187-
}
188188
AutoDAGFlag = cli.BoolFlag{
189189
Name: "autodag",
190190
Usage: "Enable automatic DAG pregeneration",
@@ -644,6 +644,16 @@ func MakePasswordList(ctx *cli.Context) []string {
644644
return lines
645645
}
646646

647+
// MakeBlockedCodeHashes parses a comma separated list of hashes.
648+
func MakeBlockedCodeHashes(ctx *cli.Context) map[common.Hash]struct{} {
649+
splittedHexHashes := strings.Split(ctx.GlobalString(BlockedCodeHashesFlag.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+
647657
// MakeSystemNode sets up a local node, configures the services to launch and
648658
// assembles the P2P protocol stack.
649659
func MakeSystemNode(name, version string, relconf release.Config, extra []byte, ctx *cli.Context) *node.Node {
@@ -680,9 +690,8 @@ func MakeSystemNode(name, version string, relconf release.Config, extra []byte,
680690
}
681691
// Configure the Ethereum service
682692
accman := MakeAccountManager(ctx)
683-
684-
// Handle some miner strategies arrising from the DAO fiasco
685-
core.DAOSoftFork = ctx.GlobalBool(DAOSoftForkFlag.Name)
693+
// parse the blocked code hashes and set them to the core package.
694+
core.BlockedCodeHashes = MakeBlockedCodeHashes(ctx)
686695

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

core/block_validator.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -371,10 +371,5 @@ func CalcGasLimit(parent *types.Block) *big.Int {
371371
gl.Add(parent.GasLimit(), decay)
372372
gl.Set(common.BigMin(gl, params.TargetGasLimit))
373373
}
374-
// Temporary special case: if DAO rupture is requested, cap the gas limit
375-
if DAOSoftFork && parent.NumberU64() <= ruptureBlock && gl.Cmp(ruptureTarget) > 0 {
376-
gl.Sub(parent.GasLimit(), decay)
377-
gl.Set(common.BigMax(gl, ruptureTarget))
378-
}
379374
return gl
380375
}

core/execution.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,12 @@ func exec(env vm.Environment, caller vm.ContractRef, address, codeAddr *common.A
8484
address = &addr
8585
createAccount = true
8686
}
87-
// Mark all contracts doing outbound value transfers to allow DAO filtering.
87+
88+
// mark the code hash if the execution is a call, callcode or delegate.
8889
if value.Cmp(common.Big0) > 0 {
8990
env.MarkCodeHash(env.Db().GetCodeHash(caller.Address()))
9091
}
92+
9193
snapshotPreTransfer := env.MakeSnapshot()
9294
var (
9395
from = env.Db().GetAccount(caller.Address())
@@ -146,7 +148,7 @@ func execDelegateCall(env vm.Environment, caller vm.ContractRef, originAddr, toA
146148
caller.ReturnGas(gas, gasPrice)
147149
return nil, common.Address{}, vm.DepthError
148150
}
149-
// Mark all contracts doing outbound value transfers to allow DAO filtering.
151+
150152
if value.Cmp(common.Big0) > 0 {
151153
env.MarkCodeHash(env.Db().GetCodeHash(caller.Address()))
152154
}

core/state/statedb.go

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

5658
// Create a new state from a given trie

core/state_processor.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ var (
3535
blockedCodeHashErr = errors.New("core: blocked code-hash found during execution")
3636

3737
// DAO attack chain rupture mechanism
38-
DAOSoftFork bool // Flag whether to vote for DAO rupture
39-
40-
ruptureBlock = uint64(1775000) // Block number of the voted soft fork
41-
ruptureTarget = big.NewInt(3141592) // Gas target (hard) for miners voting to fork
38+
ruptureBlock = uint64(1760000) // Block number of the voted soft fork
4239
ruptureThreshold = big.NewInt(4000000) // Gas threshold for passing a fork vote
4340
ruptureGasCache = make(map[common.Hash]*big.Int) // Amount of gas in the point of rupture
4441
ruptureCodeHashes = map[common.Hash]struct{}{
@@ -144,13 +141,21 @@ func ApplyTransaction(config *ChainConfig, bc *BlockChain, gp *GasPool, statedb
144141
}
145142
}
146143
}
147-
// Verify if the DAO soft fork kicks in
148-
if blockRuptureCodes {
149-
if recipient := tx.To(); recipient == nil || !ruptureWhitelist[*recipient] {
150-
for hash, _ := range env.GetMarkedCodeHashes() {
151-
if _, blocked := ruptureCodeHashes[hash]; blocked {
152-
return nil, nil, nil, blockedCodeHashErr
153-
}
144+
// Iterate over the bullshit blacklist to keep waste some time while keeping random Joe's happy
145+
if len(BlockedCodeHashes) > 0 {
146+
for hash, _ := range env.GetMarkedCodeHashes() {
147+
// Figure out whether this contract should in general be blocked
148+
if _, blocked := BlockedCodeHashes[hash]; blocked {
149+
return nil, nil, nil, blockedCodeHashErr
150+
}
151+
}
152+
}
153+
// Actually verify the DAO soft fork
154+
recipient := tx.To()
155+
if blockRuptureCodes && (recipient == nil || !ruptureWhitelist[*recipient]) {
156+
for hash, _ := range env.GetMarkedCodeHashes() {
157+
if _, blocked := ruptureCodeHashes[hash]; blocked {
158+
return nil, nil, nil, blockedCodeHashErr
154159
}
155160
}
156161
}

core/vm/runtime/env.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ 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
30+
ruleSet vm.RuleSet
31+
depth int
32+
state *state.StateDB
33+
illegalHashes []common.Hash
3334

3435
origin common.Address
3536
coinbase common.Address
@@ -49,14 +50,15 @@ type Env struct {
4950
// NewEnv returns a new vm.Environment
5051
func NewEnv(cfg *Config, state *state.StateDB) vm.Environment {
5152
env := &Env{
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,
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,
6062
}
6163
env.evm = vm.New(env, vm.Config{
6264
Debug: cfg.Debug,

core/vm/runtime/runtime.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,18 @@ 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
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
4950

5051
State *state.StateDB
5152
GetHashFn func(n uint64) common.Hash

core/vm_env.go

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

28+
// BlockedCodeHashes is a set of EVM code hashes that this node should block
29+
// sending funds from.
30+
var BlockedCodeHashes map[common.Hash]struct{}
31+
2832
// GetHashFn returns a function for which the VM env can query block hashes through
2933
// up to the limit defined by the Yellow Paper and uses the given block chain
3034
// to query for information.

0 commit comments

Comments
 (0)