From dc2e34ddf37cc46e32959a50f03e1d7fe1445630 Mon Sep 17 00:00:00 2001 From: Jeffrey Wilcke Date: Thu, 20 Oct 2016 13:36:29 +0200 Subject: core, core/state, trie: Hardfork EIP155, EIP161, EIP170 This commit implements EIP158 part 1, 2, 3 & 4 1. If an account is empty it's no longer written to the trie. An empty account is defined as (balance=0, nonce=0, storage=0, code=0). 2. Delete an empty account if it's touched 3. An empty account is redefined as either non-existent or empty. 4. Zero value calls and zero value suicides no longer consume the 25k reation costs. params: moved core/config to params Signed-off-by: Jeffrey Wilcke --- params/config.go | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++ params/gas_table.go | 18 +++++++++ params/util.go | 21 +++++++--- 3 files changed, 146 insertions(+), 5 deletions(-) create mode 100644 params/config.go (limited to 'params') diff --git a/params/config.go b/params/config.go new file mode 100644 index 000000000..f75c33870 --- /dev/null +++ b/params/config.go @@ -0,0 +1,112 @@ +// 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 params + +import ( + "math/big" + + "github.com/ethereum/go-ethereum/common" +) + +// ChainConfig is the core config which determines the blockchain settings. +// +// ChainConfig is stored in the database on a per block basis. This means +// that any network, identified by its genesis block, can have its own +// set of configuration options. +type ChainConfig struct { + ChainId *big.Int `json:"chainId"` // Chain id identifies the current chain and is used for replay protection + + HomesteadBlock *big.Int `json:"homesteadBlock"` // Homestead switch block (nil = no fork, 0 = already homestead) + DAOForkBlock *big.Int `json:"daoForkBlock"` // TheDAO hard-fork switch block (nil = no fork) + DAOForkSupport bool `json:"daoForkSupport"` // Whether the nodes supports or opposes the DAO hard-fork + + // EIP150 implements the Gas price changes (https://github.com/ethereum/EIPs/issues/150) + EIP150Block *big.Int `json:"EIP150Block"` // EIP150 HF block (nil = no fork) + EIP150Hash common.Hash `json:"EIP150Hash"` // EIP150 HF hash (fast sync aid) + + EIP155Block *big.Int `json:"EIP155Block"` // EIP155 HF block + EIP158Block *big.Int `json:"EIP158Block"` // EIP158 HF block +} + +var ( + TestChainConfig = &ChainConfig{big.NewInt(1), new(big.Int), new(big.Int), true, new(big.Int), common.Hash{}, new(big.Int), new(big.Int)} + TestRules = TestChainConfig.Rules(new(big.Int)) +) + +// IsHomestead returns whether num is either equal to the homestead block or greater. +func (c *ChainConfig) IsHomestead(num *big.Int) bool { + if c.HomesteadBlock == nil || num == nil { + return false + } + return num.Cmp(c.HomesteadBlock) >= 0 +} + +// GasTable returns the gas table corresponding to the current phase (homestead or homestead reprice). +// +// The returned GasTable's fields shouldn't, under any circumstances, be changed. +func (c *ChainConfig) GasTable(num *big.Int) GasTable { + if num == nil { + return GasTableHomestead + } + + switch { + case c.EIP158Block != nil && num.Cmp(c.EIP158Block) >= 0: + return GasTableEIP158 + case c.EIP150Block != nil && num.Cmp(c.EIP150Block) >= 0: + return GasTableHomesteadGasRepriceFork + default: + return GasTableHomestead + } +} + +func (c *ChainConfig) IsEIP150(num *big.Int) bool { + if c.EIP150Block == nil || num == nil { + return false + } + return num.Cmp(c.EIP150Block) >= 0 + +} + +func (c *ChainConfig) IsEIP155(num *big.Int) bool { + if c.EIP155Block == nil || num == nil { + return false + } + return num.Cmp(c.EIP155Block) >= 0 + +} + +func (c *ChainConfig) IsEIP158(num *big.Int) bool { + if c.EIP158Block == nil || num == nil { + return false + } + return num.Cmp(c.EIP158Block) >= 0 + +} + +// Rules wraps ChainConfig and is merely syntatic sugar or can be used for functions +// that do not have or require information about the block. +// +// Rules is a one time interface meaning that it shouldn't be used in between transition +// phases. +type Rules struct { + ChainId *big.Int + IsHomestead, IsEIP150, IsEIP155, IsEIP158 bool +} + +func (c *ChainConfig) Rules(num *big.Int) Rules { + return Rules{ChainId: new(big.Int).Set(c.ChainId), IsHomestead: c.IsHomestead(num), IsEIP150: c.IsEIP150(num), IsEIP155: c.IsEIP155(num), IsEIP158: c.IsEIP158(num)} +} diff --git a/params/gas_table.go b/params/gas_table.go index 98f00a7ee..093dacc8b 100644 --- a/params/gas_table.go +++ b/params/gas_table.go @@ -26,6 +26,8 @@ type GasTable struct { Calls *big.Int Suicide *big.Int + ExpByte *big.Int + // CreateBySuicide occurs when the // refunded account is one that does // not exist. This logic is similar @@ -44,6 +46,7 @@ var ( SLoad: big.NewInt(50), Calls: big.NewInt(40), Suicide: big.NewInt(0), + ExpByte: big.NewInt(10), // explicitly set to nil to indicate // this rule does not apply to homestead. @@ -52,6 +55,8 @@ var ( // GasTableHomestead contain the gas re-prices for // the homestead phase. + // + // TODO rename to GasTableEIP150 GasTableHomesteadGasRepriceFork = GasTable{ ExtcodeSize: big.NewInt(700), ExtcodeCopy: big.NewInt(700), @@ -59,6 +64,19 @@ var ( SLoad: big.NewInt(200), Calls: big.NewInt(700), Suicide: big.NewInt(5000), + ExpByte: big.NewInt(10), + + CreateBySuicide: big.NewInt(25000), + } + + GasTableEIP158 = GasTable{ + ExtcodeSize: big.NewInt(700), + ExtcodeCopy: big.NewInt(700), + Balance: big.NewInt(400), + SLoad: big.NewInt(200), + Calls: big.NewInt(700), + Suicide: big.NewInt(5000), + ExpByte: big.NewInt(50), CreateBySuicide: big.NewInt(25000), } diff --git a/params/util.go b/params/util.go index 583cf03bb..5764f2f9a 100644 --- a/params/util.go +++ b/params/util.go @@ -16,11 +16,22 @@ package params -import "math/big" +import ( + "math/big" + + "github.com/ethereum/go-ethereum/common" +) var ( - TestNetHomesteadBlock = big.NewInt(494000) // Testnet homestead block - MainNetHomesteadBlock = big.NewInt(1150000) // Mainnet homestead block - TestNetHomesteadGasRepriceBlock = big.NewInt(1783000) // Test net gas reprice block - MainNetHomesteadGasRepriceBlock = big.NewInt(2463000) // Main net gas reprice block + TestNetHomesteadBlock = big.NewInt(494000) // Testnet homestead block + MainNetHomesteadBlock = big.NewInt(1150000) // Mainnet homestead block + TestNetHomesteadGasRepriceBlock = big.NewInt(1783000) // Test net gas reprice block + MainNetHomesteadGasRepriceBlock = big.NewInt(2463000) // Main net gas reprice block + TestNetHomesteadGasRepriceHash = common.HexToHash("0xf376243aeff1f256d970714c3de9fd78fa4e63cf63e32a51fe1169e375d98145") // Testnet gas reprice block hash (used by fast sync) + MainNetHomesteadGasRepriceHash = common.HexToHash("0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0") // Mainnet gas reprice block hash (used by fast sync) + TestNetChainID = big.NewInt(2) // Testnet default chain ID + MainNetChainID = big.NewInt(1) // Main net default chain ID + + TestNetSpuriousDragon = big.NewInt(3000000) + MainNetSpuriousDragon = big.NewInt(3000000) ) -- cgit v1.2.3 From 7d9c6f611a6c85405299f51647f366fcf18c9b1e Mon Sep 17 00:00:00 2001 From: Jeffrey Wilcke Date: Tue, 15 Nov 2016 10:08:32 +0100 Subject: params: Hardfork block number --- params/util.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'params') diff --git a/params/util.go b/params/util.go index 5764f2f9a..c9c0f393c 100644 --- a/params/util.go +++ b/params/util.go @@ -32,6 +32,6 @@ var ( TestNetChainID = big.NewInt(2) // Testnet default chain ID MainNetChainID = big.NewInt(1) // Main net default chain ID - TestNetSpuriousDragon = big.NewInt(3000000) - MainNetSpuriousDragon = big.NewInt(3000000) + TestNetSpuriousDragon = big.NewInt(1885000) + MainNetSpuriousDragon = big.NewInt(2675000) ) -- cgit v1.2.3