Skip to content

Commit ca73dea

Browse files
authored
Merge pull request #3179 from obscuren/eip-158
EIP158 & 160 Hardfork
2 parents 2170119 + 648bd22 commit ca73dea

File tree

961 files changed

+149784
-66840
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

961 files changed

+149784
-66840
lines changed

accounts/abi/bind/auth.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ func NewKeyedTransactor(key *ecdsa.PrivateKey) *TransactOpts {
4848
keyAddr := crypto.PubkeyToAddress(key.PublicKey)
4949
return &TransactOpts{
5050
From: keyAddr,
51-
Signer: func(address common.Address, tx *types.Transaction) (*types.Transaction, error) {
51+
Signer: func(signer types.Signer, address common.Address, tx *types.Transaction) (*types.Transaction, error) {
5252
if address != keyAddr {
5353
return nil, errors.New("not authorized to sign this account")
5454
}
55-
signature, err := crypto.SignEthereum(tx.SigHash().Bytes(), key)
55+
signature, err := crypto.SignEthereum(signer.Hash(tx).Bytes(), key)
5656
if err != nil {
5757
return nil, err
5858
}
59-
return tx.WithSignature(signature)
59+
return tx.WithSignature(signer, signature)
6060
},
6161
}
6262
}

accounts/abi/bind/backends/simulated.go

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ import (
3131
"github.com/ethereum/go-ethereum/core/vm"
3232
"github.com/ethereum/go-ethereum/ethdb"
3333
"github.com/ethereum/go-ethereum/event"
34+
"github.com/ethereum/go-ethereum/params"
3435
"golang.org/x/net/context"
3536
)
3637

3738
// Default chain configuration which sets homestead phase at block 0 (i.e. no frontier)
38-
var chainConfig = &core.ChainConfig{HomesteadBlock: big.NewInt(0)}
39+
var chainConfig = &params.ChainConfig{HomesteadBlock: big.NewInt(0), EIP150Block: new(big.Int), EIP158Block: new(big.Int)}
3940

4041
// This nil assignment ensures compile time that SimulatedBackend implements bind.ContractBackend.
4142
var _ bind.ContractBackend = (*SimulatedBackend)(nil)
@@ -51,6 +52,8 @@ type SimulatedBackend struct {
5152
mu sync.Mutex
5253
pendingBlock *types.Block // Currently pending block that will be imported on request
5354
pendingState *state.StateDB // Currently pending state that will be the active on on request
55+
56+
config *params.ChainConfig
5457
}
5558

5659
// NewSimulatedBackend creates a new binding backend using a simulated blockchain
@@ -85,7 +88,7 @@ func (b *SimulatedBackend) Rollback() {
8588
}
8689

8790
func (b *SimulatedBackend) rollback() {
88-
blocks, _ := core.GenerateChain(nil, b.blockchain.CurrentBlock(), b.database, 1, func(int, *core.BlockGen) {})
91+
blocks, _ := core.GenerateChain(chainConfig, b.blockchain.CurrentBlock(), b.database, 1, func(int, *core.BlockGen) {})
8992
b.pendingBlock = blocks[0]
9093
b.pendingState, _ = state.New(b.pendingBlock.Root(), b.database)
9194
}
@@ -234,7 +237,7 @@ func (b *SimulatedBackend) SendTransaction(ctx context.Context, tx *types.Transa
234237
b.mu.Lock()
235238
defer b.mu.Unlock()
236239

237-
sender, err := tx.From()
240+
sender, err := types.Sender(types.HomesteadSigner{}, tx)
238241
if err != nil {
239242
panic(fmt.Errorf("invalid transaction: %v", err))
240243
}
@@ -243,7 +246,7 @@ func (b *SimulatedBackend) SendTransaction(ctx context.Context, tx *types.Transa
243246
panic(fmt.Errorf("invalid transaction nonce: got %d, want %d", tx.Nonce(), nonce))
244247
}
245248

246-
blocks, _ := core.GenerateChain(nil, b.blockchain.CurrentBlock(), b.database, 1, func(number int, block *core.BlockGen) {
249+
blocks, _ := core.GenerateChain(chainConfig, b.blockchain.CurrentBlock(), b.database, 1, func(number int, block *core.BlockGen) {
247250
for _, tx := range b.pendingBlock.Transactions() {
248251
block.AddTx(tx)
249252
}
@@ -259,12 +262,11 @@ type callmsg struct {
259262
ethereum.CallMsg
260263
}
261264

262-
func (m callmsg) From() (common.Address, error) { return m.CallMsg.From, nil }
263-
func (m callmsg) FromFrontier() (common.Address, error) { return m.CallMsg.From, nil }
264-
func (m callmsg) Nonce() uint64 { return 0 }
265-
func (m callmsg) CheckNonce() bool { return false }
266-
func (m callmsg) To() *common.Address { return m.CallMsg.To }
267-
func (m callmsg) GasPrice() *big.Int { return m.CallMsg.GasPrice }
268-
func (m callmsg) Gas() *big.Int { return m.CallMsg.Gas }
269-
func (m callmsg) Value() *big.Int { return m.CallMsg.Value }
270-
func (m callmsg) Data() []byte { return m.CallMsg.Data }
265+
func (m callmsg) From() common.Address { return m.CallMsg.From }
266+
func (m callmsg) Nonce() uint64 { return 0 }
267+
func (m callmsg) CheckNonce() bool { return false }
268+
func (m callmsg) To() *common.Address { return m.CallMsg.To }
269+
func (m callmsg) GasPrice() *big.Int { return m.CallMsg.GasPrice }
270+
func (m callmsg) Gas() *big.Int { return m.CallMsg.Gas }
271+
func (m callmsg) Value() *big.Int { return m.CallMsg.Value }
272+
func (m callmsg) Data() []byte { return m.CallMsg.Data }

accounts/abi/bind/base.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131

3232
// SignerFn is a signer function callback when a contract requires a method to
3333
// sign the transaction before submission.
34-
type SignerFn func(common.Address, *types.Transaction) (*types.Transaction, error)
34+
type SignerFn func(types.Signer, common.Address, *types.Transaction) (*types.Transaction, error)
3535

3636
// CallOpts is the collection of options to fine tune a contract call request.
3737
type CallOpts struct {
@@ -214,7 +214,7 @@ func (c *BoundContract) transact(opts *TransactOpts, contract *common.Address, i
214214
if opts.Signer == nil {
215215
return nil, errors.New("no signer to authorize the transaction with")
216216
}
217-
signedTx, err := opts.Signer(opts.From, rawTx)
217+
signedTx, err := opts.Signer(types.HomesteadSigner{}, opts.From, rawTx)
218218
if err != nil {
219219
return nil, err
220220
}

accounts/abi/bind/util_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func TestWaitDeployed(t *testing.T) {
6060

6161
// Create the transaction.
6262
tx := types.NewContractCreation(0, big.NewInt(0), test.gas, big.NewInt(1), common.FromHex(test.code))
63-
tx, _ = tx.SignECDSA(testKey)
63+
tx, _ = tx.SignECDSA(types.HomesteadSigner{}, testKey)
6464

6565
// Wait for it to get mined in the background.
6666
var (

cmd/ethtest/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,11 @@ func runTestWithReader(test string, r io.Reader) error {
7676
case "bk", "block", "blocktest", "blockchaintest", "blocktests", "blockchaintests":
7777
err = tests.RunBlockTestWithReader(params.MainNetHomesteadBlock, params.MainNetDAOForkBlock, params.MainNetHomesteadGasRepriceBlock, r, skipTests)
7878
case "st", "state", "statetest", "statetests":
79-
rs := tests.RuleSet{HomesteadBlock: params.MainNetHomesteadBlock, DAOForkBlock: params.MainNetDAOForkBlock, DAOForkSupport: true}
79+
rs := &params.ChainConfig{HomesteadBlock: params.MainNetHomesteadBlock, DAOForkBlock: params.MainNetDAOForkBlock, DAOForkSupport: true, EIP150Block: params.MainNetHomesteadGasRepriceBlock}
8080
err = tests.RunStateTestWithReader(rs, r, skipTests)
8181
case "tx", "transactiontest", "transactiontests":
82-
err = tests.RunTransactionTestsWithReader(r, skipTests)
82+
rs := &params.ChainConfig{HomesteadBlock: params.MainNetHomesteadBlock, DAOForkBlock: params.MainNetDAOForkBlock, DAOForkSupport: true, EIP150Block: params.MainNetHomesteadGasRepriceBlock}
83+
err = tests.RunTransactionTestsWithReader(rs, r, skipTests)
8384
case "vm", "vmtest", "vmtests":
8485
err = tests.RunVmTestWithReader(r, skipTests)
8586
case "rlp", "rlptest", "rlptests":

cmd/evm/main.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ func run(ctx *cli.Context) error {
191191
vmdone := time.Since(tstart)
192192

193193
if ctx.GlobalBool(DumpFlag.Name) {
194-
statedb.Commit()
194+
statedb.Commit(true)
195195
fmt.Println(string(statedb.Dump()))
196196
}
197197
vm.StdErrFormat(logger.StructLogs())
@@ -251,30 +251,30 @@ func NewEnv(state *state.StateDB, transactor common.Address, value *big.Int, cfg
251251
return env
252252
}
253253

254-
// ruleSet implements vm.RuleSet and will always default to the homestead rule set.
254+
// ruleSet implements vm.ChainConfig and will always default to the homestead rule set.
255255
type ruleSet struct{}
256256

257257
func (ruleSet) IsHomestead(*big.Int) bool { return true }
258258
func (ruleSet) GasTable(*big.Int) params.GasTable {
259259
return params.GasTableHomesteadGasRepriceFork
260260
}
261261

262-
func (self *VMEnv) RuleSet() vm.RuleSet { return ruleSet{} }
263-
func (self *VMEnv) Vm() vm.Vm { return self.evm }
264-
func (self *VMEnv) Db() vm.Database { return self.state }
265-
func (self *VMEnv) SnapshotDatabase() int { return self.state.Snapshot() }
266-
func (self *VMEnv) RevertToSnapshot(snap int) { self.state.RevertToSnapshot(snap) }
267-
func (self *VMEnv) Origin() common.Address { return *self.transactor }
268-
func (self *VMEnv) BlockNumber() *big.Int { return common.Big0 }
269-
func (self *VMEnv) Coinbase() common.Address { return *self.transactor }
270-
func (self *VMEnv) Time() *big.Int { return self.time }
271-
func (self *VMEnv) Difficulty() *big.Int { return common.Big1 }
272-
func (self *VMEnv) BlockHash() []byte { return make([]byte, 32) }
273-
func (self *VMEnv) Value() *big.Int { return self.value }
274-
func (self *VMEnv) GasLimit() *big.Int { return big.NewInt(1000000000) }
275-
func (self *VMEnv) VmType() vm.Type { return vm.StdVmTy }
276-
func (self *VMEnv) Depth() int { return 0 }
277-
func (self *VMEnv) SetDepth(i int) { self.depth = i }
262+
func (self *VMEnv) ChainConfig() *params.ChainConfig { return params.TestChainConfig }
263+
func (self *VMEnv) Vm() vm.Vm { return self.evm }
264+
func (self *VMEnv) Db() vm.Database { return self.state }
265+
func (self *VMEnv) SnapshotDatabase() int { return self.state.Snapshot() }
266+
func (self *VMEnv) RevertToSnapshot(snap int) { self.state.RevertToSnapshot(snap) }
267+
func (self *VMEnv) Origin() common.Address { return *self.transactor }
268+
func (self *VMEnv) BlockNumber() *big.Int { return common.Big0 }
269+
func (self *VMEnv) Coinbase() common.Address { return *self.transactor }
270+
func (self *VMEnv) Time() *big.Int { return self.time }
271+
func (self *VMEnv) Difficulty() *big.Int { return common.Big1 }
272+
func (self *VMEnv) BlockHash() []byte { return make([]byte, 32) }
273+
func (self *VMEnv) Value() *big.Int { return self.value }
274+
func (self *VMEnv) GasLimit() *big.Int { return big.NewInt(1000000000) }
275+
func (self *VMEnv) VmType() vm.Type { return vm.StdVmTy }
276+
func (self *VMEnv) Depth() int { return 0 }
277+
func (self *VMEnv) SetDepth(i int) { self.depth = i }
278278
func (self *VMEnv) GetHash(n uint64) common.Hash {
279279
if self.block.Number().Cmp(big.NewInt(int64(n))) == 0 {
280280
return self.block.Hash()

cmd/gethrpctest/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"os"
2424
"os/signal"
2525

26-
"github.com/ethereum/go-ethereum/core"
2726
"github.com/ethereum/go-ethereum/crypto"
2827
"github.com/ethereum/go-ethereum/eth"
2928
"github.com/ethereum/go-ethereum/ethdb"
@@ -122,7 +121,7 @@ func MakeSystemNode(privkey string, test *tests.BlockTest) (*node.Node, error) {
122121
ethConf := &eth.Config{
123122
TestGenesisState: db,
124123
TestGenesisBlock: test.Genesis,
125-
ChainConfig: &core.ChainConfig{HomesteadBlock: params.MainNetHomesteadBlock},
124+
ChainConfig: &params.ChainConfig{HomesteadBlock: params.MainNetHomesteadBlock},
126125
}
127126
if err := stack.Register(func(ctx *node.ServiceContext) (node.Service, error) { return eth.New(ctx, ethConf) }); err != nil {
128127
return nil, err

cmd/utils/flags.go

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -801,17 +801,17 @@ func SetupNetwork(ctx *cli.Context) {
801801
}
802802

803803
// MakeChainConfig reads the chain configuration from the database in ctx.Datadir.
804-
func MakeChainConfig(ctx *cli.Context, stack *node.Node) *core.ChainConfig {
804+
func MakeChainConfig(ctx *cli.Context, stack *node.Node) *params.ChainConfig {
805805
db := MakeChainDatabase(ctx, stack)
806806
defer db.Close()
807807

808808
return MakeChainConfigFromDb(ctx, db)
809809
}
810810

811811
// MakeChainConfigFromDb reads the chain configuration from the given database.
812-
func MakeChainConfigFromDb(ctx *cli.Context, db ethdb.Database) *core.ChainConfig {
812+
func MakeChainConfigFromDb(ctx *cli.Context, db ethdb.Database) *params.ChainConfig {
813813
// If the chain is already initialized, use any existing chain configs
814-
config := new(core.ChainConfig)
814+
config := new(params.ChainConfig)
815815

816816
genesis := core.GetBlock(db, core.GetCanonicalHash(db, 0), 0)
817817
if genesis != nil {
@@ -825,6 +825,10 @@ func MakeChainConfigFromDb(ctx *cli.Context, db ethdb.Database) *core.ChainConfi
825825
Fatalf("Could not make chain configuration: %v", err)
826826
}
827827
}
828+
// set chain id in case it's zero.
829+
if config.ChainId == nil {
830+
config.ChainId = new(big.Int)
831+
}
828832
// Check whether we are allowed to set default config params or not:
829833
// - If no genesis is set, we're running either mainnet or testnet (private nets use `geth init`)
830834
// - If a genesis is already set, ensure we have a configuration for it (mainnet or testnet)
@@ -849,21 +853,37 @@ func MakeChainConfigFromDb(ctx *cli.Context, db ethdb.Database) *core.ChainConfi
849853
}
850854
config.DAOForkSupport = true
851855
}
852-
if config.HomesteadGasRepriceBlock == nil {
856+
if config.EIP150Block == nil {
857+
if ctx.GlobalBool(TestNetFlag.Name) {
858+
config.EIP150Block = params.TestNetHomesteadGasRepriceBlock
859+
} else {
860+
config.EIP150Block = params.MainNetHomesteadGasRepriceBlock
861+
}
862+
}
863+
if config.EIP150Hash == (common.Hash{}) {
853864
if ctx.GlobalBool(TestNetFlag.Name) {
854-
config.HomesteadGasRepriceBlock = params.TestNetHomesteadGasRepriceBlock
865+
config.EIP150Hash = params.TestNetHomesteadGasRepriceHash
855866
} else {
856-
config.HomesteadGasRepriceBlock = params.MainNetHomesteadGasRepriceBlock
867+
config.EIP150Hash = params.MainNetHomesteadGasRepriceHash
857868
}
858869
}
859-
if config.HomesteadGasRepriceHash == (common.Hash{}) {
870+
if config.EIP155Block == nil {
860871
if ctx.GlobalBool(TestNetFlag.Name) {
861-
config.HomesteadGasRepriceHash = params.TestNetHomesteadGasRepriceHash
872+
config.EIP150Block = params.TestNetSpuriousDragon
862873
} else {
863-
config.HomesteadGasRepriceHash = params.MainNetHomesteadGasRepriceHash
874+
config.EIP155Block = params.MainNetSpuriousDragon
864875
}
865876
}
877+
if config.EIP158Block == nil {
878+
if ctx.GlobalBool(TestNetFlag.Name) {
879+
config.EIP158Block = params.TestNetSpuriousDragon
880+
} else {
881+
config.EIP158Block = params.MainNetSpuriousDragon
882+
}
883+
}
884+
config.DAOForkSupport = true
866885
}
886+
867887
// Force override any existing configs if explicitly requested
868888
switch {
869889
case ctx.GlobalBool(SupportDAOFork.Name):

common/registrar/ethreg/api.go

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ import (
3232
"github.com/ethereum/go-ethereum/ethdb"
3333
"github.com/ethereum/go-ethereum/logger"
3434
"github.com/ethereum/go-ethereum/logger/glog"
35+
"github.com/ethereum/go-ethereum/params"
3536
)
3637

3738
// registryAPIBackend is a backend for an Ethereum Registry.
3839
type registryAPIBackend struct {
39-
config *core.ChainConfig
40+
config *params.ChainConfig
4041
bc *core.BlockChain
4142
chainDb ethdb.Database
4243
txPool *core.TxPool
@@ -45,12 +46,12 @@ type registryAPIBackend struct {
4546

4647
// PrivateRegistarAPI offers various functions to access the Ethereum registry.
4748
type PrivateRegistarAPI struct {
48-
config *core.ChainConfig
49+
config *params.ChainConfig
4950
be *registryAPIBackend
5051
}
5152

5253
// NewPrivateRegistarAPI creates a new PrivateRegistarAPI instance.
53-
func NewPrivateRegistarAPI(config *core.ChainConfig, bc *core.BlockChain, chainDb ethdb.Database, txPool *core.TxPool, am *accounts.Manager) *PrivateRegistarAPI {
54+
func NewPrivateRegistarAPI(config *params.ChainConfig, bc *core.BlockChain, chainDb ethdb.Database, txPool *core.TxPool, am *accounts.Manager) *PrivateRegistarAPI {
5455
return &PrivateRegistarAPI{
5556
config: config,
5657
be: &registryAPIBackend{
@@ -173,25 +174,20 @@ func (be *registryAPIBackend) Call(fromStr, toStr, valueStr, gasStr, gasPriceStr
173174

174175
from.SetBalance(common.MaxBig)
175176

176-
msg := callmsg{
177-
from: from,
178-
gas: common.Big(gasStr),
179-
gasPrice: common.Big(gasPriceStr),
180-
value: common.Big(valueStr),
181-
data: common.FromHex(dataStr),
182-
}
177+
var to *common.Address
183178
if len(toStr) > 0 {
184179
addr := common.HexToAddress(toStr)
185-
msg.to = &addr
180+
to = &addr
186181
}
187-
188-
if msg.gas.Cmp(big.NewInt(0)) == 0 {
189-
msg.gas = big.NewInt(50000000)
182+
gas := common.Big(gasStr)
183+
if gas.BitLen() == 0 {
184+
gas = big.NewInt(50000000)
190185
}
191-
192-
if msg.gasPrice.Cmp(big.NewInt(0)) == 0 {
193-
msg.gasPrice = new(big.Int).Mul(big.NewInt(50), common.Shannon)
186+
gasPrice := common.Big(gasPriceStr)
187+
if gasPrice.BitLen() == 0 {
188+
gasPrice = new(big.Int).Mul(big.NewInt(50), common.Shannon)
194189
}
190+
msg := types.NewMessage(from.Address(), to, 0, common.Big(valueStr), gas, gasPrice, common.FromHex(dataStr))
195191

196192
header := be.bc.CurrentBlock().Header()
197193
vmenv := core.NewEnv(statedb, be.config, be.bc, msg, header, vm.Config{})
@@ -257,11 +253,12 @@ func (be *registryAPIBackend) Transact(fromStr, toStr, nonceStr, valueStr, gasSt
257253
tx = types.NewTransaction(nonce, to, value, gas, price, data)
258254
}
259255

260-
signature, err := be.am.SignEthereum(from, tx.SigHash().Bytes())
256+
sigHash := (types.HomesteadSigner{}).Hash(tx)
257+
signature, err := be.am.SignEthereum(from, sigHash.Bytes())
261258
if err != nil {
262259
return "", err
263260
}
264-
signedTx, err := tx.WithSignature(signature)
261+
signedTx, err := tx.WithSignature(types.HomesteadSigner{}, signature)
265262
if err != nil {
266263
return "", err
267264
}

console/console_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ import (
2828
"time"
2929

3030
"github.com/ethereum/go-ethereum/common"
31-
"github.com/ethereum/go-ethereum/core"
3231
"github.com/ethereum/go-ethereum/eth"
3332
"github.com/ethereum/go-ethereum/internal/jsre"
3433
"github.com/ethereum/go-ethereum/node"
34+
"github.com/ethereum/go-ethereum/params"
3535
)
3636

3737
const (
@@ -97,7 +97,7 @@ func newTester(t *testing.T, confOverride func(*eth.Config)) *tester {
9797
t.Fatalf("failed to create node: %v", err)
9898
}
9999
ethConf := &eth.Config{
100-
ChainConfig: &core.ChainConfig{HomesteadBlock: new(big.Int)},
100+
ChainConfig: &params.ChainConfig{HomesteadBlock: new(big.Int), ChainId: new(big.Int)},
101101
Etherbase: common.HexToAddress(testAddress),
102102
PowTest: true,
103103
}

0 commit comments

Comments
 (0)