Skip to content

Commit

Permalink
Merge pull request ethereum#246 from etclabscore/feat/support-eips-23…
Browse files Browse the repository at this point in the history
…15-2929

Convert YoloV2 flags to EIP-2315 and EIP-2929
  • Loading branch information
meowsbits authored Dec 4, 2020
2 parents 3522896 + 9c52487 commit 760dd39
Show file tree
Hide file tree
Showing 24 changed files with 207 additions and 113 deletions.
2 changes: 1 addition & 1 deletion cmd/clef/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ var (
chainIdFlag = cli.Int64Flag{
Name: "chainid",
Value: params.MainnetChainConfig.ChainID.Int64(),
Usage: "Chain id to use for signing (1=foundation, 61=classic, 3=Ropsten, 4=Rinkeby, 5=Goerli, 6=Kotti, 63=Mordor, 133519467574833=Yolo)",
Usage: "Chain id to use for signing (1=foundation, 61=classic, 3=Ropsten, 4=Rinkeby, 5=Goerli, 6=Kotti, 63=Mordor, 133519467574834=Yolo)",
}
rpcPortFlag = cli.IntFlag{
Name: "http.port",
Expand Down
10 changes: 5 additions & 5 deletions cmd/echainspec/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ var defaultChainspecValues = map[string]ctypes.Configurator{
"ropsten": params.DefaultRopstenGenesisBlock(),
"rinkeby": params.DefaultRinkebyGenesisBlock(),
"goerli": params.DefaultGoerliGenesisBlock(),
"yolov1": params.DefaultYoloV2GenesisBlock(),
"yolov2": params.DefaultYoloV2GenesisBlock(),

"social": params.DefaultSocialGenesisBlock(),
"ethersocial": params.DefaultEthersocialGenesisBlock(),
Expand Down Expand Up @@ -167,8 +167,8 @@ USAGE:
- Reading and writing chain configurations:
The default behavior is to act as a configuration reader and writer (and implicit converter).
To establish a target configuration to read, you can either
The default behavior is to act as a configuration reader and writer (and implicit converter).
To establish a target configuration to read, you can either
1. Pass in a chain configuration externally, or
2. Use one of the builtin defaults.
Expand Down Expand Up @@ -204,11 +204,11 @@ EXAMPLES:
> {{.Name}} --inputf parity --file my-parity-spec.json --outputf [geth|coregeth]
Print a default Ethereum Classic network chain configuration in coregeth format:
> {{.Name}} --default classic --outputf coregeth
Validate a default Kotti network chain configuration for block #3000000:
> {{.Name}} --default kotti validate 3000000
VERSION:
Expand Down
22 changes: 10 additions & 12 deletions cmd/evm/internal/t8ntool/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,19 +149,17 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig ctypes.ChainConfigura
vmContext.Origin = msg.From()

evm := vm.NewEVM(vmContext, statedb, chainConfig, vmConfig)
// TODO(meowsbits): re: EIP2929
/*
if chainConfig.IsYoloV2(vmContext.BlockNumber) {
statedb.AddAddressToAccessList(msg.From())
if dst := msg.To(); dst != nil {
statedb.AddAddressToAccessList(*dst)
// If it's a create-tx, the destination will be added inside evm.create
}
for _, addr := range evm.ActivePrecompiles() {
statedb.AddAddressToAccessList(addr)
}
if chainConfig.IsEnabled(chainConfig.GetEIP2929Transition, vmContext.BlockNumber) {
statedb.AddAddressToAccessList(msg.From())
if dst := msg.To(); dst != nil {
statedb.AddAddressToAccessList(*dst)
// If it's a create-tx, the destination will be added inside evm.create
}
*/
for addr := range vm.PrecompiledContractsForConfig(chainConfig, vmContext.BlockNumber) {
statedb.AddAddressToAccessList(addr)
}
}

snapshot := statedb.Snapshot()
// (ret []byte, usedGas uint64, failed bool, err error)
msgResult, err := core.ApplyMessage(evm, msg, gaspool)
Expand Down
2 changes: 1 addition & 1 deletion cmd/geth/consolecmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestConsoleCmdNetworkIdentities(t *testing.T) {
{[]string{"--mordor"}, 7, 63, params.MordorGenesisHash.Hex()},
{[]string{"--social"}, 28, 28, params.SocialGenesisHash.Hex()},
{[]string{"--ethersocial"}, 1, 31102, params.EthersocialGenesisHash.Hex()},
{[]string{"--yolov1"}, 133519467574833, 133519467574833, params.YoloV2GenesisHash.Hex()},
{[]string{"--yolov2"}, 133519467574834, 133519467574834, params.YoloV2GenesisHash.Hex()},
}
for i, p := range chainIdentityCases {

Expand Down
4 changes: 2 additions & 2 deletions cmd/puppeth/wizard_genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ func (w *wizard) manageGenesis() {
w.conf.Genesis.Config.SetEIP145Transition(w.readDefaultUint64P(*w.conf.Genesis.Config.GetEIP145Transition()))

fmt.Println()
fmt.Printf("Which block should YOLOv1 (EIP2537) come into effect? (default = %v)\n", w.conf.Genesis.Config.GetEIP2537Transition())
w.conf.Genesis.Config.SetEIP2537Transition(w.readDefaultUint64P(*w.conf.Genesis.Config.GetEIP2537Transition()))
fmt.Printf("Which block should YOLOv2 come into effect? (default = %v)\n", w.conf.Genesis.Config.GetEIP2929Transition())
w.conf.Genesis.Config.SetEIP2929Transition(w.readDefaultUint64P(*w.conf.Genesis.Config.GetEIP2929Transition()))

out, _ := json.MarshalIndent(w.conf.Genesis.Config, "", " ")
fmt.Printf("Chain configuration updated:\n\n%s\n", out)
Expand Down
2 changes: 1 addition & 1 deletion cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ var (
}
NetworkIdFlag = cli.Uint64Flag{
Name: "networkid",
Usage: "Explicitly set network id (integer)(For testnets: use --ropsten, --rinkeby, --goerli, --kotti, --mordor, --yolov1 instead)",
Usage: "Explicitly set network id (integer)(For testnets: use --ropsten, --rinkeby, --goerli, --kotti, --mordor, --yolov2 instead)",
Value: eth.DefaultConfig.NetworkId,
}
ClassicFlag = cli.BoolFlag{
Expand Down
21 changes: 9 additions & 12 deletions core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,16 @@ func ApplyTransaction(config ctypes.ChainConfigurator, bc ChainContext, author *
// about the transaction and calling mechanisms.
vmenv := vm.NewEVM(context, statedb, config, cfg)

// TODO(meowsbits): re: YoloV2, EIP2929.
/*
if config.IsYoloV2(header.Number) {
statedb.AddAddressToAccessList(msg.From())
if dst := msg.To(); dst != nil {
statedb.AddAddressToAccessList(*dst)
// If it's a create-tx, the destination will be added inside evm.create
}
for _, addr := range vmenv.ActivePrecompiles() {
statedb.AddAddressToAccessList(addr)
}
if config.IsEnabled(config.GetEIP2929Transition, header.Number) {
statedb.AddAddressToAccessList(msg.From())
if dst := msg.To(); dst != nil {
statedb.AddAddressToAccessList(*dst)
// If it's a create-tx, the destination will be added inside evm.create
}
*/
for addr := range vm.PrecompiledContractsForConfig(config, header.Number) {
statedb.AddAddressToAccessList(addr)
}
}

// Apply the transaction to the current state (included in the env)
result, err := ApplyMessage(vmenv, msg, gp)
Expand Down
10 changes: 3 additions & 7 deletions core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,16 +404,12 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
nonce := evm.StateDB.GetNonce(caller.Address())
evm.StateDB.SetNonce(caller.Address(), nonce+1)

// TODO(meowsbits): Fix this, re: YoloV2.
// We add this to the access list _before_ taking a snapshot. Even if the creation fails,
// the access-list change should not be rolled back
/*
if evm.chainRules.IsYoloV2 {
evm.StateDB.AddAddressToAccessList(address)
}
if evm.ChainConfig().IsEnabled(evm.chainConfig.GetEIP2929Transition, evm.BlockNumber) {
evm.StateDB.AddAddressToAccessList(address)
}

*/
// Ensure there's no existing contract already at the designated address
contractHash := evm.StateDB.GetCodeHash(address)
if evm.StateDB.GetNonce(address) != 0 || (contractHash != (common.Hash{}) && contractHash != emptyCodeHash) {
Expand Down
19 changes: 7 additions & 12 deletions core/vm/jump_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,18 +179,13 @@ func instructionSetForConfig(config ctypes.ChainConfigurator, bn *big.Int) JumpT
enable2200(&instructionSet) // Net metered SSTORE - https://eips.ethereum.org/EIPS/eip-2200
}

// TODO(meowsbits):
/*
// newYoloV2InstructionSet creates an instructionset containing
// - "EIP-2315: Simple Subroutines"
// - "EIP-2929: Gas cost increases for state access opcodes"
func newYoloV2InstructionSet() JumpTable {
instructionSet := newIstanbulInstructionSet()
enable2315(&instructionSet) // Subroutines - https://eips.ethereum.org/EIPS/eip-2315
enable2929(&instructionSet) // Access lists for trie accesses https://eips.ethereum.org/EIPS/eip-2929
return instructionSet
}
*/
if config.IsEnabled(config.GetEIP2315Transition, bn) {
enable2315(&instructionSet) // Subroutines - https://eips.ethereum.org/EIPS/eip-2315
}

if config.IsEnabled(config.GetEIP2929Transition, bn) {
enable2929(&instructionSet) // Access lists for trie accesses https://eips.ethereum.org/EIPS/eip-2929
}

return instructionSet
}
Expand Down
45 changes: 18 additions & 27 deletions core/vm/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,14 @@ func Execute(code, input []byte, cfg *Config) ([]byte, *state.StateDB, error) {
vmenv = NewEnv(cfg)
sender = vm.AccountRef(cfg.Origin)
)
// TODO(meowsbits): re: EIP2929
/*
if cfg.ChainConfig.IsYoloV2(vmenv.BlockNumber) {
cfg.State.AddAddressToAccessList(cfg.Origin)
cfg.State.AddAddressToAccessList(address)
for _, addr := range vmenv.ActivePrecompiles() {
cfg.State.AddAddressToAccessList(addr)
cfg.State.AddAddressToAccessList(addr)
}
if cfg.ChainConfig.IsEnabled(cfg.ChainConfig.GetEIP2929Transition, vmenv.BlockNumber) {
cfg.State.AddAddressToAccessList(cfg.Origin)
cfg.State.AddAddressToAccessList(address)
for addr := range vm.PrecompiledContractsForConfig(cfg.ChainConfig, vmenv.BlockNumber) {
cfg.State.AddAddressToAccessList(addr)
}
*/
}

cfg.State.CreateAccount(address)
// set the receiver's (the executing contract) code for execution.
cfg.State.SetCode(address, code)
Expand Down Expand Up @@ -153,15 +150,12 @@ func Create(input []byte, cfg *Config) ([]byte, common.Address, uint64, error) {
vmenv = NewEnv(cfg)
sender = vm.AccountRef(cfg.Origin)
)
// TODO(meowsbits): re: EIP2929
/*
if cfg.ChainConfig.IsYoloV2(vmenv.BlockNumber) {
cfg.State.AddAddressToAccessList(cfg.Origin)
for _, addr := range vmenv.ActivePrecompiles() {
cfg.State.AddAddressToAccessList(addr)
}
if cfg.ChainConfig.IsEnabled(cfg.ChainConfig.GetEIP2929Transition, vmenv.BlockNumber) {
cfg.State.AddAddressToAccessList(cfg.Origin)
for addr := range vm.PrecompiledContractsForConfig(cfg.ChainConfig, vmenv.BlockNumber) {
cfg.State.AddAddressToAccessList(addr)
}
*/
}

// Call the code with the given configuration.
code, address, leftOverGas, err := vmenv.Create(
Expand All @@ -184,16 +178,13 @@ func Call(address common.Address, input []byte, cfg *Config) ([]byte, uint64, er
vmenv := NewEnv(cfg)

sender := cfg.State.GetOrNewStateObject(cfg.Origin)
// TODO(meowsbits): re: EIP2929
/*
if cfg.ChainConfig.IsYoloV2(vmenv.BlockNumber) {
cfg.State.AddAddressToAccessList(cfg.Origin)
cfg.State.AddAddressToAccessList(address)
for _, addr := range vmenv.ActivePrecompiles() {
cfg.State.AddAddressToAccessList(addr)
}
if cfg.ChainConfig.IsEnabled(cfg.ChainConfig.GetEIP2929Transition, vmenv.BlockNumber) {
cfg.State.AddAddressToAccessList(cfg.Origin)
cfg.State.AddAddressToAccessList(address)
for addr := range vm.PrecompiledContractsForConfig(cfg.ChainConfig, vmenv.BlockNumber) {
cfg.State.AddAddressToAccessList(addr)
}
*/
}

// Call the code with the given configuration.
ret, leftOverGas, err := vmenv.Call(
Expand Down
26 changes: 11 additions & 15 deletions eth/api_tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/ethereum/go-ethereum/eth/tracers"
"github.com/ethereum/go-ethereum/internal/ethapi"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params/types/ctypes"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/trie"
Expand Down Expand Up @@ -597,22 +598,17 @@ func (api *PrivateDebugAPI) standardTraceBlockToFile(ctx context.Context, block
// Therefore, it's perfectly valid to specify `"futureForkBlock": 0`, to enable `futureFork`

if config != nil && config.Overrides != nil {

// TODO(meowsbits): FIXME.

/*
// Copy the config, to not screw up the main config
// Note: the Clique-part is _not_ deep copied
chainConfigCopy := new(params.ChainConfig)
*chainConfigCopy = *chainConfig
chainConfig = chainConfigCopy
if yolov2 := config.Overrides.YoloV2Block; yolov2 != nil {
chainConfig.YoloV2Block = yolov2
canon = false
// Copy the config, to not screw up the main config
// Note: the Clique-part is _not_ deep copied
chainConfigCopy := new(ctypes.ChainConfigurator)
*chainConfigCopy = chainConfig
chainConfig = *chainConfigCopy
if eip2929 := config.Overrides.GetEIP2929Transition(); eip2929 != nil {
if err := chainConfig.SetEIP2929Transition(eip2929); err != nil {
return nil, err
}
*/
canon = false
}
}
for i, tx := range block.Transactions() {
// Prepare the trasaction for un-traced execution
Expand Down
20 changes: 20 additions & 0 deletions integration/configurator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"io/ioutil"
"log"
"path/filepath"
"strings"
"testing"

"github.com/davecgh/go-spew/spew"
Expand Down Expand Up @@ -126,6 +127,25 @@ func TestEquivalent_Features(t *testing.T) {
debuglog(oconf, mg)
}

// EIP2929 is unsupported by Parity (https://docs.google.com/spreadsheets/d/1BomvS0hjc88eTfx1b8Ufa6KYS3vMEb2c8TQ5HJWx2lc/edit#gid=408811124),
// which means they cannot support the following forks.
// So skip the Parity equivalence checks for them.
parityUnsupportedForks := []string{
"yolo",
"berlin",
}
paritySupports := func(forkName string) bool {
for _, s := range parityUnsupportedForks {
if strings.Contains(strings.ToLower(forkName), s) {
return false
}
}
return true
}
if !paritySupports(name) {
continue
}

pc := &parity.ParityChainSpec{}
err = confp.Convert(oconf, pc)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var (
RinkebyGenesisHash = common.HexToHash("0x6341fd3daf94b748c72ced5a5b26028f2474f5f00d824504e4fa37a75767e177")
GoerliGenesisHash = common.HexToHash("0xbf7e331f7f7c1dd2e05159666b3bf8bc7a8a3a9eb1d518969eab529dd9b88c1a")
// TODO: update with yolov2 values
YoloV2GenesisHash = common.HexToHash("0x498a7239036dd2cd09e2bb8a80922b78632017958c332b42044c250d603a8a3e")
YoloV2GenesisHash = common.HexToHash("0xc3fd235071f24f93865b0850bd2a2119b30f7224d18a0e34c7bbf549ad7e3d36")
)

// TrustedCheckpoints associates each known checkpoint with the genesis hash of
Expand Down Expand Up @@ -219,9 +219,9 @@ var (
Threshold: 2,
}

// YoloV2ChainConfig contains the chain parameters to run a node on the YOLOv1 test network.
// YoloV2ChainConfig contains the chain parameters to run a node on the YOLOv2 test network.
YoloV2ChainConfig = &goethereum.ChainConfig{
ChainID: big.NewInt(133519467574833),
ChainID: big.NewInt(133519467574834),
HomesteadBlock: big.NewInt(0),
DAOForkBlock: nil,
DAOForkSupport: true,
Expand Down
10 changes: 9 additions & 1 deletion params/types/coregeth/chain_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ type CoreGethChainConfig struct {
EIP1706FBlock *big.Int `json:"eip1706FBlock,omitempty"`

// https://github.com/ethereum/EIPs/pull/2537: BLS12-381 curve operations
EIP2537FBlock *big.Int `json:"eip2315FBlock,omitempty"`
EIP2537FBlock *big.Int `json:"eip2537FBlock,omitempty"`

//EWASMBlock *big.Int `json:"ewasmBlock,omitempty"` // EWASM switch block (nil = no fork, 0 = already activated)

Expand All @@ -176,6 +176,14 @@ type CoreGethChainConfig struct {
ECIP1099FBlock *big.Int `json:"ecip1099FBlock,omitempty"` // ECIP1099 etchash HF block
ECBP1100FBlock *big.Int `json:"ecbp1100FBlock,omitempty"` // ECBP1100:MESS artificial finality

// EIP-2315: Simple Subroutines
// https://eips.ethereum.org/EIPS/eip-2315
EIP2315FBlock *big.Int `json:"eip2315FBlock,omitempty"`

// EIP-2929: Gas cost increases for state access opcodes
// https://eips.ethereum.org/EIPS/eip-2929
EIP2929FBlock *big.Int `json:"eip2929FBlock,omitempty"`

DisposalBlock *big.Int `json:"disposalBlock,omitempty"` // Bomb disposal HF block
SocialBlock *big.Int `json:"socialBlock,omitempty"` // Ethereum Social Reward block
EthersocialBlock *big.Int `json:"ethersocialBlock,omitempty"` // Ethersocial Reward block
Expand Down
18 changes: 18 additions & 0 deletions params/types/coregeth/chain_config_configurator.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,24 @@ func (c *CoreGethChainConfig) SetECBP1100Transition(n *uint64) error {
return nil
}

func (c *CoreGethChainConfig) GetEIP2315Transition() *uint64 {
return bigNewU64(c.EIP2315FBlock)
}

func (c *CoreGethChainConfig) SetEIP2315Transition(n *uint64) error {
c.EIP2315FBlock = setBig(c.EIP2315FBlock, n)
return nil
}

func (c *CoreGethChainConfig) GetEIP2929Transition() *uint64 {
return bigNewU64(c.EIP2929FBlock)
}

func (c *CoreGethChainConfig) SetEIP2929Transition(n *uint64) error {
c.EIP2929FBlock = setBig(c.EIP2929FBlock, n)
return nil
}

func (c *CoreGethChainConfig) IsEnabled(fn func() *uint64, n *big.Int) bool {
f := fn()
if f == nil || n == nil {
Expand Down
Loading

0 comments on commit 760dd39

Please sign in to comment.