Skip to content

Commit 98be7cd

Browse files
authored
Merge pull request ethereum#2735 from ethereum/release/1.4
Geth 1.4.8 "DAO Wars"
2 parents 667a386 + eaf706b commit 98be7cd

File tree

15 files changed

+475
-11
lines changed

15 files changed

+475
-11
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.4.7
1+
1.4.8

cmd/evm/main.go

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

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

223+
func (self *VMEnv) MarkCodeHash(common.Hash) {}
223224
func (self *VMEnv) RuleSet() vm.RuleSet { return ruleSet{} }
224225
func (self *VMEnv) Vm() vm.Vm { return self.evm }
225226
func (self *VMEnv) Db() vm.Database { return self.state }

cmd/geth/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const (
5050
clientIdentifier = "Geth" // Client identifier to advertise over the network
5151
versionMajor = 1 // Major version component of the current release
5252
versionMinor = 4 // Minor version component of the current release
53-
versionPatch = 7 // Patch version component of the current release
53+
versionPatch = 8 // Patch version component of the current release
5454
versionMeta = "stable" // Version metadata to append to the version string
5555

5656
versionOracle = "0xfa7b9770ca4cb04296cac84f37736d4041251cdf" // Ethereum address of the Geth release oracle
@@ -169,6 +169,7 @@ participating.
169169
utils.MiningGPUFlag,
170170
utils.AutoDAGFlag,
171171
utils.TargetGasLimitFlag,
172+
utils.DAOSoftForkFlag,
172173
utils.NATFlag,
173174
utils.NatspecEnabledFlag,
174175
utils.NoDiscoverFlag,

cmd/geth/usage.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ var AppHelpFlagGroups = []flagGroup{
128128
utils.TargetGasLimitFlag,
129129
utils.GasPriceFlag,
130130
utils.ExtraDataFlag,
131+
utils.DAOSoftForkFlag,
131132
},
132133
},
133134
{

cmd/utils/flags.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ var (
181181
Usage: "Target gas limit sets the artificial target gas floor for the blocks to mine",
182182
Value: params.GenesisGasLimit.String(),
183183
}
184+
DAOSoftForkFlag = cli.BoolFlag{
185+
Name: "dao-soft-fork",
186+
Usage: "Vote for the DAO soft-fork, temporarilly decreasing the gas limits",
187+
}
184188
AutoDAGFlag = cli.BoolFlag{
185189
Name: "autodag",
186190
Usage: "Enable automatic DAG pregeneration",
@@ -677,6 +681,9 @@ func MakeSystemNode(name, version string, relconf release.Config, extra []byte,
677681
// Configure the Ethereum service
678682
accman := MakeAccountManager(ctx)
679683

684+
// Handle some miner strategies arrising from the DAO fiasco
685+
core.DAOSoftFork = ctx.GlobalBool(DAOSoftForkFlag.Name)
686+
680687
// initialise new random number generator
681688
rand := rand.New(rand.NewSource(time.Now().UnixNano()))
682689
// get enabled jit flag

core/block_validator.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,5 +371,10 @@ 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+
}
374379
return gl
375380
}

core/dao_test.go

Lines changed: 358 additions & 0 deletions
Large diffs are not rendered by default.

core/execution.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ func exec(env vm.Environment, caller vm.ContractRef, address, codeAddr *common.A
8484
address = &addr
8585
createAccount = true
8686
}
87-
87+
// Mark all contracts doing outbound value transfers to allow DAO filtering.
88+
if value.Cmp(common.Big0) > 0 {
89+
env.MarkCodeHash(env.Db().GetCodeHash(caller.Address()))
90+
}
8891
snapshotPreTransfer := env.MakeSnapshot()
8992
var (
9093
from = env.Db().GetAccount(caller.Address())
@@ -143,7 +146,10 @@ func execDelegateCall(env vm.Environment, caller vm.ContractRef, originAddr, toA
143146
caller.ReturnGas(gas, gasPrice)
144147
return nil, common.Address{}, vm.DepthError
145148
}
146-
149+
// Mark all contracts doing outbound value transfers to allow DAO filtering.
150+
if value.Cmp(common.Big0) > 0 {
151+
env.MarkCodeHash(env.Db().GetCodeHash(caller.Address()))
152+
}
147153
snapshot := env.MakeSnapshot()
148154

149155
var to vm.Account

core/state/statedb.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,14 @@ func (self *StateDB) GetCode(addr common.Address) []byte {
161161
return nil
162162
}
163163

164+
func (self *StateDB) GetCodeHash(addr common.Address) common.Hash {
165+
stateObject := self.GetStateObject(addr)
166+
if stateObject != nil {
167+
return common.BytesToHash(stateObject.codeHash)
168+
}
169+
return common.Hash{}
170+
}
171+
164172
func (self *StateDB) GetState(a common.Address, b common.Hash) common.Hash {
165173
stateObject := self.GetStateObject(a)
166174
if stateObject != nil {

core/state_processor.go

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

1919
import (
20+
"errors"
2021
"math/big"
2122

23+
"github.com/ethereum/go-ethereum/common"
2224
"github.com/ethereum/go-ethereum/core/state"
2325
"github.com/ethereum/go-ethereum/core/types"
2426
"github.com/ethereum/go-ethereum/core/vm"
@@ -28,8 +30,25 @@ import (
2830
)
2931

3032
var (
31-
big8 = big.NewInt(8)
32-
big32 = big.NewInt(32)
33+
big8 = big.NewInt(8)
34+
big32 = big.NewInt(32)
35+
blockedCodeHashErr = errors.New("core: blocked code-hash found during execution")
36+
37+
// DAO attack chain rupture mechanism
38+
DAOSoftFork bool // Flag whether to vote for DAO rupture
39+
40+
ruptureBlock = uint64(1800000) // Block number of the voted soft fork
41+
ruptureTarget = big.NewInt(3141592) // Gas target (hard) for miners voting to fork
42+
ruptureThreshold = big.NewInt(4000000) // Gas threshold for passing a fork vote
43+
ruptureGasCache = make(map[common.Hash]*big.Int) // Amount of gas in the point of rupture
44+
ruptureCodeHashes = map[common.Hash]struct{}{
45+
common.HexToHash("6a5d24750f78441e56fec050dc52fe8e911976485b7472faac7464a176a67caa"): struct{}{},
46+
}
47+
ruptureWhitelist = map[common.Address]bool{
48+
common.HexToAddress("Da4a4626d3E16e094De3225A751aAb7128e96526"): true, // multisig
49+
common.HexToAddress("2ba9D006C1D72E67A70b5526Fc6b4b0C0fd6D334"): true, // attack contract
50+
}
51+
ruptureCacheLimit = 30000 // 1 epoch, 0.5 per possible fork
3352
)
3453

3554
// StateProcessor is a basic Processor, which takes care of transitioning
@@ -86,11 +105,56 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
86105
// ApplyTransactions returns the generated receipts and vm logs during the
87106
// execution of the state transition phase.
88107
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) {
89-
_, gas, err := ApplyMessage(NewEnv(statedb, config, bc, tx, header, cfg), tx, gp)
108+
env := NewEnv(statedb, config, bc, tx, header, cfg)
109+
_, gas, err := ApplyMessage(env, tx, gp)
90110
if err != nil {
91111
return nil, nil, nil, err
92112
}
93113

114+
// Check whether the DAO needs to be blocked or not
115+
if bc != nil { // Test chain maker uses nil to construct the potential chain
116+
blockRuptureCodes := false
117+
118+
if number := header.Number.Uint64(); number >= ruptureBlock {
119+
// We're past the rupture point, find the vote result on this chain and apply it
120+
ancestry := []common.Hash{header.Hash(), header.ParentHash}
121+
for _, ok := ruptureGasCache[ancestry[len(ancestry)-1]]; !ok && number >= ruptureBlock+uint64(len(ancestry)); {
122+
ancestry = append(ancestry, bc.GetHeader(ancestry[len(ancestry)-1]).ParentHash)
123+
}
124+
decider := ancestry[len(ancestry)-1]
125+
126+
vote, ok := ruptureGasCache[decider]
127+
if !ok {
128+
// We've reached the rupture point, retrieve the vote
129+
vote = bc.GetHeader(decider).GasLimit
130+
ruptureGasCache[decider] = vote
131+
}
132+
// Cache the vote result for all ancestors and check the DAO
133+
for _, hash := range ancestry {
134+
ruptureGasCache[hash] = vote
135+
}
136+
if ruptureGasCache[ancestry[0]].Cmp(ruptureThreshold) <= 0 {
137+
blockRuptureCodes = true
138+
}
139+
// Make sure we don't OOM long run due to too many votes caching up
140+
for len(ruptureGasCache) > ruptureCacheLimit {
141+
for hash, _ := range ruptureGasCache {
142+
delete(ruptureGasCache, hash)
143+
break
144+
}
145+
}
146+
}
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+
}
154+
}
155+
}
156+
}
157+
}
94158
// Update the state with pending changes
95159
usedGas.Add(usedGas, gas)
96160
receipt := types.NewReceipt(statedb.IntermediateRoot().Bytes(), usedGas)

0 commit comments

Comments
 (0)