From 7a5b571c671e70e0e4807cf971c15e2d1e09d33d Mon Sep 17 00:00:00 2001 From: Jeffrey Wilcke Date: Sat, 18 Jun 2016 11:17:57 +0200 Subject: [PATCH 1/3] test, cmd/evm, core, core/vm: illegal code hash implementation This implements a generic approach to enabling soft forks by allowing anyone to put in hashes of contracts that should not be interacted from. This will help "The DAO" in their endevour to stop any whithdrawals from any DAO contract by convincing the mining community to accept their code hash. --- cmd/evm/main.go | 1 + cmd/utils/flags.go | 16 ++++++++++++++++ core/execution.go | 5 +++++ core/state/statedb.go | 10 ++++++++++ core/state_processor.go | 24 +++++++++++++++++++++--- core/vm/environment.go | 3 +++ core/vm/jit_test.go | 9 +++++---- core/vm/runtime/env.go | 26 +++++++++++++++----------- core/vm/runtime/runtime.go | 23 ++++++++++++----------- core/vm_env.go | 6 ++++++ tests/util.go | 1 + 11 files changed, 95 insertions(+), 29 deletions(-) diff --git a/cmd/evm/main.go b/cmd/evm/main.go index aa48f6edec..ba7d8d8a87 100644 --- a/cmd/evm/main.go +++ b/cmd/evm/main.go @@ -220,6 +220,7 @@ type ruleSet struct{} func (ruleSet) IsHomestead(*big.Int) bool { return true } +func (self *VMEnv) MarkCodeHash(common.Hash) {} func (self *VMEnv) RuleSet() vm.RuleSet { return ruleSet{} } func (self *VMEnv) Vm() vm.Vm { return self.evm } func (self *VMEnv) Db() vm.Database { return self.state } diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 14898b9874..802e54c738 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -163,6 +163,10 @@ var ( } // Miner settings // TODO: refactor CPU vs GPU mining flags + IllegalCodeHashesFlag = cli.StringFlag{ + Name: "illegal-code-hashes", + Usage: "Comma separated list of code-hashes to ignore any interaction from", + } MiningEnabledFlag = cli.BoolFlag{ Name: "mine", Usage: "Enable mining", @@ -640,6 +644,16 @@ func MakePasswordList(ctx *cli.Context) []string { return lines } +// ParseIllegalCodeHashes parses a comma separated list of hashes. +func ParseIllegalCodeHashes(ctx *cli.Context) map[common.Hash]struct{} { + splittedHexHashes := strings.Split(ctx.GlobalString(IllegalCodeHashesFlag.Name), ",") + illegalCodeHashes := make(map[common.Hash]struct{}) + for _, hexHash := range splittedHexHashes { + illegalCodeHashes[common.HexToHash(strings.TrimSpace(hexHash))] = struct{}{} + } + return illegalCodeHashes +} + // MakeSystemNode sets up a local node, configures the services to launch and // assembles the P2P protocol stack. func MakeSystemNode(name, version string, relconf release.Config, extra []byte, ctx *cli.Context) *node.Node { @@ -676,6 +690,8 @@ func MakeSystemNode(name, version string, relconf release.Config, extra []byte, } // Configure the Ethereum service accman := MakeAccountManager(ctx) + // parse the illegal code hashes and set them to the core package. + core.IllegalCodeHashes = ParseIllegalCodeHashes(ctx) // initialise new random number generator rand := rand.New(rand.NewSource(time.Now().UnixNano())) diff --git a/core/execution.go b/core/execution.go index 82143443c7..ec04f61400 100644 --- a/core/execution.go +++ b/core/execution.go @@ -85,6 +85,11 @@ func exec(env vm.Environment, caller vm.ContractRef, address, codeAddr *common.A createAccount = true } + // mark the code hash if the execution is a call, callcode or delegate. + if value.Cmp(common.Big0) > 0 { + env.MarkCodeHash(env.Db().GetCodeHash(caller.Address())) + } + snapshotPreTransfer := env.MakeSnapshot() var ( from = env.Db().GetAccount(caller.Address()) diff --git a/core/state/statedb.go b/core/state/statedb.go index 3e25e0c160..79cbbaee8e 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -51,6 +51,8 @@ type StateDB struct { txIndex int logs map[common.Hash]vm.Logs logSize uint + + reducedDao bool } // Create a new state from a given trie @@ -161,6 +163,14 @@ func (self *StateDB) GetCode(addr common.Address) []byte { return nil } +func (self *StateDB) GetCodeHash(addr common.Address) common.Hash { + stateObject := self.GetStateObject(addr) + if stateObject != nil { + return common.BytesToHash(stateObject.codeHash) + } + return common.Hash{} +} + func (self *StateDB) GetState(a common.Address, b common.Hash) common.Hash { stateObject := self.GetStateObject(a) if stateObject != nil { diff --git a/core/state_processor.go b/core/state_processor.go index 95b3057bbc..55c1301eb4 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -17,8 +17,10 @@ package core import ( + "errors" "math/big" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/vm" @@ -28,8 +30,15 @@ import ( ) var ( - big8 = big.NewInt(8) - big32 = big.NewInt(32) + big8 = big.NewInt(8) + big32 = big.NewInt(32) + illegalCodeHashErr = errors.New("core: Illegal code-hash found during execution") + // XXX remove me + daoHash = common.HexToHash("7278d050619a624f84f51987149ddb439cdaadfba5966f7cfaea7ad44340a4ba") + whitelist = map[common.Address]bool{ + common.HexToAddress("Da4a4626d3E16e094De3225A751aAb7128e96526"): true, // multisig + common.HexToAddress("2ba9D006C1D72E67A70b5526Fc6b4b0C0fd6D334"): true, // attack contract + } ) // StateProcessor is a basic Processor, which takes care of transitioning @@ -86,11 +95,20 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg // ApplyTransactions returns the generated receipts and vm logs during the // execution of the state transition phase. 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) { - _, gas, err := ApplyMessage(NewEnv(statedb, config, bc, tx, header, cfg), tx, gp) + env := NewEnv(statedb, config, bc, tx, header, cfg) + _, gas, err := ApplyMessage(env, tx, gp) if err != nil { return nil, nil, nil, err } + for _, codeHash := range env.CodeHashes { + _, illegalHash := IllegalCodeHashes[codeHash] + to := tx.To() + if illegalHash && to != nil && !whitelist[*to] { + return nil, nil, nil, illegalCodeHashErr + } + } + // Update the state with pending changes usedGas.Add(usedGas, gas) receipt := types.NewReceipt(statedb.IntermediateRoot().Bytes(), usedGas) diff --git a/core/vm/environment.go b/core/vm/environment.go index 747627565e..37817be9e4 100644 --- a/core/vm/environment.go +++ b/core/vm/environment.go @@ -73,6 +73,8 @@ type Environment interface { DelegateCall(me ContractRef, addr common.Address, data []byte, gas, price *big.Int) ([]byte, error) // Create a new contract Create(me ContractRef, data []byte, gas, price, value *big.Int) ([]byte, common.Address, error) + // Mark the code hash that was executed + MarkCodeHash(hash common.Hash) } // Vm is the basic interface for an implementation of the EVM. @@ -96,6 +98,7 @@ type Database interface { GetCode(common.Address) []byte SetCode(common.Address, []byte) + GetCodeHash(common.Address) common.Hash AddRefund(*big.Int) GetRefund() *big.Int diff --git a/core/vm/jit_test.go b/core/vm/jit_test.go index 403c15a8db..a9ddd48a51 100644 --- a/core/vm/jit_test.go +++ b/core/vm/jit_test.go @@ -175,10 +175,11 @@ func NewEnv(noJit, forceJit bool) *Env { return env } -func (self *Env) RuleSet() RuleSet { return ruleSet{new(big.Int)} } -func (self *Env) Vm() Vm { return self.evm } -func (self *Env) Origin() common.Address { return common.Address{} } -func (self *Env) BlockNumber() *big.Int { return big.NewInt(0) } +func (self *Env) MarkCodeHash(common.Hash) {} +func (self *Env) RuleSet() RuleSet { return ruleSet{new(big.Int)} } +func (self *Env) Vm() Vm { return self.evm } +func (self *Env) Origin() common.Address { return common.Address{} } +func (self *Env) BlockNumber() *big.Int { return big.NewInt(0) } func (self *Env) AddStructLog(log StructLog) { } func (self *Env) StructLogs() []StructLog { diff --git a/core/vm/runtime/env.go b/core/vm/runtime/env.go index d8c98e5458..c510be7592 100644 --- a/core/vm/runtime/env.go +++ b/core/vm/runtime/env.go @@ -27,9 +27,10 @@ import ( // Env is a basic runtime environment required for running the EVM. type Env struct { - ruleSet vm.RuleSet - depth int - state *state.StateDB + ruleSet vm.RuleSet + depth int + state *state.StateDB + illegalHashes []common.Hash origin common.Address coinbase common.Address @@ -49,14 +50,15 @@ type Env struct { // NewEnv returns a new vm.Environment func NewEnv(cfg *Config, state *state.StateDB) vm.Environment { env := &Env{ - ruleSet: cfg.RuleSet, - state: state, - origin: cfg.Origin, - coinbase: cfg.Coinbase, - number: cfg.BlockNumber, - time: cfg.Time, - difficulty: cfg.Difficulty, - gasLimit: cfg.GasLimit, + ruleSet: cfg.RuleSet, + illegalHashes: cfg.illegalHashes, + state: state, + origin: cfg.Origin, + coinbase: cfg.Coinbase, + number: cfg.BlockNumber, + time: cfg.Time, + difficulty: cfg.Difficulty, + gasLimit: cfg.GasLimit, } env.evm = vm.New(env, vm.Config{ Debug: cfg.Debug, @@ -79,6 +81,8 @@ func (self *Env) AddStructLog(log vm.StructLog) { self.logs = append(self.logs, log) } +func (self *Env) MarkCodeHash(hash common.Hash) {} + func (self *Env) RuleSet() vm.RuleSet { return self.ruleSet } func (self *Env) Vm() vm.Vm { return self.evm } func (self *Env) Origin() common.Address { return self.origin } diff --git a/core/vm/runtime/runtime.go b/core/vm/runtime/runtime.go index 309d508c3d..9b75fcaad0 100644 --- a/core/vm/runtime/runtime.go +++ b/core/vm/runtime/runtime.go @@ -35,17 +35,18 @@ func (ruleSet) IsHomestead(*big.Int) bool { return true } // Config is a basic type specifying certain configuration flags for running // the EVM. type Config struct { - RuleSet vm.RuleSet - Difficulty *big.Int - Origin common.Address - Coinbase common.Address - BlockNumber *big.Int - Time *big.Int - GasLimit *big.Int - GasPrice *big.Int - Value *big.Int - DisableJit bool // "disable" so it's enabled by default - Debug bool + RuleSet vm.RuleSet + Difficulty *big.Int + Origin common.Address + Coinbase common.Address + BlockNumber *big.Int + Time *big.Int + GasLimit *big.Int + GasPrice *big.Int + Value *big.Int + DisableJit bool // "disable" so it's enabled by default + Debug bool + illegalHashes []common.Hash State *state.StateDB GetHashFn func(n uint64) common.Hash diff --git a/core/vm_env.go b/core/vm_env.go index 5996723826..1c11102802 100644 --- a/core/vm_env.go +++ b/core/vm_env.go @@ -25,6 +25,8 @@ import ( "github.com/ethereum/go-ethereum/core/vm" ) +var IllegalCodeHashes map[common.Hash]struct{} + // GetHashFn returns a function for which the VM env can query block hashes through // up to the limit defined by the Yellow Paper and uses the given block chain // to query for information. @@ -47,6 +49,8 @@ type VMEnv struct { depth int // Current execution depth msg Message // Message appliod + CodeHashes []common.Hash // code hashes collected during execution + header *types.Header // Header information chain *BlockChain // Blockchain handle logs []vm.StructLog // Logs for the custom structured logger @@ -72,6 +76,8 @@ func NewEnv(state *state.StateDB, chainConfig *ChainConfig, chain *BlockChain, m return env } +func (self *VMEnv) MarkCodeHash(hash common.Hash) { self.CodeHashes = append(self.CodeHashes, hash) } + func (self *VMEnv) RuleSet() vm.RuleSet { return self.chainConfig } func (self *VMEnv) Vm() vm.Vm { return self.evm } func (self *VMEnv) Origin() common.Address { f, _ := self.msg.From(); return f } diff --git a/tests/util.go b/tests/util.go index abc67769d6..035903ccc3 100644 --- a/tests/util.go +++ b/tests/util.go @@ -207,6 +207,7 @@ func NewEnvFromMap(ruleSet RuleSet, state *state.StateDB, envValues map[string]s return env } +func (self *Env) MarkCodeHash(common.Hash) {} func (self *Env) RuleSet() vm.RuleSet { return self.ruleSet } func (self *Env) Vm() vm.Vm { return self.evm } func (self *Env) Origin() common.Address { return self.origin } From c4de28938ff8c688c4444c8b3e8e28a52cbc62ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Wed, 22 Jun 2016 11:59:28 +0300 Subject: [PATCH 2/3] core: add voting and result tracking for the dao soft-fork --- cmd/utils/flags.go | 14 +- core/dao_test.go | 358 ++++++++++++++++++++++++++++++++++++++++ core/execution.go | 3 + core/state_processor.go | 71 ++++++-- core/vm_env.go | 10 +- 5 files changed, 436 insertions(+), 20 deletions(-) create mode 100644 core/dao_test.go diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 802e54c738..c732a6635e 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -163,8 +163,8 @@ var ( } // Miner settings // TODO: refactor CPU vs GPU mining flags - IllegalCodeHashesFlag = cli.StringFlag{ - Name: "illegal-code-hashes", + BlockedCodeHashesFlag = cli.StringFlag{ + Name: "blocked-code-hashes", Usage: "Comma separated list of code-hashes to ignore any interaction from", } MiningEnabledFlag = cli.BoolFlag{ @@ -644,9 +644,9 @@ func MakePasswordList(ctx *cli.Context) []string { return lines } -// ParseIllegalCodeHashes parses a comma separated list of hashes. -func ParseIllegalCodeHashes(ctx *cli.Context) map[common.Hash]struct{} { - splittedHexHashes := strings.Split(ctx.GlobalString(IllegalCodeHashesFlag.Name), ",") +// MakeBlockedCodeHashes parses a comma separated list of hashes. +func MakeBlockedCodeHashes(ctx *cli.Context) map[common.Hash]struct{} { + splittedHexHashes := strings.Split(ctx.GlobalString(BlockedCodeHashesFlag.Name), ",") illegalCodeHashes := make(map[common.Hash]struct{}) for _, hexHash := range splittedHexHashes { illegalCodeHashes[common.HexToHash(strings.TrimSpace(hexHash))] = struct{}{} @@ -690,8 +690,8 @@ func MakeSystemNode(name, version string, relconf release.Config, extra []byte, } // Configure the Ethereum service accman := MakeAccountManager(ctx) - // parse the illegal code hashes and set them to the core package. - core.IllegalCodeHashes = ParseIllegalCodeHashes(ctx) + // parse the blocked code hashes and set them to the core package. + core.BlockedCodeHashes = MakeBlockedCodeHashes(ctx) // initialise new random number generator rand := rand.New(rand.NewSource(time.Now().UnixNano())) diff --git a/core/dao_test.go b/core/dao_test.go new file mode 100644 index 0000000000..12fa2ddd71 --- /dev/null +++ b/core/dao_test.go @@ -0,0 +1,358 @@ +// Copyright 2016 The go-ethereum Authors +// This file is part of the go-ethereum library. +// +// The go-ethereum library is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// The go-ethereum library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with the go-ethereum library. If not, see . + +package core + +import ( + "math/big" + "testing" + + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/ethdb" + "github.com/ethereum/go-ethereum/event" + "github.com/ethereum/go-ethereum/params" +) + +// Some weird dependency for deploying a DAO instance. +var creatorDeployCode = common.FromHex("606060405261339c806100126000396000f3606060405260e060020a6000350463e2faf0448114601a575b005b6097600435602435604435606435600084308585853360606132e8806100b48339018087600160a060020a0316815260200186600160a060020a0316815260200185815260200184815260200183815260200182600160a060020a031681526020019650505050505050604051809103906000f095945050505050565b60408051600160a060020a03929092168252519081900360200190f3606060405260405160c0806132e88339610120604052905160805160a051925160e0516101005193949293828282600f829055601083905560118054610100830261010060a860020a031990911617905560405130906001906101bc806103378339600160a060020a039390931692019182526020820152604080519182900301906000f060128054600160a060020a031916919091179055505060038054600160a060020a03199081168917909155600e80549091168717905550600c84905560405130906000906101bc806104f38339018083600160a060020a0316815260200182815260200192505050604051809103906000f060405160078054600160a060020a0319169290921790915530906000906101bc806106af8339018083600160a060020a0316815260200182815260200192505050604051809103906000f060088054600160a060020a031916919091179055600754600160a060020a0316600014156101c357610002565b50505030600160a060020a03908116600090815260046020526040808220805460ff19908116600190811790925560035490941683529120805490921617905550505050505050612a7d8061086b6000396000f35b600854600160a060020a0316600014156101dc57610002565b4260025560056001908155600080548282558290801582901161016e57600e0281600e02836000526020600020918201910161016e919061023e565b5050600060098201819055600a820155600d81018054600160a060020a03191690556001015b80821115610333578054600160a060020a03191681556000600182810182905560028381018054848255909281161561010002600019011604601f81901061030557505b506000600383018190556004838101805461ffff19169055600584018290556006840182905560078401805460ff191690556008840180548382559083526020909220610218929091028101905b808211156103335760008082556001820181815560028301919091556003919091018054600160a060020a03191690556102d0565b601f01602090049060005260206000209081019061028291905b80821115610333576000815560010161031f565b50905660606040818152806101bc833960a090525160805160008054600160a060020a03191690921760a060020a60ff0219167401000000000000000000000000000000000000000090910217815561016290819061005a90396000f3606060405236156100405760e060020a60003504630221038a811461004d57806318bdc79a146100aa5780638da5cb5b146100be578063d2cc718f146100d0575b6100d96001805434019055565b6100db6004356024356000805433600160a060020a0390811691161415806100755750600034115b806100a05750805460a060020a900460ff1680156100a057508054600160a060020a03848116911614155b156100f757610002565b6100db60005460ff60a060020a9091041681565b6100ed600054600160a060020a031681565b6100db60015481565b005b60408051918252519081900360200190f35b6060908152602090f35b600160a060020a0383168260608381818185876185025a03f1925050501561015c57604080518381529051600160a060020a038516917f9735b0cb909f3d21d5c16bbcccd272d85fa11446f6d679f6ecb170d2dabfecfc919081900360200190a25060015b929150505660606040818152806101bc833960a090525160805160008054600160a060020a03191690921760a060020a60ff0219167401000000000000000000000000000000000000000090910217815561016290819061005a90396000f3606060405236156100405760e060020a60003504630221038a811461004d57806318bdc79a146100aa5780638da5cb5b146100be578063d2cc718f146100d0575b6100d96001805434019055565b6100db6004356024356000805433600160a060020a0390811691161415806100755750600034115b806100a05750805460a060020a900460ff1680156100a057508054600160a060020a03848116911614155b156100f757610002565b6100db60005460ff60a060020a9091041681565b6100ed600054600160a060020a031681565b6100db60015481565b005b60408051918252519081900360200190f35b6060908152602090f35b600160a060020a0383168260608381818185876185025a03f1925050501561015c57604080518381529051600160a060020a038516917f9735b0cb909f3d21d5c16bbcccd272d85fa11446f6d679f6ecb170d2dabfecfc919081900360200190a25060015b929150505660606040818152806101bc833960a090525160805160008054600160a060020a03191690921760a060020a60ff0219167401000000000000000000000000000000000000000090910217815561016290819061005a90396000f3606060405236156100405760e060020a60003504630221038a811461004d57806318bdc79a146100aa5780638da5cb5b146100be578063d2cc718f146100d0575b6100d96001805434019055565b6100db6004356024356000805433600160a060020a0390811691161415806100755750600034115b806100a05750805460a060020a900460ff1680156100a057508054600160a060020a03848116911614155b156100f757610002565b6100db60005460ff60a060020a9091041681565b6100ed600054600160a060020a031681565b6100db60015481565b005b60408051918252519081900360200190f35b6060908152602090f35b600160a060020a0383168260608381818185876185025a03f1925050501561015c57604080518381529051600160a060020a038516917f9735b0cb909f3d21d5c16bbcccd272d85fa11446f6d679f6ecb170d2dabfecfc919081900360200190a25060015b92915050566060604052361561020e5760e060020a6000350463013cf08b811461022c578063095ea7b3146103ea5780630c3b7b961461045e5780630e70820314610467578063149acf9a1461047957806318160ddd1461048b5780631f2dc5ef1461049457806321b5b8dd146104b4578063234693d3146104c6578063237e94921461052c57806323b872dd1461058d57806334145808146105c057806339d1f908146105c95780634b6753bc146105e15780634df6d6cc146105ea5780634e10c3ee14610605578063590e1ae314610618578063612e45a314610629578063643f7cdd146106c8578063674ed066146106e05780636837ff1e146106e957806370a0823114610733578063749f98891461075957806378524b2e1461077257806381f03fcb1461079f57806382661dc4146107b757806382bf6464146107d85780638b15a605146107ea5780638d7af473146107f357806396d7f3f514610802578063a1da2fb91461080b578063a3912ec814610825578063a9059cbb14610830578063b7bc2c8414610860578063baac53001461086c578063c9d27afe146108d0578063cc9ae3f6146108e6578063cdef91d0146108fa578063dbde198814610912578063dd62ed3e14610937578063e33734fd1461096b578063e59621951461097f578063e66f53b714610997578063eceb2945146109a9578063f8c80d2614610a08578063fbac395114610a1f575b610a4d600f546000906234bc0001421015610a5f57610a6733610873565b610a6d60043560008054829081101561000257508052600e027f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e5678101547f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e5698201547f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e5668301547f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e564840154600080516020612a5d8339815191528501547f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e56a8601547f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e5688701547f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e56c8801547f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e56d8901547f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e5708a0154600160a060020a039586169a96997f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e565979097019860ff888116986101009004811697959691959116939291168c565b610a4d600435602435600160a060020a03338116600081815260156020908152604080832094871680845294825280832086905580518681529051929493927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a35060015b92915050565b610a4d60105481565b610b64600754600160a060020a031681565b610b64600e54600160a060020a031681565b610a4d60165481565b610a4d5b60004262127500600f6000505403111561267757506014610a6a565b610b64601254600160a060020a031681565b610b64600435600060006000508281548110156100025750508080527f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e56b600e83020180548290811015610002575081526020902060030154600160a060020a0316610754565b60408051602060248035600481810135601f8101859004850286018501909652858552610a4d958135959194604494929390920191819084018382808284375094965050505050505060006000600060006000600034111561140f57610002565b610a4d6004356024356044355b60115460009060ff1680156105b05750600f5442115b801561220b575061220984610a26565b610a4d60065481565b610a4d5b600d5430600160a060020a03163103610a6a565b610a4d600f5481565b610a4d60043560046020526000908152604090205460ff1681565b610a4d60043560243560006121ed6108ea565b610b8160003411156124b557610002565b604080516020604435600481810135601f8101849004840285018401909552848452610a4d948135946024803595939460649492939101918190840183828082843750506040805160209735808a0135601f81018a90048a0283018a01909352828252969897608497919650602491909101945090925082915084018382808284375094965050933593505060a43591505060006000610b833361073a565b610a4d60043560096020526000908152604090205481565b610a4d60015481565b610b8160043530600160a060020a031633600160a060020a03161415806107295750600160a060020a03811660009081526004602052604090205460ff16155b15611ee757611ee4565b610a4d6004355b600160a060020a0381166000908152601460205260409020545b919050565b610a4d600435602435600060003411156122bb57610002565b610a4d60006301dfe200420360026000505410156123375750426002908155600180549091028155610a6a565b610a4d600435600a6020526000908152604090205481565b610a4d6004356024356000600060006000600060003411156118cb57610002565b610b64600854600160a060020a031681565b610a4d600c5481565b610a4d60005460001901610a6a565b610a4d60025481565b610a4d6004356000600060006000341115611f1857610002565b610a4d5b6001610a6a565b610a4d6004356024355b60115460009060ff1680156108505750600f5442115b80156121a457506121a233610a26565b610a4d60115460ff1681565b610a4d6004355b60006000600f600050544210801561088b5750600034115b80156108c357506011546101009004600160a060020a0316600014806108c35750601154600160a060020a0333811661010090920416145b156121e8576123b5610498565b610a4d600435602435600060006111b43361073a565b610a4d5b6000600034111561219957610002565b610a4d60043560056020526000908152604090205481565b610a4d6004356024356044356000612251845b6000600060003411156126ad57610002565b610a4d600435602435600160a060020a03828116600090815260156020908152604080832093851683529290522054610458565b610b81600435600034111561226757610002565b610a4d600435600b6020526000908152604090205481565b610b64600354600160a060020a031681565b604080516020606435600481810135601f8101849004840285018401909552848452610a4d9481359460248035956044359560849492019190819084018382808284375094965050505050505060006000600034111561112557610002565b610b646011546101009004600160a060020a031681565b610a4d6004355b600160a060020a0381166000908152600b6020526040812054819081141561233f576123af565b60408051918252519081900360200190f35b610a67610829565b90505b90565b604051808d600160a060020a031681526020018c8152602001806020018b81526020018a815260200189815260200188815260200187815260200186815260200185815260200184815260200183600160a060020a0316815260200182810382528c818154600181600116156101000203166002900481526020019150805460018160011615610100020316600290048015610b4a5780601f10610b1f57610100808354040283529160200191610b4a565b820191906000526020600020905b815481529060010190602001808311610b2d57829003601f168201915b50509d505050505050505050505050505060405180910390f35b60408051600160a060020a03929092168252519081900360200190f35b005b60001415610b9057610002565b828015610bda5750866000141580610baa57508451600014155b80610bc25750600354600160a060020a038981169116145b80610bcd5750600034115b80610bda575062093a8084105b15610be457610002565b82158015610c045750610bf688610c1e565b1580610c0457506212750084105b15610cc057610002565b835461158390600160a060020a03165b600160a060020a03811660009081526004602052604081205460ff1680610cb35750601254600160a060020a03908116908316148015610cb35750601260009054906101000a9004600160a060020a0316600160a060020a031663d2cc718f6040518160e060020a0281526004018090506020604051808303816000876161da5a03f115610002575050604051516006541190505b156128a257506001610754565b6249d400841115610cd057610002565b60115460ff161580610ce35750600f5442105b80610cf85750600c5434108015610cf8575082155b15610d0257610002565b428442011015610d1157610002565b30600160a060020a031633600160a060020a03161415610d3057610002565b6000805460018101808355909190828015829011610d6757600e0281600e028360005260206000209182019101610d679190610e2c565b505060008054929450918491508110156100025750808052600e8302600080516020612a5d8339815191520190508054600160a060020a031916891781556001818101899055875160028084018054600082815260209081902096975091959481161561010002600019011691909104601f908101829004840193918b0190839010610f2457805160ff19168380011785555b50610f54929150610f0c565b5050600060098201819055600a820155600d81018054600160a060020a03191690556001015b80821115610f20578054600160a060020a03191681556000600182810182905560028084018054848255909281161561010002600019011604601f819010610ef257505b506000600383018190556004808401805461ffff19169055600584018290556006840182905560078401805460ff191690556008840180548382559083526020909220610e06929091028101905b80821115610f2057600080825560018201818155600283019190915560039091018054600160a060020a0319169055610ebe565b601f016020900490600052602060002090810190610e7091905b80821115610f205760008155600101610f0c565b5090565b82800160010185558215610dfa579182015b82811115610dfa578251826000505591602001919060010190610f36565b50508787866040518084600160a060020a0316606060020a0281526014018381526020018280519060200190808383829060006004602084601f0104600f02600301f150905001935050505060405180910390208160050160005081905550834201816003016000508190555060018160040160006101000a81548160ff02191690830217905550828160070160006101000a81548160ff02191690830217905550821561103a5760088101805460018101808355909190828015829011611035576004028160040283600052602060002091820191016110359190610ebe565b505050505b600d8082018054600160a060020a031916331790553460068301819055815401905560408051600160a060020a038a16815260208181018a9052918101859052608060608201818152895191830191909152885185937f5790de2c279e58269b93b12828f56fd5f2bc8ad15e61ce08572585c81a38756f938d938d938a938e93929160a084019185810191908190849082908590600090600490601f850104600f02600301f150905090810190601f16801561110a5780820380516001836020036101000a031916815260200191505b509550505050505060405180910390a2509695505050505050565b6000805487908110156100025750808052600e8702600080516020612a5d83398151915201905090508484846040518084600160a060020a0316606060020a0281526014018381526020018280519060200190808383829060006004602084601f0104600f02600301f15090500193505050506040518091039020816005016000505414915050949350505050565b600014156111c157610002565b60003411156111cf57610002565b6000805485908110156100025750600160a060020a0333168152600e85027f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e56e8101602052604090912054600080516020612a5d83398151915291909101915060ff16806112485750600c810160205260406000205460ff165b80611257575060038101544210155b1561126157610002565b82156112a757600160a060020a0333166000908152601460209081526040808320546009850180549091019055600b84019091529020805460ff191660011790556112e3565b600160a060020a033316600090815260146020908152604080832054600a850180549091019055600c84019091529020805460ff191660011790555b600160a060020a0333166000908152600b6020526040812054141561130f576040600020849055611383565b600160a060020a0333166000908152600b60205260408120548154811015610002579080527f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e566600e90910201546003820154111561138357600160a060020a0333166000908152600b602052604090208490555b604080518481529051600160a060020a0333169186917f86abfce99b7dd908bec0169288797f85049ec73cbe046ed9de818fab3a497ae09181900360200190a35092915050565b6040805186815260208101839052815189927fdfc78bdca8e3e0b18c16c5c99323c6cb9eb5e00afde190b4e7273f5158702b07928290030190a25b5050505092915050565b6000805488908110156100025750808052600e8802600080516020612a5d833981519152019050600781015490945060ff1661144e57620d2f00611453565b622398805b600485015490935060ff16801561146f57506003840154830142115b1561147d5761151f8761152e565b60038401544210806114945750600484015460ff16155b8061151557508360000160009054906101000a9004600160a060020a03168460010160005054876040518084600160a060020a0316606060020a0281526014018381526020018280519060200190808383829060006004602084601f0104600f02600301f15090500193505050506040518091039020846005016000505414155b15610c0e57610002565b611405565b426002555b6113ca875b6000600060005082815481101561000257908052600e02600080516020612a5d833981519152018150600481015490915060ff161561157557600d80546006830154900390555b600401805460ff1916905550565b1580156115945750600484015460ff165b156115a2576115ae8761152e565b600191506115df6105cd565b604051600d8501546006860154600160a060020a0391909116916000919082818181858883f1935050505050611405565b600185015411156115ef57600091505b50600a8301546009840154865191019060049010801590611634575085600081518110156100025790602001015160f860020a900460f860020a02606860f860020a02145b8015611664575085600181518110156100025790602001015160f860020a900460f860020a02603760f860020a02145b8015611694575085600281518110156100025790602001015160f860020a900460f860020a0260ff60f860020a02145b80156116c4575085600381518110156100025790602001015160f860020a900460f860020a02601e60f860020a02145b80156116f3575030600160a060020a03166000908152600560205260409020546116f09061170b6105cd565b81105b156116fd57600091505b600184015461172e9061170d565b015b30600160a060020a03166000908152600560205260408120546128aa6105cd565b811015801561174557506009840154600a85015490115b801561174e5750815b1561178957604051600d8501546006860154600160a060020a0391909116916000919082818181858883f19350505050151561179757610002565b60018401546118709061170d565b42600255604051600185015485548851600160a060020a03919091169289918190602084810191908190849082908590600090600490601f850104600f02600301f150905090810190601f1680156118035780820380516001836020036101000a031916815260200191505b5091505060006040518083038185876185025a03f192505050151561182757610002565b60048401805461ff0019166101001790556001848101805430600160a060020a031660009081526005602052604090208054919091019055546006805490910190559450611529565b811015801561188757506009840154600a85015410155b80611890575081155b1561152957604051600d8501546006860154600160a060020a0391909116916000919082818181858883f19350505050151561152457610002565b6118d43361073a565b600014156118e157610002565b60008054889081101561000257508052600e87027f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e566810154600080516020612a5d83398151915291909101945042108061194357506003840154622398800142115b8061195c57508354600160a060020a0390811690871614155b8061196c5750600784015460ff16155b806119925750600160a060020a0333166000908152600b8501602052604090205460ff16155b806119b55750600160a060020a0333166000908152600b60205260409020548714155b156119bf57610002565b600884018054600090811015610002579081526020812060030154600160a060020a03161415611b2b57611c1586604051600090600160a060020a038316907f9046fefd66f538ab35263248a44217dcb70e2eb2cd136629e141b8b8f9f03b60908390a260408051600e547fe2faf044000000000000000000000000000000000000000000000000000000008252600160a060020a03858116600484015260248301859052604483018590526223988042016064840152925192169163e2faf04491608480820192602092909190829003018187876161da5a03f1156100025750506040515191506107549050565b6008850180546000908110156100025781815260208082209390935530600160a060020a031681526005909252604082205481549092908110156100025790815260208120905060020155601654600885018054600090811015610002579081526020812090506001015560048401805461ff0019166101001790555b60088401805460009081101561000257815482825260208220600101549291908110156100025790815260208120905054600160a060020a033316600090815260146020526040812054600888018054939091029390930495509081101561000257908152602081209050604080516003909201547fbaac5300000000000000000000000000000000000000000000000000000000008352600160a060020a033381166004850152915191169163baac5300918691602480820192602092909190829003018185886185025a03f11561000257505060405151600014159150611c91905057610002565b60088501805460009081101561000257818152602081206003018054600160a060020a03191690931790925580549091908110156100025790815260208120905060030154600160a060020a031660001415611c7057610002565b600d5430600160a060020a0316311015611c8957610002565b611aae6105cd565b60088401805460009081101561000257815482825260208220600101549291908110156100025790815260208120905060020154600160a060020a0333811660009081526014602090815260408083205430909416835260058083528184205460099093529083205460088b018054969095029690960497509487020494508593929091908290811015610002575260208120815060030154600160a060020a03908116825260208281019390935260409182016000908120805490950190945530168352600590915290205482901015611d6b57610002565b30600160a060020a031660009081526005602052604081208054849003905560088501805483926009929091829081101561000257508152602080822060030154600160a060020a0390811683529290526040808220805494909401909355309091168152205481901015611ddf57610002565b30600160a060020a039081166000908152600960209081526040808320805486900390553393909316808352601482528383205484519081529351929390927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929181900390910190a3611e5233610925565b50600160a060020a0333166000908152601460209081526040808320805460168054919091039055839055600a90915281205560019450611405565b30600160a060020a03908116600081815260056020908152604080832080549587168085528285208054979097019096558484528390556009909152808220805494835290822080549490940190935590815290555b50565b604051600160a060020a0382811691309091163190600081818185876185025a03f1925050501515611e8e57610002565b600160a060020a0333818116600090815260096020908152604080832054815160065460085460e060020a63d2cc718f028352935196995091969195929091169363d2cc718f93600483810194919391929183900301908290876161da5a03f11561000257505050604051805190602001506005600050600033600160a060020a031681526020019081526020016000206000505402041015611fba57610002565b600160a060020a03338116600090815260096020908152604080832054815160065460085460e060020a63d2cc718f02835293519296909593169363d2cc718f93600483810194929383900301908290876161da5a03f11561000257505050604051805190602001506005600050600033600160a060020a03168152602001908152602001600020600050540204039050831561210957600860009054906101000a9004600160a060020a0316600160a060020a0316630221038a83600160a060020a0316630e7082036040518160e060020a0281526004018090506020604051808303816000876161da5a03f11561000257505060408051805160e160020a63011081c5028252600160a060020a031660048201526024810186905290516044808301935060209282900301816000876161da5a03f115610002575050604051511515905061217157610002565b6040805160085460e160020a63011081c5028252600160a060020a038581166004840152602483018590529251921691630221038a9160448082019260209290919082900301816000876161da5a03f115610002575050604051511515905061217157610002565b600160a060020a03331660009081526009602052604090208054909101905550600192915050565b610a6733610925565b155b80156121bf57506121bf3384845b6000600061283b8561073a565b80156121db57506121db8383600060003411156128cc57610002565b156121e857506001610458565b610002565b15156121f857610002565b612202838361083a565b9050610458565b155b801561221d575061221d8484846121b2565b801561223a575061223a8484846000600034111561297157610002565b156121e85750600161224a565b90505b9392505050565b151561225c57610002565b61224784848461059a565b30600160a060020a031633600160a060020a03161415806122ac575030600160a060020a03166000908152600560205260409020546064906122a76105cd565b010481115b156122b657610002565b600c55565b600354600160a060020a039081163391909116146122d857610002565b600160a060020a038316600081815260046020908152604091829020805460ff191686179055815185815291517f73ad2a153c8b67991df9459024950b318a609782cee8c7eeda47b905f9baa91f9281900390910190a2506001610458565b506000610a6a565b600160a060020a0383166000908152600b6020526040812054815481101561000257818052600e02600080516020612a5d83398151915201905060038101549091504211156123aa57600160a060020a0383166000908152600b6020526040812081905591506123af565b600191505b50919050565b604051601254601434908102939093049350600160a060020a03169183900390600081818185876185025a03f150505050600160a060020a038316600081815260146020908152604080832080548601905560168054860190556013825291829020805434019055815184815291517fdbccb92686efceafb9bb7e0394df7f58f71b954061b81afb57109bf247d3d75a9281900390910190a260105460165410801590612465575060115460ff16155b156123aa576011805460ff1916600117905560165460408051918252517ff381a3e2428fdda36615919e8d9c35878d9eb0cf85ac6edf575088e80e4c147e9181900360200190a1600191506123af565b600f54421180156124c9575060115460ff16155b15612675576040805160125460e060020a63d2cc718f0282529151600160a060020a039290921691630221038a913091849163d2cc718f91600480830192602092919082900301816000876161da5a03f11561000257505060408051805160e160020a63011081c5028252600160a060020a039490941660048201526024810193909352516044838101936020935082900301816000876161da5a03f11561000257505060408051600160a060020a03331660008181526013602052928320549093509181818185876185025a03f192505050156126755760406000818120600160a060020a0333169182905260136020908152835191548252925191927fbb28353e4598c3b9199101a66e0989549b659a59a54d2c27fbb183f1932c8e6d92918290030190a26014600050600033600160a060020a0316815260200190815260200160002060005054601660008282825054039250508190555060006014600050600033600160a060020a031681526020019081526020016000206000508190555060006013600050600033600160a060020a03168152602001908152602001600020600050819055505b565b4262054600600f600050540311156126a5576201518062127500600f60005054034203046014019050610a6a565b50601e610a6a565b600160a060020a038381166000908152600a6020908152604080832054601654600754835160e060020a63d2cc718f02815293519296919591169363d2cc718f9360048181019492939183900301908290876161da5a03f11561000257505060405151905061271b8661073a565b0204101561272857610002565b600160a060020a038381166000908152600a6020908152604080832054601654600754835160e060020a63d2cc718f02815293519296919591169363d2cc718f9360048181019492939183900301908290876161da5a03f1156100025750506040515190506127968661073a565b0204039050600760009054906101000a9004600160a060020a0316600160a060020a0316630221038a84836040518360e060020a0281526004018083600160a060020a03168152602001828152602001925050506020604051808303816000876161da5a03f115610002575050604051511515905061281457610002565b600160a060020a0383166000908152600a60205260409020805482019055600191506123af565b600160a060020a0386166000908152600a602052604090205480850291909104915081111561286957610002565b600160a060020a038581166000908152600a60205260408082208054859003905591861681522080548201905560019150509392505050565b506000610754565b0160030260166000505483020460016000505460166000505404019050610754565b600160a060020a0333166000908152601460205260409020548290108015906128f55750600082115b1561296957600160a060020a03338116600081815260146020908152604080832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a3506001610458565b506000610458565b600160a060020a0384166000908152601460205260409020548290108015906129ba57506015602090815260406000818120600160a060020a0333168252909252902054829010155b80156129c65750600082115b15612a5557600160a060020a0383811660008181526014602090815260408083208054880190558885168084528184208054899003905560158352818420339690961684529482529182902080548790039055815186815291519293927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a350600161224a565b50600061224a56290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563") + +// EVM deploy bytecode of the DAO to simulate blocking. +var daoDeployCode = common.FromHex("606060405260405160c0806132c88339610120604052905160805160a051925160e0516101005193949293828282600f829055601083905560118054610100830261010060a860020a031990911617905560405130906001906101bc8061033e8339600160a060020a03909316908301526101408201526040519081900361016001906000f060128054600160a060020a031916919091179055505060038054600160a060020a03199081168917909155600e80549091168717905550600c84905560405130906000906101bc806104fa8339018083600160a060020a0316815260200182815260200192505050604051809103906000f0600760006101000a815481600160a060020a03021916908302179055503060006040516101bc806106b68339018083600160a060020a0316815260200182815260200192505050604051809103906000f060088054600160a060020a031916919091179055600754600160a060020a03166000141561017557610002565b600854600160a060020a03166000141561018e57610002565b426002556005600190815560008054828255829080158290116101ca57600e0281600e0283600052602060002091820191016101ca9190610245565b50505030600160a060020a03908116600090815260046020526040808220805460ff19908116600190811790925560035490941683529120805490921617905550505050505050612a56806108726000396000f35b5050600060098201819055600a820155600d81018054600160a060020a03191690556001015b8082111561033a578054600160a060020a03191681556000600182810182905560028381018054848255909281161561010002600019011604601f81901061030c57505b506000600383018190556004838101805461ffff19169055600584018290556006840182905560078401805460ff19169055600884018054838255908352602090922061021f929091028101905b8082111561033a5760008082556001820181815560028301919091556003919091018054600160a060020a03191690556102d7565b601f01602090049060005260206000209081019061028991905b8082111561033a5760008155600101610326565b50905660606040818152806101bc833960a090525160805160008054600160a060020a03191690921760a060020a60ff0219167401000000000000000000000000000000000000000090910217815561016290819061005a90396000f3606060405236156100405760e060020a60003504630221038a811461004d57806318bdc79a146100aa5780638da5cb5b146100be578063d2cc718f146100d0575b6100d96001805434019055565b6100db6004356024356000805433600160a060020a0390811691161415806100755750600034115b806100a05750805460a060020a900460ff1680156100a057508054600160a060020a03848116911614155b156100f757610002565b6100db60005460ff60a060020a9091041681565b6100ed600054600160a060020a031681565b6100db60015481565b005b60408051918252519081900360200190f35b6060908152602090f35b600160a060020a0383168260608381818185876185025a03f1925050501561015c57604080518381529051600160a060020a038516917f9735b0cb909f3d21d5c16bbcccd272d85fa11446f6d679f6ecb170d2dabfecfc919081900360200190a25060015b929150505660606040818152806101bc833960a090525160805160008054600160a060020a03191690921760a060020a60ff0219167401000000000000000000000000000000000000000090910217815561016290819061005a90396000f3606060405236156100405760e060020a60003504630221038a811461004d57806318bdc79a146100aa5780638da5cb5b146100be578063d2cc718f146100d0575b6100d96001805434019055565b6100db6004356024356000805433600160a060020a0390811691161415806100755750600034115b806100a05750805460a060020a900460ff1680156100a057508054600160a060020a03848116911614155b156100f757610002565b6100db60005460ff60a060020a9091041681565b6100ed600054600160a060020a031681565b6100db60015481565b005b60408051918252519081900360200190f35b6060908152602090f35b600160a060020a0383168260608381818185876185025a03f1925050501561015c57604080518381529051600160a060020a038516917f9735b0cb909f3d21d5c16bbcccd272d85fa11446f6d679f6ecb170d2dabfecfc919081900360200190a25060015b929150505660606040818152806101bc833960a090525160805160008054600160a060020a03191690921760a060020a60ff0219167401000000000000000000000000000000000000000090910217815561016290819061005a90396000f3606060405236156100405760e060020a60003504630221038a811461004d57806318bdc79a146100aa5780638da5cb5b146100be578063d2cc718f146100d0575b6100d96001805434019055565b6100db6004356024356000805433600160a060020a0390811691161415806100755750600034115b806100a05750805460a060020a900460ff1680156100a057508054600160a060020a03848116911614155b156100f757610002565b6100db60005460ff60a060020a9091041681565b6100ed600054600160a060020a031681565b6100db60015481565b005b60408051918252519081900360200190f35b6060908152602090f35b600160a060020a0383168260608381818185876185025a03f1925050501561015c57604080518381529051600160a060020a038516917f9735b0cb909f3d21d5c16bbcccd272d85fa11446f6d679f6ecb170d2dabfecfc919081900360200190a25060015b92915050566060604052361561020e5760e060020a6000350463013cf08b8114610247578063095ea7b3146102d05780630c3b7b96146103455780630e7082031461034e578063149acf9a1461036057806318160ddd146103725780631f2dc5ef1461037b57806321b5b8dd1461039b578063237e9492146103ad57806323b872dd1461040e5780632632bf2014610441578063341458081461047257806339d1f9081461047b5780634b6753bc146104935780634df6d6cc1461049c5780634e10c3ee146104b7578063590e1ae3146104ca578063612e45a3146104db578063643f7cdd1461057a578063674ed066146105925780636837ff1e1461059b57806370a08231146105e5578063749f98891461060b57806378524b2e1461062457806381f03fcb1461067e57806382661dc41461069657806382bf6464146106b75780638b15a605146106c95780638d7af473146106d257806396d7f3f5146106e1578063a1da2fb9146106ea578063a3912ec814610704578063a9059cbb1461070f578063b7bc2c841461073f578063baac53001461074b578063be7c29c1146107b1578063c9d27afe14610817578063cc9ae3f61461082d578063cdef91d014610841578063dbde198814610859578063dd62ed3e1461087e578063e33734fd146108b2578063e5962195146108c6578063e66f53b7146108de578063eceb2945146108f0578063f8c80d261461094f575b610966600f546000906234bc000142108015610239575060125433600160a060020a03908116911614155b156109785761098033610752565b6109866004356000805482908110156100025750808052600e8202600080516020612a3683398151915201905060038101546004820154600683015460018401548454600786015460058701546009880154600a890154600d8a0154600160a060020a039586169b509599600201989760ff81811698610100909204811697949691951693168c565b61096660043560243533600160a060020a03908116600081815260156020908152604080832094871680845294825280832086905580518681529051929493927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a35060015b92915050565b61096660105481565b610a7d600754600160a060020a031681565b610a7d600e54600160a060020a031681565b61096660165481565b6109665b60004262127500600f60005054031115610de557506014610983565b610a7d601254600160a060020a031681565b60408051602060248035600481810135601f810185900485028601850190965285855261096695813595919460449492939092019181908401838280828437509496505050505050506000600060006000600060003411156116a857610002565b6109666004356024356044355b60115460009060ff1680156104315750600f5442115b80156124e957506124e78461044b565b6109666000610980335b600160a060020a0381166000908152600b602052604081205481908114156129cb57610b99565b61096660065481565b6109665b600d5430600160a060020a03163103610983565b610966600f5481565b61096660043560046020526000908152604090205460ff1681565b61096660043560243560006124cb610831565b610a9a6000341115610ba457610002565b604080516020604435600481810135601f8101849004840285018401909552848452610966948135946024803595939460649492939101918190840183828082843750506040805160209735808a0135601f81018a90048a0283018a01909352828252969897608497919650602491909101945090925082915084018382808284375094965050933593505060a435915050600060006110c1336105ec565b61096660043560096020526000908152604090205481565b61096660015481565b610a9a60043530600160a060020a031633600160a060020a03161415806105db5750600160a060020a03811660009081526004602052604090205460ff16155b156121cb576121c8565b6109666004355b600160a060020a0381166000908152601460205260409020545b919050565b6109666004356024356000600034111561259957610002565b610966600062e6b680420360026000505410806106505750600354600160a060020a0390811633909116145b80156106645750600254621274ff19420190105b156126145750426002908155600180549091028155610983565b610966600435600a6020526000908152604090205481565b610966600435602435600060006000600060006000341115611ba157610002565b610a7d600854600160a060020a031681565b610966600c5481565b61096660005460001901610983565b61096660025481565b61096660043560006000600060003411156121fc57610002565b6109665b6001610983565b6109666004356024355b60115460009060ff16801561072f5750600f5442115b801561248757506124853361044b565b61096660115460ff1681565b6109666004355b60006000600f600050544210801561076a5750600034115b80156107a457506011546101009004600160a060020a0316600014806107a457506011546101009004600160a060020a0390811633909116145b15610b9f57610a9c61037f565b610a7d600435600060006000508281548110156100025750508080527f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e56b600e83020180548290811015610002575081526020902060030154600160a060020a0316610606565b61096660043560243560006000610e1b336105ec565b6109665b6000600034111561247c57610002565b61096660043560056020526000908152604090205481565b610966600435602435604435600061252f845b6000600060003411156127ac57610002565b610966600435602435600160a060020a0382811660009081526015602090815260408083209385168352929052205461033f565b610a9a600435600034111561254557610002565b610966600435600b6020526000908152604090205481565b610a7d600354600160a060020a031681565b604080516020606435600481810135601f81018490048402850184019095528484526109669481359460248035956044359560849492019190819084018382808284375094965050505050505060006000600034111561103257610002565b610a7d6011546101009004600160a060020a031681565b60408051918252519081900360200190f35b610980610708565b90505b90565b604051808d600160a060020a031681526020018c8152602001806020018b81526020018a815260200189815260200188815260200187815260200186815260200185815260200184815260200183600160a060020a0316815260200182810382528c818154600181600116156101000203166002900481526020019150805460018160011615610100020316600290048015610a635780601f10610a3857610100808354040283529160200191610a63565b820191906000526020600020905b815481529060010190602001808311610a4657829003601f168201915b50509d505050505050505050505050505060405180910390f35b60408051600160a060020a03929092168252519081900360200190f35b005b604051601254601434908102939093049350600160a060020a03169183900390600081818185876185025a03f150505050600160a060020a038316600081815260146020908152604080832080548601905560168054860190556013825291829020805434019055815184815291517fdbccb92686efceafb9bb7e0394df7f58f71b954061b81afb57109bf247d3d75a9281900390910190a260105460165410801590610b4c575060115460ff16155b15610b94576011805460ff1916600117905560165460408051918252517ff381a3e2428fdda36615919e8d9c35878d9eb0cf85ac6edf575088e80e4c147e9181900360200190a15b600191505b50919050565b610002565b600f5442118015610bb8575060115460ff16155b15610de357601260009054906101000a9004600160a060020a0316600160a060020a031663d2cc718f6040518160e060020a0281526004018090506020604051808303816000876161da5a03f1156100025750506040516012549051600160a060020a039190911631109050610cc9576040805160125460e060020a63d2cc718f0282529151600160a060020a039290921691630221038a913091849163d2cc718f91600482810192602092919082900301816000876161da5a03f11561000257505060408051805160e160020a63011081c5028252600160a060020a039490941660048201526024810193909352516044838101936020935082900301816000876161da5a03f115610002575050505b33600160a060020a0316600081815260136020526040808220549051909181818185876185025a03f19250505015610de35733600160a060020a03167fbb28353e4598c3b9199101a66e0989549b659a59a54d2c27fbb183f1932c8e6d6013600050600033600160a060020a03168152602001908152602001600020600050546040518082815260200191505060405180910390a26014600050600033600160a060020a0316815260200190815260200160002060005054601660008282825054039250508190555060006014600050600033600160a060020a031681526020019081526020016000206000508190555060006013600050600033600160a060020a03168152602001908152602001600020600050819055505b565b4262054600600f60005054031115610e13576201518062127500600f60005054034203046014019050610983565b50601e610983565b60001415610e2857610002565b6000341115610e3657610002565b6000805485908110156100025750600160a060020a03331681527f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e56e600e8602908101602052604090912054600080516020612a3683398151915291909101915060ff1680610eb05750600c810160205260406000205460ff165b80610ebf575060038101544210155b15610ec957610002565b8215610f0f5733600160a060020a03166000908152601460209081526040808320546009850180549091019055600b84019091529020805460ff19166001179055610f4b565b33600160a060020a0316600090815260146020908152604080832054600a850180549091019055600c84019091529020805460ff191660011790555b33600160a060020a03166000908152600b60205260408120541415610f77576040600020849055610feb565b33600160a060020a03166000908152600b60205260408120548154811015610002579080527f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e566600e909102015460038201541115610feb5733600160a060020a03166000908152600b602052604090208490555b60408051848152905133600160a060020a03169186917f86abfce99b7dd908bec0169288797f85049ec73cbe046ed9de818fab3a497ae09181900360200190a35092915050565b6000805487908110156100025750808052600e8702600080516020612a3683398151915201905090508484846040518084600160a060020a0316606060020a0281526014018381526020018280519060200190808383829060006004602084601f0104600f02600301f15090500193505050506040518091039020816005016000505414915050949350505050565b600014156110ce57610002565b82801561111857508660001415806110e857508451600014155b806111005750600354600160a060020a038981169116145b8061110b5750600034115b80611118575062093a8084105b1561112257610002565b8215801561114257506111348861115c565b158061114257506212750084105b156111fe57610002565b83546118e590600160a060020a03165b600160a060020a03811660009081526004602052604081205460ff16806111f15750601254600160a060020a039081169083161480156111f15750601260009054906101000a9004600160a060020a0316600160a060020a031663d2cc718f6040518160e060020a0281526004018090506020604051808303816000876161da5a03f115610002575050604051516006541190505b156129a157506001610606565b6249d40084111561120e57610002565b60115460ff1615806112215750600f5442105b806112365750600c5434108015611236575082155b1561124057610002565b42844201101561124f57610002565b30600160a060020a031633600160a060020a0316141561126e57610002565b60008054600181018083559091908280158290116112a557600e0281600e0283600052602060002091820191016112a5919061136a565b505060008054929450918491508110156100025750808052600e8302600080516020612a368339815191520190508054600160a060020a031916891781556001818101899055875160028084018054600082815260209081902096975091959481161561010002600019011691909104601f908101829004840193918b019083901061146257805160ff19168380011785555b5061149292915061144a565b5050600060098201819055600a820155600d81018054600160a060020a03191690556001015b8082111561145e578054600160a060020a03191681556000600182810182905560028084018054848255909281161561010002600019011604601f81901061143057505b506000600383018190556004808401805461ffff19169055600584018290556006840182905560078401805460ff191690556008840180548382559083526020909220611344929091028101905b8082111561145e57600080825560018201818155600283019190915560039091018054600160a060020a03191690556113fc565b601f0160209004906000526020600020908101906113ae91905b8082111561145e576000815560010161144a565b5090565b82800160010185558215611338579182015b82811115611338578251826000505591602001919060010190611474565b50508787866040518084600160a060020a0316606060020a0281526014018381526020018280519060200190808383829060006004602084601f0104600f02600301f150905001935050505060405180910390208160050160005081905550834201816003016000508190555060018160040160006101000a81548160ff02191690830217905550828160070160006101000a81548160ff02191690830217905550821561157857600881018054600181018083559091908280158290116115735760040281600402836000526020600020918201910161157391906113fc565b505050505b600d8082018054600160a060020a031916331790553460068301819055815401905560408051600160a060020a038a16815260208181018a9052918101859052608060608201818152895191830191909152885185937f5790de2c279e58269b93b12828f56fd5f2bc8ad15e61ce08572585c81a38756f938d938d938a938e93929160a084019185810191908190849082908590600090600490601f850104600f02600301f150905090810190601f1680156116485780820380516001836020036101000a031916815260200191505b509550505050505060405180910390a2509695505050505050565b6040805186815260208101839052815189927fdfc78bdca8e3e0b18c16c5c99323c6cb9eb5e00afde190b4e7273f5158702b07928290030190a25b5050505092915050565b6000805488908110156100025750808052600e8802600080516020612a36833981519152019050600781015490945060ff166116e757620d2f006116ec565b622398805b600485015490935060ff16801561170857506003840154830142115b15611716576117b887611890565b600384015442108061172d5750600484015460ff16155b806117ae57508360000160009054906101000a9004600160a060020a03168460010160005054876040518084600160a060020a0316606060020a0281526014018381526020018280519060200190808383829060006004602084601f0104600f02600301f15090500193505050506040518091039020846005016000505414155b1561114c57610002565b61169e565b60048401805461ff001916610100179055835460019550600160a060020a03908116309091161480159061180157508354600754600160a060020a03908116911614155b801561181d57506008548454600160a060020a03908116911614155b801561183957508354601254600160a060020a03908116911614155b801561185557506003548454600160a060020a03908116911614155b1561188b5760018401805430600160a060020a031660009081526005602052604090208054919091019055546006805490910190555b611663875b6000600060005082815481101561000257908052600e02600080516020612a36833981519152018150600481015490915060ff16156118d757600d80546006830154900390555b600401805460ff1916905550565b15156118f45761190087611890565b6001915061193161047f565b604051600d8501546006860154600160a060020a0391909116916000919082818181858883f193505050505061169e565b6001850154111561194157600091505b50600a8301546009840154865191019060049010801590611986575085600081518110156100025790602001015160f860020a900460f860020a02606860f860020a02145b80156119b6575085600181518110156100025790602001015160f860020a900460f860020a02603760f860020a02145b80156119e6575085600281518110156100025790602001015160f860020a900460f860020a0260ff60f860020a02145b8015611a16575085600381518110156100025790602001015160f860020a900460f860020a02601e60f860020a02145b8015611a45575030600160a060020a0316600090815260056020526040902054611a4290611a5d61047f565b81105b15611a4f57600091505b6001840154611a8090611a5f565b015b30600160a060020a03166000908152600560205260408120546129a961047f565b8110611ad457604051600d8501546006860154600160a060020a0391909116916000919082818181858883f193505050501515611abc57610002565b4260025560165460059004811115611ad45760056001555b6001840154611ae290611a5f565b8110158015611af85750600a8401546009850154115b8015611b015750815b1561188b578360000160009054906101000a9004600160a060020a0316600160a060020a0316846001016000505487604051808280519060200190808383829060006004602084601f0104600f02600301f150905090810190601f168015611b7d5780820380516001836020036101000a031916815260200191505b5091505060006040518083038185876185025a03f19250505015156117bd57610002565b611baa336105ec565b60001415611bb757610002565b60008054889081101561000257508052600e87027f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e566810154600080516020612a36833981519152919091019450421080611c1957506003840154622398800142115b80611c3257508354600160a060020a0390811690871614155b80611c425750600784015460ff16155b80611c68575033600160a060020a03166000908152600b8501602052604090205460ff16155b80611c9c575033600160a060020a03166000908152600b60205260409020548714801590611c9c5750604060009081205414155b15611ca657610002565b600884018054600090811015610002579081526020812060030154600160a060020a03161415611e1257611efc86604051600090600160a060020a038316907f9046fefd66f538ab35263248a44217dcb70e2eb2cd136629e141b8b8f9f03b60908390a260408051600e547fe2faf044000000000000000000000000000000000000000000000000000000008252600160a060020a03858116600484015260248301859052604483018590526223988042016064840152925192169163e2faf04491608480820192602092909190829003018187876161da5a03f1156100025750506040515191506106069050565b6008850180546000908110156100025781815260208082209390935530600160a060020a031681526005909252604082205481549092908110156100025790815260208120905060020155601654600885018054600090811015610002579081526020812090506001015560048401805461ff0019166101001790555b6008840180546000908110156100025781548282526020822060010154929190811015610002579081526020812090505433600160a060020a031660009081526014602052604081205460088801805493909102939093049550908110156100025790815260208120905060030154604080517fbaac530000000000000000000000000000000000000000000000000000000000815233600160a060020a0390811660048301529151929091169163baac53009186916024808301926020929190829003018185886185025a03f11561000257505060405151600014159150611f78905057610002565b60088501805460009081101561000257818152602081206003018054600160a060020a03191690931790925580549091908110156100025790815260208120905060030154600160a060020a031660001415611f5757610002565b600d5430600160a060020a0316311015611f7057610002565b611d9561047f565b6008840180546000908110156100025781548282526020822060010154929190811015610002579081526020812090506002015433600160a060020a0390811660009081526014602090815260408083205430909416835260058083528184205460099093529083205460088b018054969095029690960497509487020494508593929091908290811015610002575260208120815060030154600160a060020a0390811682526020828101939093526040918201600090812080549095019094553016835260059091529020548290101561205357610002565b30600160a060020a031660009081526005602052604081208054849003905560088501805483926009929091829081101561000257508152602080822060030154600160a060020a039081168352929052604080822080549094019093553090911681522054819010156120c657610002565b30600160a060020a0390811660009081526009602090815260408083208054869003905533909316808352601482528383205484519081529351929390927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929181900390910190a36121383361086c565b5033600160a060020a03166000908152601460209081526040808320805460168054919091039055839055600a9091528120556001945061169e565b30600160a060020a0390811660008181526005602090815260408083208054958716808552828520805490970190965584845283905560099091528082208054948352908220805490940190935590815290555b50565b604051600160a060020a0382811691309091163190600081818185876185025a03f192505050151561217457610002565b33600160a060020a03818116600090815260096020908152604080832054815160065460085460e060020a63d2cc718f028352935197995091969195929092169363d2cc718f936004848101949193929183900301908290876161da5a03f11561000257505050604051805190602001506005600050600033600160a060020a03168152602001908152602001600020600050540204101561229d57610002565b600160a060020a03338116600090815260096020908152604080832054815160065460085460e060020a63d2cc718f02835293519296909593169363d2cc718f93600483810194929383900301908290876161da5a03f11561000257505050604051805190602001506005600050600033600160a060020a0316815260200190815260200160002060005054020403905083156123ec57600860009054906101000a9004600160a060020a0316600160a060020a0316630221038a83600160a060020a0316630e7082036040518160e060020a0281526004018090506020604051808303816000876161da5a03f11561000257505060408051805160e160020a63011081c5028252600160a060020a031660048201526024810186905290516044808301935060209282900301816000876161da5a03f115610002575050604051511515905061245457610002565b6040805160085460e160020a63011081c5028252600160a060020a038581166004840152602483018590529251921691630221038a9160448082019260209290919082900301816000876161da5a03f115610002575050604051511515905061245457610002565b600160a060020a03331660009081526009602052604090208054909101905550600192915050565b6109803361086c565b155b80156124a257506124a23384845b6000600061293a856105ec565b80156124be57506124be83836000600034111561261c57610002565b15610b9f5750600161033f565b15156124d657610002565b6124e08383610719565b905061033f565b155b80156124fb57506124fb848484612495565b80156125185750612518848484600060003411156126c157610002565b15610b9f57506001612528565b90505b9392505050565b151561253a57610002565b61252584848461041b565b30600160a060020a031633600160a060020a031614158061258a575030600160a060020a031660009081526005602052604090205460649061258561047f565b010481115b1561259457610002565b600c55565b600354600160a060020a0390811633909116146125b557610002565b600160a060020a038316600081815260046020908152604091829020805460ff191686179055815185815291517f73ad2a153c8b67991df9459024950b318a609782cee8c7eeda47b905f9baa91f9281900390910190a250600161033f565b506000610983565b33600160a060020a03166000908152601460205260409020548290108015906126455750600082115b156126b957600160a060020a03338116600081815260146020908152604080832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a350600161033f565b50600061033f565b600160a060020a03841660009081526014602052604090205482901080159061270a5750601560209081526040600081812033600160a060020a03168252909252902054829010155b80156127165750600082115b156127a457600160a060020a03838116600081815260146020908152604080832080548801905588851680845281842080548990039055601583528184203390961684529482529182902080548790039055815186815291519293927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a3506001612528565b506000612528565b600160a060020a038381166000908152600a6020908152604080832054601654600754835160e060020a63d2cc718f02815293519296919591169363d2cc718f9360048181019492939183900301908290876161da5a03f11561000257505060405151905061281a866105ec565b0204101561282757610002565b600160a060020a038381166000908152600a6020908152604080832054601654600754835160e060020a63d2cc718f02815293519296919591169363d2cc718f9360048181019492939183900301908290876161da5a03f115610002575050604051519050612895866105ec565b0204039050600760009054906101000a9004600160a060020a0316600160a060020a0316630221038a84836040518360e060020a0281526004018083600160a060020a03168152602001828152602001925050506020604051808303816000876161da5a03f115610002575050604051511515905061291357610002565b600160a060020a0383166000908152600a6020526040902080548201905560019150610b99565b600160a060020a0386166000908152600a602052604090205480850291909104915081111561296857610002565b600160a060020a038581166000908152600a60205260408082208054859003905591861681522080548201905560019150509392505050565b506000610606565b0160030260166000505483020460016000505460166000505404019050610606565b600160a060020a0383166000908152600b6020526040812054815481101561000257818052600e02600080516020612a368339815191520190506003810154909150421115610b9457600160a060020a0383166000908152600b602052604081208190559150610b9956290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563") + +// Proxy contract to whitelist interaction with: +// +// contract Proxy { +// address _dao; +// +// function Proxy(address dao) { +// _dao = dao; +// } +// function() { +// if (msg.value > 0) { +// _dao.call.value(msg.value)(); +// } else { +// _dao.call(bytes4(sha3("refund()"))); +// } +// } +// } +var proxyDeployCode = common.FromHex("606060405260405160208060dd83395060806040525160008054600160a060020a031916821790555060a98060346000396000f360606040523615600a575b60486000341115604a576000805473ffffffffffffffffffffffffffffffffffffffff1690349060609081818185876185025a03f1925050505060a7565b005b600080547f590e1ae300000000000000000000000000000000000000000000000000000000606090815273ffffffffffffffffffffffffffffffffffffffff9091169163590e1ae3916064919060048183876161da5a03f1505050505b56") + +// Tests that unannimous votes are handled correctly (i.e. the simple case). +func TestDAOForkUnanimousFail(t *testing.T) { testDAOUnanimousFork(t, false) } +func TestDAOForkUnanimousPass(t *testing.T) { testDAOUnanimousFork(t, true) } + +func testDAOUnanimousFork(t *testing.T, pass bool) { + // Reduce the test size to avoid wasting too much time + defer func(old uint64) { ruptureBlock = old }(ruptureBlock) + ruptureBlock = 128 + + defer func(old int) { ruptureCacheLimit = old }(ruptureCacheLimit) + ruptureCacheLimit = 256 + + // Depending on the tested outcome, set a high or a low gas limit + defer func(old *big.Int) { params.GenesisGasLimit = old }(params.GenesisGasLimit) + defer func(old *big.Int) { params.TargetGasLimit = old }(params.TargetGasLimit) + if pass { + params.GenesisGasLimit = new(big.Int).Add(ruptureThreshold, big.NewInt(-10)) + params.TargetGasLimit = new(big.Int).Add(ruptureThreshold, big.NewInt(-10)) + } else { + params.GenesisGasLimit = new(big.Int).Add(ruptureThreshold, big.NewInt(10)) + params.TargetGasLimit = new(big.Int).Add(ruptureThreshold, big.NewInt(10)) + } + // Create a test chain with a DAO instance deployed and attempt to transact with it + var ( + slockit, _ = crypto.HexToECDSA("49a7b37aa6f6645917e7b807e9d1c00d4fa71f18343b0d4122a4d2df64dd6fee") + black, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291") + white, _ = crypto.HexToECDSA("8a1f9a8f95be41cd7ccb6168179afb4504aefe388d1e14474d32c45c72ce7b7a") + slockitAddr = crypto.PubkeyToAddress(slockit.PublicKey) + blackAddr = crypto.PubkeyToAddress(black.PublicKey) + whiteAddr = crypto.PubkeyToAddress(white.PublicKey) + creatorAddr common.Address + daoAddr common.Address + blackProxy common.Address + whiteProxy common.Address + db, _ = ethdb.NewMemDatabase() + ) + genesis := WriteGenesisBlockForTesting(db, + GenesisAccount{slockitAddr, big.NewInt(1000000)}, + GenesisAccount{blackAddr, big.NewInt(1000000)}, + GenesisAccount{whiteAddr, big.NewInt(1000000)}, + ) + length := int(ruptureBlock) + 2*ruptureCacheLimit + chain, _ := GenerateChain(genesis, db, length, func(i int, gen *BlockGen) { + switch i { + case 0: + // Deploy the DAO creator in the first block + tx, _ := types.NewContractCreation(gen.TxNonce(slockitAddr), big.NewInt(1), params.GenesisGasLimit, new(big.Int), creatorDeployCode).SignECDSA(slockit) + gen.AddTx(tx) + creatorAddr = crypto.CreateAddress(slockitAddr, tx.Nonce()) + + case 1: + // Deploy the DAO in the second block + var args []byte + args = append(args, common.LeftPadBytes(slockitAddr.Bytes(), 32)...) // curator + args = append(args, common.LeftPadBytes(creatorAddr.Bytes(), 32)...) // daoCreator + args = append(args, common.LeftPadBytes([]byte{0}, 32)...) // proposalDeposit + args = append(args, common.LeftPadBytes([]byte{100}, 32)...) // minTokensToCreate + args = append(args, common.LeftPadBytes([]byte{100}, 32)...) // closingTime + args = append(args, common.LeftPadBytes([]byte{0}, 32)...) // privateCreation + + tx, _ := types.NewContractCreation(gen.TxNonce(slockitAddr), big.NewInt(0), params.GenesisGasLimit, new(big.Int), append(daoDeployCode, args...)).SignECDSA(slockit) + gen.AddTx(tx) + daoAddr = crypto.CreateAddress(slockitAddr, tx.Nonce()) + + case 2: + // Deploy the black and white hat proxy contracts + tx, _ := types.NewContractCreation(gen.TxNonce(blackAddr), big.NewInt(1), big.NewInt(1000000), new(big.Int), append(proxyDeployCode, common.LeftPadBytes(daoAddr.Bytes(), 32)...)).SignECDSA(black) + gen.AddTx(tx) + blackProxy = crypto.CreateAddress(blackAddr, tx.Nonce()) + + tx, _ = types.NewContractCreation(gen.TxNonce(whiteAddr), big.NewInt(1), big.NewInt(1000000), new(big.Int), append(proxyDeployCode, common.LeftPadBytes(daoAddr.Bytes(), 32)...)).SignECDSA(white) + gen.AddTx(tx) + whiteProxy = crypto.CreateAddress(whiteAddr, tx.Nonce()) + + ruptureWhitelist[whiteProxy] = true + + case 3: + // Fund the DAO with some funds, but not enough for successful creation + tx, _ := types.NewTransaction(gen.TxNonce(whiteAddr), whiteProxy, big.NewInt(2), big.NewInt(1000000), nil, nil).SignECDSA(white) + gen.AddTx(tx) + + tx, _ = types.NewTransaction(gen.TxNonce(blackAddr), blackProxy, big.NewInt(2), big.NewInt(1000000), nil, nil).SignECDSA(black) + gen.AddTx(tx) + + case length - 2: + // DAO creation failed by this time and forks are in effect; try retrieving whitelisted funds + tx, _ := types.NewTransaction(gen.TxNonce(whiteAddr), whiteProxy, big.NewInt(0), big.NewInt(1000000), nil, nil).SignECDSA(white) + gen.AddTx(tx) + + case length - 1: + // DAO creation failed by this time and forks are in effect; try retrieving blacklisted funds + tx, _ := types.NewTransaction(gen.TxNonce(blackAddr), blackProxy, big.NewInt(0), big.NewInt(1000000), nil, nil).SignECDSA(black) + gen.AddTx(tx) + } + }) + defer delete(ruptureWhitelist, whiteProxy) // This can't be done in the aboge generator sadly + + // Import the chain. This runs all block validation rules. + bc, _ := NewBlockChain(db, MakeChainConfig(), FakePow{}, new(event.TypeMux)) + n, err := bc.InsertChain(chain) + + // The chain should either succeed (no votes), or fail on the black address + if !pass { + if err != nil { + t.Errorf("block %d rejected on non forked chain: %v", n, err) + } + } else { + if n != length-1 || err != blockedCodeHashErr { + t.Errorf("failure mismatch: have %d:%v, want %d:%v", n, err, length-1, blockedCodeHashErr) + } + } + // Verify account balances to make sure transactions executd properly, not just the test is bugged + state, _ := bc.State() + if state.GetBalance(whiteProxy).Cmp(big.NewInt(3)) != 0 { // 1 init + 2 refund + t.Errorf("white proxy balance mismatch: have %v, want 3", state.GetBalance(whiteProxy)) + } + if !pass { + if state.GetBalance(blackProxy).Cmp(big.NewInt(3)) != 0 { // 1 init + 2 refund (fork refused) + t.Errorf("black proxy balance mismatch: have %v, want 3", state.GetBalance(blackProxy)) + } + if state.GetBalance(daoAddr).Cmp(big.NewInt(0)) != 0 { // all refunded (fork refused) + t.Errorf("dao balance mismatch: have %v, want 0", state.GetBalance(daoAddr)) + } + } else { + if state.GetBalance(blackProxy).Cmp(big.NewInt(1)) != 0 { // 1 init (refund refused due to fork) + t.Errorf("black proxy balance mismatch: have %v, want 1", state.GetBalance(blackProxy)) + } + if state.GetBalance(daoAddr).Cmp(big.NewInt(2)) != 0 { // 2 from black (refund refused due to fork) + t.Errorf("dao balance mismatch: have %v, want 2", state.GetBalance(daoAddr)) + } + } +} + +// Tests the unique corner case where miners don't cleanly decide on the outcome +// of the vote, rather +func TestDAOForkRaceyResolution(t *testing.T) { + // Reduce the test size to avoid wasting too much time + defer func(old uint64) { ruptureBlock = old }(ruptureBlock) + ruptureBlock = 128 + + defer func(old int) { ruptureCacheLimit = old }(ruptureCacheLimit) + ruptureCacheLimit = 256 + + // Set up the parameters of the test chain + var ( + slockit, _ = crypto.HexToECDSA("49a7b37aa6f6645917e7b807e9d1c00d4fa71f18343b0d4122a4d2df64dd6fee") + black, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291") + white, _ = crypto.HexToECDSA("8a1f9a8f95be41cd7ccb6168179afb4504aefe388d1e14474d32c45c72ce7b7a") + slockitAddr = crypto.PubkeyToAddress(slockit.PublicKey) + blackAddr = crypto.PubkeyToAddress(black.PublicKey) + whiteAddr = crypto.PubkeyToAddress(white.PublicKey) + creatorAddr common.Address + daoAddr common.Address + blackProxy common.Address + whiteProxy common.Address + db, _ = ethdb.NewMemDatabase() + ) + defer func(old *big.Int) { params.GenesisGasLimit = old }(params.GenesisGasLimit) + params.GenesisGasLimit = ruptureThreshold + + genesis := WriteGenesisBlockForTesting(db, + GenesisAccount{slockitAddr, big.NewInt(1000000)}, + GenesisAccount{blackAddr, big.NewInt(1000000)}, + GenesisAccount{whiteAddr, big.NewInt(1000000)}, + ) + // Generate a chain where the outcome for the fork proposal is pass + defer func(old *big.Int) { params.TargetGasLimit = old }(params.TargetGasLimit) + params.TargetGasLimit = new(big.Int).Add(ruptureThreshold, big.NewInt(-10)) + + length := int(ruptureBlock) + 2*ruptureCacheLimit + chainPass, _ := GenerateChain(genesis, db, length, func(i int, gen *BlockGen) { + switch i { + case 0: + // Deploy the DAO creator in the first block + tx, _ := types.NewContractCreation(gen.TxNonce(slockitAddr), big.NewInt(1), big.NewInt(3999980), new(big.Int), creatorDeployCode).SignECDSA(slockit) + gen.AddTx(tx) + creatorAddr = crypto.CreateAddress(slockitAddr, tx.Nonce()) + + case 1: + // Deploy the DAO in the second block + var args []byte + args = append(args, common.LeftPadBytes(slockitAddr.Bytes(), 32)...) // curator + args = append(args, common.LeftPadBytes(creatorAddr.Bytes(), 32)...) // daoCreator + args = append(args, common.LeftPadBytes([]byte{0}, 32)...) // proposalDeposit + args = append(args, common.LeftPadBytes([]byte{100}, 32)...) // minTokensToCreate + args = append(args, common.LeftPadBytes([]byte{100}, 32)...) // closingTime + args = append(args, common.LeftPadBytes([]byte{0}, 32)...) // privateCreation + + tx, _ := types.NewContractCreation(gen.TxNonce(slockitAddr), big.NewInt(0), big.NewInt(3999980), new(big.Int), append(daoDeployCode, args...)).SignECDSA(slockit) + gen.AddTx(tx) + daoAddr = crypto.CreateAddress(slockitAddr, tx.Nonce()) + + case 2: + // Deploy the black and white hat proxy contracts + tx, _ := types.NewContractCreation(gen.TxNonce(blackAddr), big.NewInt(1), big.NewInt(1000000), new(big.Int), append(proxyDeployCode, common.LeftPadBytes(daoAddr.Bytes(), 32)...)).SignECDSA(black) + gen.AddTx(tx) + blackProxy = crypto.CreateAddress(blackAddr, tx.Nonce()) + + tx, _ = types.NewContractCreation(gen.TxNonce(whiteAddr), big.NewInt(1), big.NewInt(1000000), new(big.Int), append(proxyDeployCode, common.LeftPadBytes(daoAddr.Bytes(), 32)...)).SignECDSA(white) + gen.AddTx(tx) + whiteProxy = crypto.CreateAddress(whiteAddr, tx.Nonce()) + + ruptureWhitelist[whiteProxy] = true + + case 3: + // Fund the DAO with some funds, but not enough for successful creation + tx, _ := types.NewTransaction(gen.TxNonce(whiteAddr), whiteProxy, big.NewInt(2), big.NewInt(1000000), nil, nil).SignECDSA(white) + gen.AddTx(tx) + + tx, _ = types.NewTransaction(gen.TxNonce(blackAddr), blackProxy, big.NewInt(2), big.NewInt(1000000), nil, nil).SignECDSA(black) + gen.AddTx(tx) + + case length - 2: + // DAO creation failed by this time and forks are in effect; try retrieving whitelisted funds + tx, _ := types.NewTransaction(gen.TxNonce(whiteAddr), whiteProxy, big.NewInt(0), big.NewInt(1000000), nil, nil).SignECDSA(white) + gen.AddTx(tx) + + case length - 1: + // DAO creation failed by this time and forks are in effect; try retrieving blacklisted funds + tx, _ := types.NewTransaction(gen.TxNonce(blackAddr), blackProxy, big.NewInt(0), big.NewInt(1000000), nil, nil).SignECDSA(black) + gen.AddTx(tx) + } + }) + // Generate a chain to work around the last bad block above + chainPassCont, _ := GenerateChain(chainPass[len(chainPass)-2], db, 3, func(i int, gen *BlockGen) {}) + + // Generate a fork of the chain where the outcome of the fork proposal is fail + params.TargetGasLimit = new(big.Int).Add(ruptureThreshold, big.NewInt(10)) + chainFail, _ := GenerateChain(chainPass[4], db, length-4, func(i int, gen *BlockGen) { // Start fro block #4 to reuse previous creation code + switch i { + case length - 4 - 2: + // DAO creation failed by this time and forks are in effect; try retrieving whitelisted funds + tx, _ := types.NewTransaction(gen.TxNonce(whiteAddr), whiteProxy, big.NewInt(0), big.NewInt(1000000), nil, nil).SignECDSA(white) + gen.AddTx(tx) + + case length - 4 - 1: + // DAO creation failed by this time and forks are in effect; try retrieving blacklisted funds + tx, _ := types.NewTransaction(gen.TxNonce(blackAddr), blackProxy, big.NewInt(0), big.NewInt(1000000), nil, nil).SignECDSA(black) + gen.AddTx(tx) + } + }) + defer delete(ruptureWhitelist, whiteProxy) // This can't be done in the aboge generator sadly + + // Import the chain where the vote passed + bc, _ := NewBlockChain(db, MakeChainConfig(), FakePow{}, new(event.TypeMux)) + + if n, err := bc.InsertChain(chainPass); n != length-1 || err != blockedCodeHashErr { + t.Fatalf("forked chain error mismatch: have %v/%v, want %v/%v", n, err, length-1, blockedCodeHashErr) + } + state, _ := bc.State() + if state.GetBalance(whiteProxy).Cmp(big.NewInt(3)) != 0 { // 1 init + 2 refund + t.Errorf("white proxy balance mismatch: have %v, want 3", state.GetBalance(whiteProxy)) + } + if state.GetBalance(blackProxy).Cmp(big.NewInt(1)) != 0 { // 1 init (no refund on the passing chain) + t.Errorf("black proxy balance mismatch: have %v, want 1", state.GetBalance(blackProxy)) + } + if state.GetBalance(daoAddr).Cmp(big.NewInt(2)) != 0 { // 2 from black (refund refused due to fork) + t.Errorf("dao balance mismatch: have %v, want 2", state.GetBalance(daoAddr)) + } + // Import the chain where the vote failed (longer than the passing with 1 block (dropped from the passing)) + if _, err := bc.InsertChain(chainFail); err != nil { + t.Fatalf("failed to import non-forked chain: %v", err) + } + state, _ = bc.State() + if state.GetBalance(whiteProxy).Cmp(big.NewInt(3)) != 0 { // 1 init + 2 refund + t.Errorf("white proxy balance mismatch: have %v, want 3", state.GetBalance(whiteProxy)) + } + if state.GetBalance(blackProxy).Cmp(big.NewInt(3)) != 0 { // 1 init + 2 refund (fork refused) + t.Errorf("black proxy balance mismatch: have %v, want 3", state.GetBalance(blackProxy)) + } + if state.GetBalance(daoAddr).Cmp(big.NewInt(0)) != 0 { // all refunded (fork refused) + t.Errorf("dao balance mismatch: have %v, want 0", state.GetBalance(daoAddr)) + } + // Try to import a bad block on theforked chain to make sure no cache screwes up + if _, err := bc.InsertChain(chainPass[len(chainPass)-2:]); err != blockedCodeHashErr { + t.Fatalf("forked chain error mismatch: have %v, want %v", err, blockedCodeHashErr) + } + // The balances must still be that of the failed chain + state, _ = bc.State() + if state.GetBalance(whiteProxy).Cmp(big.NewInt(3)) != 0 { // 1 init + 2 refund + t.Errorf("white proxy balance mismatch: have %v, want 3", state.GetBalance(whiteProxy)) + } + if state.GetBalance(blackProxy).Cmp(big.NewInt(3)) != 0 { // 1 init + 2 refund (fork refused) + t.Errorf("black proxy balance mismatch: have %v, want 3", state.GetBalance(blackProxy)) + } + if state.GetBalance(daoAddr).Cmp(big.NewInt(0)) != 0 { // all refunded (fork refused) + t.Errorf("dao balance mismatch: have %v, want 0", state.GetBalance(daoAddr)) + } + // Overrule the passing chain with fresh blocks + if _, err := bc.InsertChain(chainPassCont); err != nil { + t.Fatalf("failed to import forked chain continuation: %v", err) + } + // Balances must be switched over to the forked version + state, _ = bc.State() + if state.GetBalance(whiteProxy).Cmp(big.NewInt(3)) != 0 { // 1 init + 2 refund + t.Errorf("white proxy balance mismatch: have %v, want 3", state.GetBalance(whiteProxy)) + } + if state.GetBalance(blackProxy).Cmp(big.NewInt(1)) != 0 { // 1 init (no refund on the passing chain) + t.Errorf("black proxy balance mismatch: have %v, want 1", state.GetBalance(blackProxy)) + } + if state.GetBalance(daoAddr).Cmp(big.NewInt(2)) != 0 { // 2 from black (refund refused due to fork) + t.Errorf("dao balance mismatch: have %v, want 2", state.GetBalance(daoAddr)) + } +} diff --git a/core/execution.go b/core/execution.go index ec04f61400..7f4c647586 100644 --- a/core/execution.go +++ b/core/execution.go @@ -149,6 +149,9 @@ func execDelegateCall(env vm.Environment, caller vm.ContractRef, originAddr, toA return nil, common.Address{}, vm.DepthError } + if value.Cmp(common.Big0) > 0 { + env.MarkCodeHash(env.Db().GetCodeHash(caller.Address())) + } snapshot := env.MakeSnapshot() var to vm.Account diff --git a/core/state_processor.go b/core/state_processor.go index 55c1301eb4..1e54eefa32 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -32,13 +32,20 @@ import ( var ( big8 = big.NewInt(8) big32 = big.NewInt(32) - illegalCodeHashErr = errors.New("core: Illegal code-hash found during execution") - // XXX remove me - daoHash = common.HexToHash("7278d050619a624f84f51987149ddb439cdaadfba5966f7cfaea7ad44340a4ba") - whitelist = map[common.Address]bool{ + blockedCodeHashErr = errors.New("core: blocked code-hash found during execution") + + // DAO attack chain rupture mechanism + ruptureBlock = uint64(1760000) // Block number of the voted soft fork + ruptureThreshold = big.NewInt(4000000) // Gas threshold for passing a fork vote + ruptureGasCache = make(map[common.Hash]*big.Int) // Amount of gas in the point of rupture + ruptureCodeHashes = map[common.Hash]struct{}{ + common.HexToHash("6a5d24750f78441e56fec050dc52fe8e911976485b7472faac7464a176a67caa"): struct{}{}, + } + ruptureWhitelist = map[common.Address]bool{ common.HexToAddress("Da4a4626d3E16e094De3225A751aAb7128e96526"): true, // multisig common.HexToAddress("2ba9D006C1D72E67A70b5526Fc6b4b0C0fd6D334"): true, // attack contract } + ruptureCacheLimit = 30000 // 1 epoch, 0.5 per possible fork ) // StateProcessor is a basic Processor, which takes care of transitioning @@ -101,14 +108,58 @@ func ApplyTransaction(config *ChainConfig, bc *BlockChain, gp *GasPool, statedb return nil, nil, nil, err } - for _, codeHash := range env.CodeHashes { - _, illegalHash := IllegalCodeHashes[codeHash] - to := tx.To() - if illegalHash && to != nil && !whitelist[*to] { - return nil, nil, nil, illegalCodeHashErr + // Check whether the DAO needs to be blocked or not + if bc != nil { // Test chain maker uses nil to construct the potential chain + blockRuptureCodes := false + + if number := header.Number.Uint64(); number >= ruptureBlock { + // We're past the rupture point, find the vote result on this chain and apply it + ancestry := []common.Hash{header.Hash(), header.ParentHash} + for _, ok := ruptureGasCache[ancestry[len(ancestry)-1]]; !ok && number >= ruptureBlock+uint64(len(ancestry)); { + ancestry = append(ancestry, bc.GetHeaderByHash(ancestry[len(ancestry)-1]).ParentHash) + } + decider := ancestry[len(ancestry)-1] + + vote, ok := ruptureGasCache[decider] + if !ok { + // We've reached the rupture point, retrieve the vote + vote = bc.GetHeaderByHash(decider).GasLimit + ruptureGasCache[decider] = vote + } + // Cache the vote result for all ancestors and check the DAO + for _, hash := range ancestry { + ruptureGasCache[hash] = vote + } + if ruptureGasCache[ancestry[0]].Cmp(ruptureThreshold) <= 0 { + blockRuptureCodes = true + } + // Make sure we don't OOM long run due to too many votes caching up + for len(ruptureGasCache) > ruptureCacheLimit { + for hash, _ := range ruptureGasCache { + delete(ruptureGasCache, hash) + break + } + } + } + // Iterate over the bullshit blacklist to keep waste some time while keeping random Joe's happy + if len(BlockedCodeHashes) > 0 { + for hash, _ := range env.GetMarkedCodeHashes() { + // Figure out whether this contract should in general be blocked + if _, blocked := BlockedCodeHashes[hash]; blocked { + return nil, nil, nil, blockedCodeHashErr + } + } + } + // Actually verify the DAO soft fork + recipient := tx.To() + if blockRuptureCodes && (recipient == nil || !ruptureWhitelist[*recipient]) { + for hash, _ := range env.GetMarkedCodeHashes() { + if _, blocked := ruptureCodeHashes[hash]; blocked { + return nil, nil, nil, blockedCodeHashErr + } + } } } - // Update the state with pending changes usedGas.Add(usedGas, gas) receipt := types.NewReceipt(statedb.IntermediateRoot().Bytes(), usedGas) diff --git a/core/vm_env.go b/core/vm_env.go index 1c11102802..4692c14c4b 100644 --- a/core/vm_env.go +++ b/core/vm_env.go @@ -25,7 +25,9 @@ import ( "github.com/ethereum/go-ethereum/core/vm" ) -var IllegalCodeHashes map[common.Hash]struct{} +// BlockedCodeHashes is a set of EVM code hashes that this node should block +// sending funds from. +var BlockedCodeHashes map[common.Hash]struct{} // GetHashFn returns a function for which the VM env can query block hashes through // up to the limit defined by the Yellow Paper and uses the given block chain @@ -49,7 +51,7 @@ type VMEnv struct { depth int // Current execution depth msg Message // Message appliod - CodeHashes []common.Hash // code hashes collected during execution + codeHashes map[common.Hash]struct{} // code hashes collected during execution header *types.Header // Header information chain *BlockChain // Blockchain handle @@ -60,6 +62,7 @@ type VMEnv struct { func NewEnv(state *state.StateDB, chainConfig *ChainConfig, chain *BlockChain, msg Message, header *types.Header, cfg vm.Config) *VMEnv { env := &VMEnv{ chainConfig: chainConfig, + codeHashes: make(map[common.Hash]struct{}), chain: chain, state: state, header: header, @@ -76,7 +79,8 @@ func NewEnv(state *state.StateDB, chainConfig *ChainConfig, chain *BlockChain, m return env } -func (self *VMEnv) MarkCodeHash(hash common.Hash) { self.CodeHashes = append(self.CodeHashes, hash) } +func (self *VMEnv) MarkCodeHash(hash common.Hash) { self.codeHashes[hash] = struct{}{} } +func (self *VMEnv) GetMarkedCodeHashes() map[common.Hash]struct{} { return self.codeHashes } func (self *VMEnv) RuleSet() vm.RuleSet { return self.chainConfig } func (self *VMEnv) Vm() vm.Vm { return self.evm } From ba784bdf36f2daf7827ec1ec864f3393ba8d86a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Thu, 23 Jun 2016 12:47:15 +0300 Subject: [PATCH 3/3] core: update DAO soft-fork number, clean up the code --- cmd/geth/main.go | 1 + cmd/geth/usage.go | 1 + cmd/utils/flags.go | 23 +++++++---------------- core/block_validator.go | 5 +++++ core/execution.go | 6 ++---- core/state/statedb.go | 2 -- core/state_processor.go | 27 +++++++++++---------------- core/vm/runtime/env.go | 24 +++++++++++------------- core/vm/runtime/runtime.go | 23 +++++++++++------------ core/vm_env.go | 4 ---- 10 files changed, 49 insertions(+), 67 deletions(-) diff --git a/cmd/geth/main.go b/cmd/geth/main.go index c372430f1c..95aad3beae 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -169,6 +169,7 @@ participating. utils.MiningGPUFlag, utils.AutoDAGFlag, utils.TargetGasLimitFlag, + utils.DAOSoftForkFlag, utils.NATFlag, utils.NatspecEnabledFlag, utils.NoDiscoverFlag, diff --git a/cmd/geth/usage.go b/cmd/geth/usage.go index e7ef9e2c7b..10bc56b97c 100644 --- a/cmd/geth/usage.go +++ b/cmd/geth/usage.go @@ -128,6 +128,7 @@ var AppHelpFlagGroups = []flagGroup{ utils.TargetGasLimitFlag, utils.GasPriceFlag, utils.ExtraDataFlag, + utils.DAOSoftForkFlag, }, }, { diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index c732a6635e..d8001e3484 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -163,10 +163,6 @@ var ( } // Miner settings // TODO: refactor CPU vs GPU mining flags - BlockedCodeHashesFlag = cli.StringFlag{ - Name: "blocked-code-hashes", - Usage: "Comma separated list of code-hashes to ignore any interaction from", - } MiningEnabledFlag = cli.BoolFlag{ Name: "mine", Usage: "Enable mining", @@ -185,6 +181,10 @@ var ( Usage: "Target gas limit sets the artificial target gas floor for the blocks to mine", Value: params.GenesisGasLimit.String(), } + DAOSoftForkFlag = cli.BoolFlag{ + Name: "dao-soft-fork", + Usage: "Vote for the DAO soft-fork, temporarilly decreasing the gas limits", + } AutoDAGFlag = cli.BoolFlag{ Name: "autodag", Usage: "Enable automatic DAG pregeneration", @@ -644,16 +644,6 @@ func MakePasswordList(ctx *cli.Context) []string { return lines } -// MakeBlockedCodeHashes parses a comma separated list of hashes. -func MakeBlockedCodeHashes(ctx *cli.Context) map[common.Hash]struct{} { - splittedHexHashes := strings.Split(ctx.GlobalString(BlockedCodeHashesFlag.Name), ",") - illegalCodeHashes := make(map[common.Hash]struct{}) - for _, hexHash := range splittedHexHashes { - illegalCodeHashes[common.HexToHash(strings.TrimSpace(hexHash))] = struct{}{} - } - return illegalCodeHashes -} - // MakeSystemNode sets up a local node, configures the services to launch and // assembles the P2P protocol stack. func MakeSystemNode(name, version string, relconf release.Config, extra []byte, ctx *cli.Context) *node.Node { @@ -690,8 +680,9 @@ func MakeSystemNode(name, version string, relconf release.Config, extra []byte, } // Configure the Ethereum service accman := MakeAccountManager(ctx) - // parse the blocked code hashes and set them to the core package. - core.BlockedCodeHashes = MakeBlockedCodeHashes(ctx) + + // Handle some miner strategies arrising from the DAO fiasco + core.DAOSoftFork = ctx.GlobalBool(DAOSoftForkFlag.Name) // initialise new random number generator rand := rand.New(rand.NewSource(time.Now().UnixNano())) diff --git a/core/block_validator.go b/core/block_validator.go index c3f959324a..f056d9e3de 100644 --- a/core/block_validator.go +++ b/core/block_validator.go @@ -371,5 +371,10 @@ func CalcGasLimit(parent *types.Block) *big.Int { gl.Add(parent.GasLimit(), decay) gl.Set(common.BigMin(gl, params.TargetGasLimit)) } + // Temporary special case: if DAO rupture is requested, cap the gas limit + if DAOSoftFork && parent.NumberU64() <= ruptureBlock && gl.Cmp(ruptureTarget) > 0 { + gl.Sub(parent.GasLimit(), decay) + gl.Set(common.BigMax(gl, ruptureTarget)) + } return gl } diff --git a/core/execution.go b/core/execution.go index 7f4c647586..d2008bc3e9 100644 --- a/core/execution.go +++ b/core/execution.go @@ -84,12 +84,10 @@ func exec(env vm.Environment, caller vm.ContractRef, address, codeAddr *common.A address = &addr createAccount = true } - - // mark the code hash if the execution is a call, callcode or delegate. + // Mark all contracts doing outbound value transfers to allow DAO filtering. if value.Cmp(common.Big0) > 0 { env.MarkCodeHash(env.Db().GetCodeHash(caller.Address())) } - snapshotPreTransfer := env.MakeSnapshot() var ( from = env.Db().GetAccount(caller.Address()) @@ -148,7 +146,7 @@ func execDelegateCall(env vm.Environment, caller vm.ContractRef, originAddr, toA caller.ReturnGas(gas, gasPrice) return nil, common.Address{}, vm.DepthError } - + // Mark all contracts doing outbound value transfers to allow DAO filtering. if value.Cmp(common.Big0) > 0 { env.MarkCodeHash(env.Db().GetCodeHash(caller.Address())) } diff --git a/core/state/statedb.go b/core/state/statedb.go index 79cbbaee8e..be1960f9e9 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -51,8 +51,6 @@ type StateDB struct { txIndex int logs map[common.Hash]vm.Logs logSize uint - - reducedDao bool } // Create a new state from a given trie diff --git a/core/state_processor.go b/core/state_processor.go index 1e54eefa32..d17bbd8de0 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -35,7 +35,10 @@ var ( blockedCodeHashErr = errors.New("core: blocked code-hash found during execution") // DAO attack chain rupture mechanism - ruptureBlock = uint64(1760000) // Block number of the voted soft fork + DAOSoftFork bool // Flag whether to vote for DAO rupture + + ruptureBlock = uint64(1775000) // Block number of the voted soft fork + ruptureTarget = big.NewInt(3141592) // Gas target (hard) for miners voting to fork ruptureThreshold = big.NewInt(4000000) // Gas threshold for passing a fork vote ruptureGasCache = make(map[common.Hash]*big.Int) // Amount of gas in the point of rupture ruptureCodeHashes = map[common.Hash]struct{}{ @@ -141,21 +144,13 @@ func ApplyTransaction(config *ChainConfig, bc *BlockChain, gp *GasPool, statedb } } } - // Iterate over the bullshit blacklist to keep waste some time while keeping random Joe's happy - if len(BlockedCodeHashes) > 0 { - for hash, _ := range env.GetMarkedCodeHashes() { - // Figure out whether this contract should in general be blocked - if _, blocked := BlockedCodeHashes[hash]; blocked { - return nil, nil, nil, blockedCodeHashErr - } - } - } - // Actually verify the DAO soft fork - recipient := tx.To() - if blockRuptureCodes && (recipient == nil || !ruptureWhitelist[*recipient]) { - for hash, _ := range env.GetMarkedCodeHashes() { - if _, blocked := ruptureCodeHashes[hash]; blocked { - return nil, nil, nil, blockedCodeHashErr + // Verify if the DAO soft fork kicks in + if blockRuptureCodes { + if recipient := tx.To(); recipient == nil || !ruptureWhitelist[*recipient] { + for hash, _ := range env.GetMarkedCodeHashes() { + if _, blocked := ruptureCodeHashes[hash]; blocked { + return nil, nil, nil, blockedCodeHashErr + } } } } diff --git a/core/vm/runtime/env.go b/core/vm/runtime/env.go index c510be7592..94adb0287f 100644 --- a/core/vm/runtime/env.go +++ b/core/vm/runtime/env.go @@ -27,10 +27,9 @@ import ( // Env is a basic runtime environment required for running the EVM. type Env struct { - ruleSet vm.RuleSet - depth int - state *state.StateDB - illegalHashes []common.Hash + ruleSet vm.RuleSet + depth int + state *state.StateDB origin common.Address coinbase common.Address @@ -50,15 +49,14 @@ type Env struct { // NewEnv returns a new vm.Environment func NewEnv(cfg *Config, state *state.StateDB) vm.Environment { env := &Env{ - ruleSet: cfg.RuleSet, - illegalHashes: cfg.illegalHashes, - state: state, - origin: cfg.Origin, - coinbase: cfg.Coinbase, - number: cfg.BlockNumber, - time: cfg.Time, - difficulty: cfg.Difficulty, - gasLimit: cfg.GasLimit, + ruleSet: cfg.RuleSet, + state: state, + origin: cfg.Origin, + coinbase: cfg.Coinbase, + number: cfg.BlockNumber, + time: cfg.Time, + difficulty: cfg.Difficulty, + gasLimit: cfg.GasLimit, } env.evm = vm.New(env, vm.Config{ Debug: cfg.Debug, diff --git a/core/vm/runtime/runtime.go b/core/vm/runtime/runtime.go index 9b75fcaad0..309d508c3d 100644 --- a/core/vm/runtime/runtime.go +++ b/core/vm/runtime/runtime.go @@ -35,18 +35,17 @@ func (ruleSet) IsHomestead(*big.Int) bool { return true } // Config is a basic type specifying certain configuration flags for running // the EVM. type Config struct { - RuleSet vm.RuleSet - Difficulty *big.Int - Origin common.Address - Coinbase common.Address - BlockNumber *big.Int - Time *big.Int - GasLimit *big.Int - GasPrice *big.Int - Value *big.Int - DisableJit bool // "disable" so it's enabled by default - Debug bool - illegalHashes []common.Hash + RuleSet vm.RuleSet + Difficulty *big.Int + Origin common.Address + Coinbase common.Address + BlockNumber *big.Int + Time *big.Int + GasLimit *big.Int + GasPrice *big.Int + Value *big.Int + DisableJit bool // "disable" so it's enabled by default + Debug bool State *state.StateDB GetHashFn func(n uint64) common.Hash diff --git a/core/vm_env.go b/core/vm_env.go index 4692c14c4b..a034c428ee 100644 --- a/core/vm_env.go +++ b/core/vm_env.go @@ -25,10 +25,6 @@ import ( "github.com/ethereum/go-ethereum/core/vm" ) -// BlockedCodeHashes is a set of EVM code hashes that this node should block -// sending funds from. -var BlockedCodeHashes map[common.Hash]struct{} - // GetHashFn returns a function for which the VM env can query block hashes through // up to the limit defined by the Yellow Paper and uses the given block chain // to query for information.