Skip to content

Commit

Permalink
Merge branch 'develop' into jt/eth-68
Browse files Browse the repository at this point in the history
  • Loading branch information
jonastheis authored Jun 27, 2024
2 parents 94961f9 + 418bc6f commit cf0a8ef
Show file tree
Hide file tree
Showing 15 changed files with 86 additions and 40 deletions.
3 changes: 3 additions & 0 deletions Dockerfile.mockccc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ RUN cd /go-ethereum && env GO111MODULE=on go run build/ci.go install ./cmd/geth
# Pull Geth into a second stage deploy alpine container
FROM ubuntu:20.04

RUN apt-get -qq update \
&& apt-get -qq install -y --no-install-recommends ca-certificates

ENV CGO_LDFLAGS="-ldl"

COPY --from=builder /go-ethereum/build/bin/geth /usr/local/bin/
Expand Down
2 changes: 1 addition & 1 deletion core/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3722,7 +3722,7 @@ func TestCurieTransition(t *testing.T) {
b, _ := json.Marshal(params.AllEthashProtocolChanges)
json.Unmarshal(b, &config)
config.CurieBlock = big.NewInt(2)
config.DescartesBlock = nil
config.DarwinTime = nil

var (
db = rawdb.NewMemoryDatabase()
Expand Down
2 changes: 1 addition & 1 deletion core/state_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestStateProcessorErrors(t *testing.T) {
ShanghaiBlock: big.NewInt(0),
BernoulliBlock: big.NewInt(0),
CurieBlock: big.NewInt(0),
DescartesBlock: big.NewInt(0),
DarwinTime: new(uint64),
Ethash: new(params.EthashConfig),
}
signer = types.LatestSigner(config)
Expand Down
2 changes: 1 addition & 1 deletion core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
var (
msg = st.msg
sender = vm.AccountRef(msg.From())
rules = st.evm.ChainConfig().Rules(st.evm.Context.BlockNumber)
rules = st.evm.ChainConfig().Rules(st.evm.Context.BlockNumber, st.evm.Context.Time.Uint64())
contractCreation = msg.To() == nil
)

Expand Down
2 changes: 1 addition & 1 deletion core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func NewEVM(blockCtx BlockContext, txCtx TxContext, statedb StateDB, chainConfig
StateDB: statedb,
Config: config,
chainConfig: chainConfig,
chainRules: chainConfig.Rules(blockCtx.BlockNumber),
chainRules: chainConfig.Rules(blockCtx.BlockNumber, blockCtx.Time.Uint64()),
}
evm.interpreter = NewEVMInterpreter(evm, config)
return evm
Expand Down
4 changes: 2 additions & 2 deletions core/vm/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ func NewEVMInterpreter(evm *EVM, cfg Config) *EVMInterpreter {
if cfg.JumpTable[STOP] == nil {
var jt JumpTable
switch {
case evm.chainRules.IsDescartes:
jt = descartesInstructionSet
case evm.chainRules.IsDarwin:
jt = darwinInstructionSet
case evm.chainRules.IsCurie:
jt = curieInstructionSet
case evm.chainRules.IsShanghai:
Expand Down
8 changes: 4 additions & 4 deletions core/vm/jump_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ var (
londonInstructionSet = newLondonInstructionSet()
shanghaiInstructionSet = newShanghaiInstructionSet()
curieInstructionSet = newCurieInstructionSet()
descartesInstructionSet = newDescartesInstructionSet()
darwinInstructionSet = newDarwinInstructionSet()
)

// JumpTable contains the EVM opcodes supported at a given fork.
type JumpTable [256]*operation

// newDescartesInstructionSet returns the frontier, homestead, byzantium,
// contantinople, istanbul, petersburg, berlin, london, shanghai, curie, and descartes instructions.
func newDescartesInstructionSet() JumpTable {
// newDarwinInstructionSet returns the frontier, homestead, byzantium,
// contantinople, istanbul, petersburg, berlin, london, shanghai, curie, and darwin instructions.
func newDarwinInstructionSet() JumpTable {
instructionSet := newCurieInstructionSet()
return instructionSet
}
Expand Down
8 changes: 4 additions & 4 deletions core/vm/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func setDefaults(cfg *Config) {
ShanghaiBlock: new(big.Int),
BernoulliBlock: new(big.Int),
CurieBlock: new(big.Int),
DescartesBlock: new(big.Int),
DarwinTime: new(uint64),
}
}

Expand Down Expand Up @@ -122,7 +122,7 @@ func Execute(code, input []byte, cfg *Config) ([]byte, *state.StateDB, error) {
address = common.BytesToAddress([]byte("contract"))
vmenv = NewEnv(cfg)
sender = vm.AccountRef(cfg.Origin)
rules = cfg.ChainConfig.Rules(vmenv.Context.BlockNumber)
rules = cfg.ChainConfig.Rules(vmenv.Context.BlockNumber, vmenv.Context.Time.Uint64())
)
// Execute the preparatory steps for state transition which includes:
// - prepare accessList(post-berlin)
Expand Down Expand Up @@ -156,7 +156,7 @@ func Create(input []byte, cfg *Config) ([]byte, common.Address, uint64, error) {
var (
vmenv = NewEnv(cfg)
sender = vm.AccountRef(cfg.Origin)
rules = cfg.ChainConfig.Rules(vmenv.Context.BlockNumber)
rules = cfg.ChainConfig.Rules(vmenv.Context.BlockNumber, vmenv.Context.Time.Uint64())
)
// Execute the preparatory steps for state transition which includes:
// - prepare accessList(post-berlin)
Expand Down Expand Up @@ -185,7 +185,7 @@ func Call(address common.Address, input []byte, cfg *Config) ([]byte, uint64, er
vmenv = NewEnv(cfg)
sender = cfg.State.GetOrNewStateObject(cfg.Origin)
statedb = cfg.State
rules = cfg.ChainConfig.Rules(vmenv.Context.BlockNumber)
rules = cfg.ChainConfig.Rules(vmenv.Context.BlockNumber, vmenv.Context.Time.Uint64())
)
// Execute the preparatory steps for state transition which includes:
// - prepare accessList(post-berlin)
Expand Down
2 changes: 1 addition & 1 deletion eth/gasprice/gasprice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func newTestBackend(t *testing.T, londonBlock *big.Int, pending bool, pendingTxC
config.ShanghaiBlock = londonBlock
config.BernoulliBlock = londonBlock
config.CurieBlock = londonBlock
config.DescartesBlock = londonBlock
config.DarwinTime = nil
engine := ethash.NewFaker()
db := rawdb.NewMemoryDatabase()
genesis, err := gspec.Commit(db)
Expand Down
2 changes: 1 addition & 1 deletion eth/tracers/js/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ func (jst *jsTracer) CaptureStart(env *vm.EVM, from common.Address, to common.Ad
jst.ctx["block"] = env.Context.BlockNumber.Uint64()
jst.dbWrapper.db = env.StateDB
// Update list of precompiles based on current block
rules := env.ChainConfig().Rules(env.Context.BlockNumber)
rules := env.ChainConfig().Rules(env.Context.BlockNumber, env.Context.Time.Uint64())
jst.activePrecompiles = vm.ActivePrecompiles(rules)

// Compute intrinsic gas
Expand Down
2 changes: 1 addition & 1 deletion eth/tracers/native/4byte.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (t *fourByteTracer) CaptureStart(env *vm.EVM, from common.Address, to commo
t.env = env

// Update list of precompiles based on current block
rules := env.ChainConfig().Rules(env.Context.BlockNumber)
rules := env.ChainConfig().Rules(env.Context.BlockNumber, env.Context.Time.Uint64())
t.activePrecompiles = vm.ActivePrecompiles(rules)

// Save the outer calldata also
Expand Down
2 changes: 1 addition & 1 deletion internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1492,7 +1492,7 @@ func AccessList(ctx context.Context, b Backend, blockNrOrHash rpc.BlockNumberOrH
to = crypto.CreateAddress(args.from(), uint64(*args.Nonce))
}
// Retrieve the precompiles since they don't need to be added to the access list
precompiles := vm.ActivePrecompiles(b.ChainConfig().Rules(header.Number))
precompiles := vm.ActivePrecompiles(b.ChainConfig().Rules(header.Number, header.Time))

// Create an initial tracer
prevTracer := vm.NewAccessListTracer(nil, args.from(), to, precompiles)
Expand Down
45 changes: 24 additions & 21 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ var (
ShanghaiBlock: nil,
BernoulliBlock: nil,
CurieBlock: nil,
DescartesBlock: nil,
DarwinTime: nil,
Clique: &CliqueConfig{
Period: 3,
Epoch: 30000,
Expand Down Expand Up @@ -320,7 +320,7 @@ var (
ShanghaiBlock: big.NewInt(0),
BernoulliBlock: big.NewInt(3747132),
CurieBlock: big.NewInt(4740239),
DescartesBlock: nil,
DarwinTime: nil,
Clique: &CliqueConfig{
Period: 3,
Epoch: 30000,
Expand Down Expand Up @@ -359,7 +359,7 @@ var (
ShanghaiBlock: big.NewInt(0),
BernoulliBlock: big.NewInt(5220340),
CurieBlock: big.NewInt(7096836),
DescartesBlock: nil,
DarwinTime: nil,
Clique: &CliqueConfig{
Period: 3,
Epoch: 30000,
Expand Down Expand Up @@ -404,7 +404,7 @@ var (
ShanghaiBlock: big.NewInt(0),
BernoulliBlock: big.NewInt(0),
CurieBlock: big.NewInt(0),
DescartesBlock: big.NewInt(0),
DarwinTime: new(uint64),
TerminalTotalDifficulty: nil,
Ethash: new(EthashConfig),
Clique: nil,
Expand Down Expand Up @@ -447,7 +447,7 @@ var (
ShanghaiBlock: big.NewInt(0),
BernoulliBlock: big.NewInt(0),
CurieBlock: big.NewInt(0),
DescartesBlock: big.NewInt(0),
DarwinTime: new(uint64),
TerminalTotalDifficulty: nil,
Ethash: nil,
Clique: &CliqueConfig{Period: 0, Epoch: 30000},
Expand Down Expand Up @@ -485,7 +485,7 @@ var (
ShanghaiBlock: big.NewInt(0),
BernoulliBlock: big.NewInt(0),
CurieBlock: big.NewInt(0),
DescartesBlock: big.NewInt(0),
DarwinTime: new(uint64),
TerminalTotalDifficulty: nil,
Ethash: new(EthashConfig),
Clique: nil,
Expand All @@ -501,7 +501,7 @@ var (
ScrollChainAddress: common.HexToAddress("0x0000000000000000000000000000000000000000"),
},
}}
TestRules = TestChainConfig.Rules(new(big.Int))
TestRules = TestChainConfig.Rules(new(big.Int), 0)

TestNoL1DataFeeChainConfig = &ChainConfig{
ChainID: big.NewInt(1),
Expand All @@ -524,7 +524,7 @@ var (
ShanghaiBlock: big.NewInt(0),
BernoulliBlock: big.NewInt(0),
CurieBlock: big.NewInt(0),
DescartesBlock: big.NewInt(0),
DarwinTime: new(uint64),
TerminalTotalDifficulty: nil,
Ethash: new(EthashConfig),
Clique: nil,
Expand Down Expand Up @@ -622,7 +622,7 @@ type ChainConfig struct {
ShanghaiBlock *big.Int `json:"shanghaiBlock,omitempty"` // Shanghai switch block (nil = no fork, 0 = already on shanghai)
BernoulliBlock *big.Int `json:"bernoulliBlock,omitempty"` // Bernoulli switch block (nil = no fork, 0 = already on bernoulli)
CurieBlock *big.Int `json:"curieBlock,omitempty"` // Curie switch block (nil = no fork, 0 = already on curie)
DescartesBlock *big.Int `json:"descartesBlock,omitempty"` // Descartes switch block (nil = no fork, 0 = already on descartes)
DarwinTime *uint64 `json:"darwinTime,omitempty"` // Darwin switch time (nil = no fork, 0 = already on darwin)

// TerminalTotalDifficulty is the amount of total difficulty reached by
// the network that triggers the consensus upgrade.
Expand Down Expand Up @@ -739,7 +739,7 @@ func (c *ChainConfig) String() string {
default:
engine = "unknown"
}
return fmt.Sprintf("{ChainID: %v Homestead: %v DAO: %v DAOSupport: %v EIP150: %v EIP155: %v EIP158: %v Byzantium: %v Constantinople: %v Petersburg: %v Istanbul: %v, Muir Glacier: %v, Berlin: %v, London: %v, Arrow Glacier: %v, Archimedes: %v, Shanghai: %v, Bernoulli: %v, Curie: %v, Descartes: %v, Engine: %v, Scroll config: %v}",
return fmt.Sprintf("{ChainID: %v Homestead: %v DAO: %v DAOSupport: %v EIP150: %v EIP155: %v EIP158: %v Byzantium: %v Constantinople: %v Petersburg: %v Istanbul: %v, Muir Glacier: %v, Berlin: %v, London: %v, Arrow Glacier: %v, Archimedes: %v, Shanghai: %v, Bernoulli: %v, Curie: %v, Darwin: %v, Engine: %v, Scroll config: %v}",
c.ChainID,
c.HomesteadBlock,
c.DAOForkBlock,
Expand All @@ -759,7 +759,7 @@ func (c *ChainConfig) String() string {
c.ShanghaiBlock,
c.BernoulliBlock,
c.CurieBlock,
c.DescartesBlock,
c.DarwinTime,
engine,
c.Scroll,
)
Expand Down Expand Up @@ -852,9 +852,9 @@ func (c *ChainConfig) IsCurie(num *big.Int) bool {
return isForked(c.CurieBlock, num)
}

// IsDescartes returns whether num is either equal to the Descartes fork block or greater.
func (c *ChainConfig) IsDescartes(num *big.Int) bool {
return isForked(c.DescartesBlock, num)
// IsDarwin returns whether num is either equal to the Darwin fork block or greater.
func (c *ChainConfig) IsDarwin(now uint64) bool {
return isForkedTime(now, c.DarwinTime)
}

// IsTerminalPoWBlock returns whether the given block is the last block of PoW stage.
Expand Down Expand Up @@ -910,7 +910,6 @@ func (c *ChainConfig) CheckConfigForkOrder() error {
{name: "shanghaiBlock", block: c.ShanghaiBlock, optional: true},
{name: "bernoulliBlock", block: c.BernoulliBlock, optional: true},
{name: "curieBlock", block: c.CurieBlock, optional: true},
{name: "descartesBlock", block: c.DescartesBlock, optional: true},
} {
if lastFork.name != "" {
// Next one must be higher number
Expand Down Expand Up @@ -995,9 +994,6 @@ func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, head *big.Int) *Confi
if isForkIncompatible(c.CurieBlock, newcfg.CurieBlock, head) {
return newCompatError("Curie fork block", c.CurieBlock, newcfg.CurieBlock)
}
if isForkIncompatible(c.DescartesBlock, newcfg.DescartesBlock, head) {
return newCompatError("Descartes fork block", c.DescartesBlock, newcfg.DescartesBlock)
}
return nil
}

Expand All @@ -1015,6 +1011,13 @@ func isForked(s, head *big.Int) bool {
return s.Cmp(head) <= 0
}

func isForkedTime(now uint64, forkTime *uint64) bool {
if forkTime == nil {
return false
}
return now >= *forkTime
}

func configNumEqual(x, y *big.Int) bool {
if x == nil {
return y == nil
Expand Down Expand Up @@ -1066,11 +1069,11 @@ type Rules struct {
IsHomestead, IsEIP150, IsEIP155, IsEIP158 bool
IsByzantium, IsConstantinople, IsPetersburg, IsIstanbul bool
IsBerlin, IsLondon, IsArchimedes, IsShanghai bool
IsBernoulli, IsCurie, IsDescartes bool
IsBernoulli, IsCurie, IsDarwin bool
}

// Rules ensures c's ChainID is not nil.
func (c *ChainConfig) Rules(num *big.Int) Rules {
func (c *ChainConfig) Rules(num *big.Int, time uint64) Rules {
chainID := c.ChainID
if chainID == nil {
chainID = new(big.Int)
Expand All @@ -1091,6 +1094,6 @@ func (c *ChainConfig) Rules(num *big.Int) Rules {
IsShanghai: c.IsShanghai(num),
IsBernoulli: c.IsBernoulli(num),
IsCurie: c.IsCurie(num),
IsDescartes: c.IsDescartes(num),
IsDarwin: c.IsDarwin(time),
}
}
40 changes: 40 additions & 0 deletions params/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"math/big"
"reflect"
"testing"

"github.com/stretchr/testify/require"
)

func TestCheckCompatible(t *testing.T) {
Expand Down Expand Up @@ -96,3 +98,41 @@ func TestCheckCompatible(t *testing.T) {
}
}
}

func TestIsForkedTime(t *testing.T) {
timePtr := func(t uint64) *uint64 {
return &t
}

tests := map[string]struct {
forkTime *uint64
now uint64
isForked bool
}{
"not configured": {
forkTime: nil,
isForked: false,
},
"before fork time": {
forkTime: timePtr(10),
now: 3,
isForked: false,
},
"on fork time": {
forkTime: timePtr(10),
now: 10,
isForked: true,
},
"after fork time": {
forkTime: timePtr(10),
now: 11,
isForked: true,
},
}

for desc, test := range tests {
t.Run(desc, func(t *testing.T) {
require.Equal(t, test.isForked, isForkedTime(test.now, test.forkTime))
})
}
}
2 changes: 1 addition & 1 deletion params/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
const (
VersionMajor = 5 // Major version component of the current release
VersionMinor = 5 // Minor version component of the current release
VersionPatch = 0 // Patch version component of the current release
VersionPatch = 1 // Patch version component of the current release
VersionMeta = "mainnet" // Version metadata to append to the version string
)

Expand Down

0 comments on commit cf0a8ef

Please sign in to comment.