Skip to content

Commit

Permalink
Merge pull request #561 from etclabscore/merge/foundation-release/1.1…
Browse files Browse the repository at this point in the history
…2.2+spiral

Merge/foundation release/1.12.2+spiral
  • Loading branch information
meowsbits authored Sep 5, 2023
2 parents 1433432 + 40a56aa commit f1d9db7
Show file tree
Hide file tree
Showing 26 changed files with 305 additions and 39 deletions.
6 changes: 6 additions & 0 deletions beacon/engine/gen_blockparams.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions beacon/engine/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
// be built.
type PayloadAttributes struct {
Timestamp uint64 `json:"timestamp" gencodec:"required"`
Number *uint64 `json:"blockNumber,omitempty"`
Random common.Hash `json:"prevRandao" gencodec:"required"`
SuggestedFeeRecipient common.Address `json:"suggestedFeeRecipient" gencodec:"required"`
Withdrawals []*types.Withdrawal `json:"withdrawals"`
Expand Down
4 changes: 2 additions & 2 deletions cmd/evm/internal/t8ntool/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func Transaction(ctx *cli.Context) error {
eip2f := chainConfig.IsEnabled(chainConfig.GetEIP2Transition, new(big.Int))
eip2028f := chainConfig.IsEnabled(chainConfig.GetEIP2028Transition, new(big.Int))
zero := uint64(0)
eip3860f := chainConfig.IsEnabledByTime(chainConfig.GetEIP3860TransitionTime, &zero)
eip3860f := chainConfig.IsEnabledByTime(chainConfig.GetEIP3860TransitionTime, &zero) || chainConfig.IsEnabled(chainConfig.GetEIP3860Transition, new(big.Int))

// Check intrinsic gas
if gas, err := core.IntrinsicGas(tx.Data(), tx.AccessList(), tx.To() == nil,
Expand Down Expand Up @@ -182,7 +182,7 @@ func Transaction(ctx *cli.Context) error {
}
// Check whether the init code size has been exceeded.
// EIP-3860: Limit and meter initcode
if chainConfig.IsEnabledByTime(chainConfig.GetEIP3860TransitionTime, &zero) && tx.To() == nil && uint64(len(tx.Data())) > vars.MaxInitCodeSize {
if (chainConfig.IsEnabledByTime(chainConfig.GetEIP3860TransitionTime, &zero) || chainConfig.IsEnabled(chainConfig.GetEIP3860Transition, new(big.Int))) && tx.To() == nil && uint64(len(tx.Data())) > vars.MaxInitCodeSize {
r.Error = errors.New("max initcode size exceeded")
}
results = append(results, r)
Expand Down
2 changes: 1 addition & 1 deletion cmd/evm/internal/t8ntool/transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func Transition(ctx *cli.Context) error {
}
}
// Withdrawals are only valid in Shanghai; EIP-4895.
if chainConfig.IsEnabledByTime(chainConfig.GetEIP4895TransitionTime, &prestate.Env.Number) && prestate.Env.Withdrawals == nil {
if (chainConfig.IsEnabledByTime(chainConfig.GetEIP4895TransitionTime, &prestate.Env.Timestamp) || chainConfig.IsEnabled(chainConfig.GetEIP4895Transition, new(big.Int).SetUint64(prestate.Env.Number))) && prestate.Env.Withdrawals == nil {
return NewError(ErrorConfig, errors.New("Shanghai config but missing 'withdrawals' in env section"))
}
isMerged := chainConfig.GetEthashTerminalTotalDifficulty() != nil && chainConfig.GetEthashTerminalTotalDifficulty().BitLen() == 0
Expand Down
4 changes: 2 additions & 2 deletions consensus/beacon/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func (beacon *Beacon) verifyHeader(chain consensus.ChainHeaderReader, header, pa
return err
}
// Verify existence / non-existence of withdrawalsHash.
shanghai := chain.Config().IsEnabledByTime(chain.Config().GetEIP4895TransitionTime, &header.Time)
shanghai := chain.Config().IsEnabledByTime(chain.Config().GetEIP4895TransitionTime, &header.Time) || chain.Config().IsEnabled(chain.Config().GetEIP4895Transition, header.Number)
if shanghai && header.WithdrawalsHash == nil {
return errors.New("missing withdrawalsHash")
}
Expand Down Expand Up @@ -362,7 +362,7 @@ func (beacon *Beacon) FinalizeAndAssemble(chain consensus.ChainHeaderReader, hea
if !beacon.IsPoSHeader(header) {
return beacon.ethone.FinalizeAndAssemble(chain, header, state, txs, uncles, receipts, nil)
}
shanghai := chain.Config().IsEnabledByTime(chain.Config().GetEIP4895TransitionTime, &header.Time)
shanghai := chain.Config().IsEnabledByTime(chain.Config().GetEIP4895TransitionTime, &header.Time) || chain.Config().IsEnabled(chain.Config().GetEIP4895Transition, header.Number)
if shanghai {
// All blocks after Shanghai must include a withdrawals root.
if withdrawals == nil {
Expand Down
2 changes: 1 addition & 1 deletion consensus/clique/clique.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ func (c *Clique) verifyHeader(chain consensus.ChainHeaderReader, header *types.H
if header.GasLimit > vars.MaxGasLimit {
return fmt.Errorf("invalid gasLimit: have %v, max %v", header.GasLimit, vars.MaxGasLimit)
}
if chain.Config().IsEnabledByTime(chain.Config().GetEIP3855TransitionTime, &header.Time) {
if chain.Config().IsEnabledByTime(chain.Config().GetEIP3855TransitionTime, &header.Time) || chain.Config().IsEnabled(chain.Config().GetEIP3855Transition, header.Number) {
return fmt.Errorf("clique does not support shanghai fork")
}
if chain.Config().IsEnabledByTime(chain.Config().GetEIP4844TransitionTime, &header.Time) {
Expand Down
2 changes: 1 addition & 1 deletion consensus/ethash/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func (ethash *Ethash) verifyHeader(chain consensus.ChainHeaderReader, header, pa
if diff := new(big.Int).Sub(header.Number, parent.Number); diff.Cmp(big.NewInt(1)) != 0 {
return consensus.ErrInvalidNumber
}
if chain.Config().IsEnabledByTime(chain.Config().GetEIP3860TransitionTime, &header.Time) {
if chain.Config().IsEnabledByTime(chain.Config().GetEIP3860TransitionTime, &header.Time) || chain.Config().IsEnabled(chain.Config().GetEIP3860Transition, header.Number) {
return fmt.Errorf("ethash does not support shanghai fork")
}
if chain.Config().IsEnabledByTime(chain.Config().GetEIP4844TransitionTime, &header.Time) {
Expand Down
18 changes: 9 additions & 9 deletions core/forkid/forkid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,21 +372,21 @@ func TestValidation(t *testing.T) {
// In this case we don't know if Cancun passed yet or not.
//
// TODO(karalabe): Enable this when Cancun is specced
//{params.MainnetChainConfig, 20000000, 1668000000, ID{Hash: checksumToBytes(0x71147644), Next: 0}, nil},
// {params.MainnetChainConfig, 20000000, 1668000000, ID{Hash: checksumToBytes(0x71147644), Next: 0}, nil},

// Local is mainnet currently in Shanghai only (so it's aware of Cancun), remote announces
// also Shanghai, and it's also aware of Cancun (e.g. updated node before the fork). We
// don't know if Cancun passed yet (will pass) or not.
//
// TODO(karalabe): Enable this when Cancun is specced and update next timestamp
//{params.MainnetChainConfig, 20000000, 1668000000, ID{Hash: checksumToBytes(0x71147644), Next: 1678000000}, nil},
// {params.MainnetChainConfig, 20000000, 1668000000, ID{Hash: checksumToBytes(0x71147644), Next: 1678000000}, nil},

// Local is mainnet currently in Shanghai only (so it's aware of Cancun), remote announces
// also Shanghai, and it's also aware of some random fork (e.g. misconfigured Cancun). As
// neither forks passed at neither nodes, they may mismatch, but we still connect for now.
//
// TODO(karalabe): Enable this when Cancun is specced
//{params.MainnetChainConfig, 20000000, 1668000000, ID{Hash: checksumToBytes(0x71147644), Next: math.MaxUint64}, nil},
// {params.MainnetChainConfig, 20000000, 1668000000, ID{Hash: checksumToBytes(0x71147644), Next: math.MaxUint64}, nil},

// Local is mainnet exactly on Cancun, remote announces Shanghai + knowledge about Cancun. Remote
// is simply out of sync, accept.
Expand All @@ -397,30 +397,30 @@ func TestValidation(t *testing.T) {
// Local is mainnet Cancun, remote announces Shanghai + knowledge about Cancun. Remote
// is simply out of sync, accept.
// TODO(karalabe): Enable this when Cancun is specced, update local head and time, next timestamp
//{params.MainnetChainConfig, 21123456, 1678123456, ID{Hash: checksumToBytes(0x71147644), Next: 1678000000}, nil},
// {params.MainnetChainConfig, 21123456, 1678123456, ID{Hash: checksumToBytes(0x71147644), Next: 1678000000}, nil},

// Local is mainnet Prague, remote announces Shanghai + knowledge about Cancun. Remote
// is definitely out of sync. It may or may not need the Prague update, we don't know yet.
//
// TODO(karalabe): Enable this when Cancun **and** Prague is specced, update all the numbers
//{params.MainnetChainConfig, 0, 0, ID{Hash: checksumToBytes(0x3edd5b10), Next: 4370000}, nil},
// {params.MainnetChainConfig, 0, 0, ID{Hash: checksumToBytes(0x3edd5b10), Next: 4370000}, nil},

// Local is mainnet Shanghai, remote announces Cancun. Local is out of sync, accept.
//
// TODO(karalabe): Enable this when Cancun is specced, update remote checksum
//{params.MainnetChainConfig, 21000000, 1678000000, ID{Hash: checksumToBytes(0x00000000), Next: 0}, nil},
// {params.MainnetChainConfig, 21000000, 1678000000, ID{Hash: checksumToBytes(0x00000000), Next: 0}, nil},

// Local is mainnet Shanghai, remote announces Cancun, but is not aware of Prague. Local
// out of sync. Local also knows about a future fork, but that is uncertain yet.
//
// TODO(karalabe): Enable this when Cancun **and** Prague is specced, update remote checksum
//{params.MainnetChainConfig, 21000000, 1678000000, ID{Hash: checksumToBytes(0x00000000), Next: 0}, nil},
// {params.MainnetChainConfig, 21000000, 1678000000, ID{Hash: checksumToBytes(0x00000000), Next: 0}, nil},

// Local is mainnet Cancun. remote announces Shanghai but is not aware of further forks.
// Remote needs software update.
//
// TODO(karalabe): Enable this when Cancun is specced, update local head and time
//{params.MainnetChainConfig, 21000000, 1678000000, ID{Hash: checksumToBytes(0x71147644), Next: 0}, ErrRemoteStale},
// {params.MainnetChainConfig, 21000000, 1678000000, ID{Hash: checksumToBytes(0x71147644), Next: 0}, ErrRemoteStale},

// Local is mainnet Shanghai, and isn't aware of more forks. Remote announces Shanghai +
// 0xffffffff. Local needs software update, reject.
Expand All @@ -430,7 +430,7 @@ func TestValidation(t *testing.T) {
// 0xffffffff. Local needs software update, reject.
//
// TODO(karalabe): Enable this when Cancun is specced, update remote checksum
//{params.MainnetChainConfig, 20000000, 1668000000, ID{Hash: checksumToBytes(checksumUpdate(0x00000000, math.MaxUint64)), Next: 0}, ErrLocalIncompatibleOrStale},
// {params.MainnetChainConfig, 20000000, 1668000000, ID{Hash: checksumToBytes(checksumUpdate(0x00000000, math.MaxUint64)), Next: 0}, ErrLocalIncompatibleOrStale},

// Local is mainnet Shanghai, remote is random Shanghai.
{params.MainnetChainConfig, 20000000, 1681338455, ID{Hash: checksumToBytes(0x12345678), Next: 0}, ErrLocalIncompatibleOrStale},
Expand Down
7 changes: 5 additions & 2 deletions core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, triedb *trie.Database, gen

applyOverrides := func(config ctypes.ChainConfigurator) {
if config != nil {
// Block-based overrides are not provided because Shanghai is
// ETH-network specific and that protocol is defined exclusively in time-based forks.
if overrides != nil && overrides.OverrideShanghai != nil {
config.SetEIP3651TransitionTime(overrides.OverrideShanghai)
config.SetEIP3855TransitionTime(overrides.OverrideShanghai)
Expand Down Expand Up @@ -436,8 +438,9 @@ func GenesisToBlock(g *genesisT.Genesis, db ethdb.Database) *types.Block {
}
var withdrawals []*types.Withdrawal
if conf := g.Config; conf != nil {
isShangai := conf.IsEnabledByTime(g.Config.GetEIP4895TransitionTime, &g.Timestamp)
if isShangai {
// EIP4895 defines the withdwrawals tx type, implemented on ETH in the Shanghai fork.
isEIP4895 := conf.IsEnabledByTime(g.Config.GetEIP4895TransitionTime, &g.Timestamp) || g.Config.IsEnabled(g.Config.GetEIP4895Transition, new(big.Int).SetUint64(g.Number))
if isEIP4895 {
head.WithdrawalsHash = &types.EmptyWithdrawalsHash
withdrawals = make([]*types.Withdrawal, 0)
}
Expand Down
2 changes: 1 addition & 1 deletion core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
// Fail if Shanghai not enabled and len(withdrawals) is non-zero.
withdrawals := block.Withdrawals()
blockTime := block.Time()
if len(withdrawals) > 0 && !p.config.IsEnabledByTime(p.config.GetEIP4895TransitionTime, &blockTime) {
if len(withdrawals) > 0 && !(p.config.IsEnabledByTime(p.config.GetEIP4895TransitionTime, &blockTime) || p.config.IsEnabled(p.config.GetEIP4895Transition, blockNumber)) {
return nil, nil, 0, fmt.Errorf("withdrawals before shanghai")
}
// Finalize the block, applying any consensus engine specific extras (e.g. block rewards)
Expand Down
4 changes: 2 additions & 2 deletions core/state_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ func GenerateBadBlock(parent *types.Block, engine consensus.Engine, txs types.Tr
if config.IsEnabled(config.GetEIP1559Transition, header.Number) {
header.BaseFee = eip1559.CalcBaseFee(config, parent.Header())
}
if config.IsEnabledByTime(config.GetEIP4895TransitionTime, &header.Time) {
if config.IsEnabledByTime(config.GetEIP4895TransitionTime, &header.Time) || config.IsEnabled(config.GetEIP4895Transition, header.Number) {
header.WithdrawalsHash = &types.EmptyWithdrawalsHash
}
var receipts []*types.Receipt
Expand Down Expand Up @@ -485,7 +485,7 @@ func GenerateBadBlock(parent *types.Block, engine consensus.Engine, txs types.Tr
header.BlobGasUsed = &used
}
// Assemble and return the final block for sealing
if config.IsEnabledByTime(config.GetEIP4895TransitionTime, &header.Time) {
if config.IsEnabledByTime(config.GetEIP4895TransitionTime, &header.Time) || config.IsEnabled(config.GetEIP4895Transition, header.Number) {
return types.NewBlockWithWithdrawals(header, txs, nil, receipts, []*types.Withdrawal{}, trie.NewStackTrie(nil))
}
return types.NewBlock(header, txs, nil, receipts, trie.NewStackTrie(nil))
Expand Down
6 changes: 4 additions & 2 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,10 +399,12 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
eip3529f = st.evm.ChainConfig().IsEnabled(st.evm.ChainConfig().GetEIP3529Transition, st.evm.Context.BlockNumber)

// EIP-3860: Limit and meter initcode
eip3860f = st.evm.ChainConfig().IsEnabledByTime(st.evm.ChainConfig().GetEIP3860TransitionTime, &st.evm.Context.Time)
eip3860f = st.evm.ChainConfig().IsEnabledByTime(st.evm.ChainConfig().GetEIP3860TransitionTime, &st.evm.Context.Time) ||
st.evm.ChainConfig().IsEnabled(st.evm.ChainConfig().GetEIP3860Transition, st.evm.Context.BlockNumber)

// EIP-3651: Warm coinbase
eip3651f = st.evm.ChainConfig().IsEnabledByTime(st.evm.ChainConfig().GetEIP3651TransitionTime, &st.evm.Context.Time)
eip3651f = st.evm.ChainConfig().IsEnabledByTime(st.evm.ChainConfig().GetEIP3651TransitionTime, &st.evm.Context.Time) ||
st.evm.ChainConfig().IsEnabled(st.evm.ChainConfig().GetEIP3651Transition, st.evm.Context.BlockNumber)
)

// Check clauses 4-5, subtract intrinsic gas if everything is correct
Expand Down
6 changes: 3 additions & 3 deletions core/vm/jump_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func instructionSetForConfig(config ctypes.ChainConfigurator, isPostMerge bool,
if config.IsEnabled(config.GetEIP3198Transition, bn) {
enable3198(instructionSet) // BASEFEE opcode https://eips.ethereum.org/EIPS/eip-3198
}
if isPostMerge {
if isPostMerge || config.IsEnabled(config.GetEIP4399Transition, bn) { // EIP4399: Supplant DIFFICULTY opcode with PREVRANDAO (ETH @ PoS)
instructionSet[PREVRANDAO] = &operation{
execute: opRandom,
constantGas: GasQuickStep,
Expand All @@ -203,10 +203,10 @@ func instructionSetForConfig(config ctypes.ChainConfigurator, isPostMerge bool,
}

// Shangai
if config.IsEnabledByTime(config.GetEIP3855TransitionTime, bt) {
if config.IsEnabledByTime(config.GetEIP3855TransitionTime, bt) || config.IsEnabled(config.GetEIP3855Transition, bn) {
enable3855(instructionSet) // PUSH0 instruction
}
if config.IsEnabledByTime(config.GetEIP3860TransitionTime, bt) {
if config.IsEnabledByTime(config.GetEIP3860TransitionTime, bt) || config.IsEnabled(config.GetEIP3860Transition, bn) {
enable3860(instructionSet) // Limit and meter initcode
}

Expand Down
9 changes: 6 additions & 3 deletions core/vm/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ func Execute(code, input []byte, cfg *Config) ([]byte, *state.StateDB, error) {

// Shanghai
// EIP-3651: Warm coinbase
eip3651f = cfg.ChainConfig.IsEnabledByTime(cfg.ChainConfig.GetEIP3651TransitionTime, &vmenv.Context.Time)
eip3651f = cfg.ChainConfig.IsEnabledByTime(cfg.ChainConfig.GetEIP3651TransitionTime, &vmenv.Context.Time) ||
cfg.ChainConfig.IsEnabled(cfg.ChainConfig.GetEIP3651Transition, vmenv.Context.BlockNumber)
)
// Execute the preparatory steps for state transition which includes:
// - prepare accessList(post-berlin)
Expand Down Expand Up @@ -165,7 +166,8 @@ func Create(input []byte, cfg *Config) ([]byte, common.Address, uint64, error) {

// Shanghai
// EIP-3651: Warm coinbase
eip3651f = cfg.ChainConfig.IsEnabledByTime(cfg.ChainConfig.GetEIP3651TransitionTime, &vmenv.Context.Time)
eip3651f = cfg.ChainConfig.IsEnabledByTime(cfg.ChainConfig.GetEIP3651TransitionTime, &vmenv.Context.Time) ||
cfg.ChainConfig.IsEnabled(cfg.ChainConfig.GetEIP3651Transition, vmenv.Context.BlockNumber)
)
// Execute the preparatory steps for state transition which includes:
// - prepare accessList(post-berlin)
Expand Down Expand Up @@ -200,7 +202,8 @@ func Call(address common.Address, input []byte, cfg *Config) ([]byte, uint64, er

// Shanghai
// EIP-3651: Warm coinbase
eip3651f = cfg.ChainConfig.IsEnabledByTime(cfg.ChainConfig.GetEIP3651TransitionTime, &vmenv.Context.Time)
eip3651f = cfg.ChainConfig.IsEnabledByTime(cfg.ChainConfig.GetEIP3651TransitionTime, &vmenv.Context.Time) ||
cfg.ChainConfig.IsEnabled(cfg.ChainConfig.GetEIP3651Transition, vmenv.Context.BlockNumber)
)
// Execute the preparatory steps for state transition which includes:
// - prepare accessList(post-berlin)
Expand Down
Loading

0 comments on commit f1d9db7

Please sign in to comment.