From 8c9a76d3bc0c5bf7061654d1ec102647f4c9b745 Mon Sep 17 00:00:00 2001
From: ledgerwatch <akhounov@gmail.com>
Date: Tue, 4 May 2021 06:50:06 +0100
Subject: [PATCH] Add Baikal checks properly (#1868)

Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
---
 consensus/clique/verifier.go      | 4 ++--
 consensus/ethash/consensus.go     | 4 ++--
 core/blockchain.go                | 2 +-
 core/chain_makers.go              | 4 ++--
 core/genesis.go                   | 2 +-
 core/state_transition.go          | 8 ++++----
 core/types/transaction_signing.go | 2 +-
 core/vm/interpreter.go            | 4 ++--
 core/vm/jump_table.go             | 8 ++++----
 params/config.go                  | 4 ++--
 10 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/consensus/clique/verifier.go b/consensus/clique/verifier.go
index 6947c48496..ceb209e66a 100644
--- a/consensus/clique/verifier.go
+++ b/consensus/clique/verifier.go
@@ -106,8 +106,8 @@ func (c *Clique) verifyCascadingFields(chain consensus.ChainHeaderReader, header
 		return consensus.ErrUnknownAncestor
 	}
 	// Verify the header's EIP-1559 attributes.
-	if chain.Config().IsAleut(header.Number.Uint64()) {
-		if err := misc.VerifyEip1559Header(parent, header, chain.Config().IsAleut(parent.Number.Uint64())); err != nil {
+	if chain.Config().IsAleut(header.Number.Uint64()) || chain.Config().IsBaikal(header.Number.Uint64()) {
+		if err := misc.VerifyEip1559Header(parent, header, chain.Config().IsAleut(parent.Number.Uint64()) || chain.Config().IsBaikal(parent.Number.Uint64())); err != nil {
 			return err
 		}
 	}
diff --git a/consensus/ethash/consensus.go b/consensus/ethash/consensus.go
index 0d8a853551..4131fc8eee 100644
--- a/consensus/ethash/consensus.go
+++ b/consensus/ethash/consensus.go
@@ -270,8 +270,8 @@ func (ethash *Ethash) verifyHeader(chain consensus.ChainHeaderReader, header, pa
 		return fmt.Errorf("invalid gasLimit: have %v, max %v", header.GasLimit, cap)
 	}
 	// Verify the block's gas usage and (if applicable) verify the base fee.
-	if chain.Config().IsAleut(header.Number.Uint64()) {
-		if err := misc.VerifyEip1559Header(parent, header, chain.Config().IsAleut(parent.Number.Uint64())); err != nil {
+	if chain.Config().IsAleut(header.Number.Uint64()) || chain.Config().IsBaikal(header.Number.Uint64()) {
+		if err := misc.VerifyEip1559Header(parent, header, chain.Config().IsAleut(parent.Number.Uint64()) || chain.Config().IsBaikal(parent.Number.Uint64())); err != nil {
 			return err
 		}
 	} else {
diff --git a/core/blockchain.go b/core/blockchain.go
index c4faa70e1c..33440d96a6 100644
--- a/core/blockchain.go
+++ b/core/blockchain.go
@@ -540,7 +540,7 @@ func ExecuteBlockEphemerally(
 	var receipts types.Receipts
 	usedGas := new(uint64)
 	gp := new(GasPool)
-	if chainConfig.IsAleut(block.NumberU64()) {
+	if chainConfig.IsAleut(block.NumberU64()) || chainConfig.IsBaikal(block.NumberU64()) {
 		gp.AddGas(block.GasLimit() * params.ElasticityMultiplier)
 	} else {
 		gp.AddGas(block.GasLimit())
diff --git a/core/chain_makers.go b/core/chain_makers.go
index 135c184fdb..b1822811d7 100644
--- a/core/chain_makers.go
+++ b/core/chain_makers.go
@@ -363,10 +363,10 @@ func makeHeader(chain consensus.ChainReader, parent *types.Block, state *state.I
 		Time:     time,
 	}
 
-	if chain.Config().IsAleut(parent.Number().Uint64()) {
+	if chain.Config().IsAleut(parent.Number().Uint64()) || chain.Config().IsBaikal(parent.Number().Uint64()) {
 		header.BaseFee = misc.CalcBaseFee(parent.Header())
 		header.Eip1559 = true
-	} else if chain.Config().IsAleut(header.Number.Uint64()) {
+	} else if chain.Config().IsAleut(header.Number.Uint64()) || chain.Config().IsBaikal(header.Number.Uint64()) {
 		header.BaseFee = new(big.Int).SetUint64(params.InitialBaseFee)
 		header.Eip1559 = true
 	}
diff --git a/core/genesis.go b/core/genesis.go
index 8564a43d0c..7013b3507d 100644
--- a/core/genesis.go
+++ b/core/genesis.go
@@ -312,7 +312,7 @@ func (g *Genesis) ToBlock(history bool) (*types.Block, *state.IntraBlockState, e
 	if g.Difficulty == nil {
 		head.Difficulty = params.GenesisDifficulty
 	}
-	if g.Config != nil && g.Config.IsAleut(0) {
+	if g.Config != nil && (g.Config.IsAleut(0) || g.Config.IsBaikal(0)) {
 		head.Eip1559 = true
 		head.BaseFee = new(big.Int).SetUint64(params.InitialBaseFee)
 	}
diff --git a/core/state_transition.go b/core/state_transition.go
index 0a61e86164..b16e81b835 100644
--- a/core/state_transition.go
+++ b/core/state_transition.go
@@ -193,7 +193,7 @@ func (st *StateTransition) to() common.Address {
 
 func (st *StateTransition) buyGas(gasBailout bool) error {
 	price := st.gasPrice
-	if st.evm.ChainConfig().IsAleut(st.evm.Context.BlockNumber) {
+	if st.evm.ChainConfig().IsAleut(st.evm.Context.BlockNumber) || st.evm.ChainConfig().IsBaikal(st.evm.Context.BlockNumber) {
 		// price = min(tip, feeCap - baseFee) + baseFee
 		price = cmath.Min256(new(uint256.Int).Add(st.tip, st.evm.Context.BaseFee), st.feeCap)
 	}
@@ -229,7 +229,7 @@ func (st *StateTransition) preCheck(gasBailout bool) error {
 		}
 	}
 	// Make sure the transaction feeCap is greater than the block's baseFee.
-	if st.evm.ChainConfig().IsAleut(st.evm.Context.BlockNumber) {
+	if st.evm.ChainConfig().IsAleut(st.evm.Context.BlockNumber) || st.evm.ChainConfig().IsBaikal(st.evm.Context.BlockNumber) {
 		if st.feeCap.Cmp(st.evm.Context.BaseFee) < 0 {
 			return fmt.Errorf("%w: address %v, feeCap: %d baseFee: %d", ErrFeeCapTooLow,
 				st.msg.From().Hex(), st.feeCap.Uint64(), st.evm.Context.BaseFee.Uint64())
@@ -323,7 +323,7 @@ func (st *StateTransition) TransitionDb(refunds bool, gasBailout bool) (*Executi
 		}
 	}
 	price := st.gasPrice
-	if st.evm.ChainConfig().IsAleut(st.evm.Context.BlockNumber) {
+	if st.evm.ChainConfig().IsAleut(st.evm.Context.BlockNumber) || st.evm.ChainConfig().IsBaikal(st.evm.Context.BlockNumber) {
 		var feeDiff uint256.Int
 		if st.evm.Context.BaseFee.Lt(st.feeCap) {
 			feeDiff.Sub(st.feeCap, st.evm.Context.BaseFee)
@@ -349,7 +349,7 @@ func (st *StateTransition) refundGas(refundQuotient uint64) {
 
 	// Return ETH for remaining gas, exchanged at the original rate.
 	price := st.gasPrice
-	if st.evm.ChainConfig().IsAleut(st.evm.Context.BlockNumber) {
+	if st.evm.ChainConfig().IsAleut(st.evm.Context.BlockNumber) || st.evm.ChainConfig().IsBaikal(st.evm.Context.BlockNumber) {
 		// price = min(tip, feeCap - baseFee) + baseFee
 		price = cmath.Min256(new(uint256.Int).Add(st.tip, st.evm.Context.BaseFee), st.feeCap)
 	}
diff --git a/core/types/transaction_signing.go b/core/types/transaction_signing.go
index c6e552a2ab..3bb8aed82f 100644
--- a/core/types/transaction_signing.go
+++ b/core/types/transaction_signing.go
@@ -41,7 +41,7 @@ func MakeSigner(config *params.ChainConfig, blockNumber uint64) *Signer {
 	}
 	signer.unprotected = true
 	switch {
-	case config.IsAleut(blockNumber):
+	case config.IsAleut(blockNumber) || config.IsBaikal(blockNumber):
 		// All transaction types are still supported
 		signer.protected = true
 		signer.accesslist = true
diff --git a/core/vm/interpreter.go b/core/vm/interpreter.go
index 847384364f..5e0cacd46d 100644
--- a/core/vm/interpreter.go
+++ b/core/vm/interpreter.go
@@ -96,8 +96,8 @@ type EVMInterpreter struct {
 func NewEVMInterpreter(evm *EVM, cfg Config) *EVMInterpreter {
 	var jt *JumpTable
 	switch {
-	case evm.chainRules.IsAleut:
-		jt = &aleutInstructionSet
+	case evm.chainRules.IsAleut || evm.chainRules.IsBaikal:
+		jt = &londonInstructionSet
 	case evm.chainRules.IsBerlin:
 		jt = &berlinInstructionSet
 	case evm.chainRules.IsIstanbul:
diff --git a/core/vm/jump_table.go b/core/vm/jump_table.go
index b1ac48b70d..7658eae680 100644
--- a/core/vm/jump_table.go
+++ b/core/vm/jump_table.go
@@ -64,15 +64,15 @@ var (
 	constantinopleInstructionSet   = newConstantinopleInstructionSet()
 	istanbulInstructionSet         = newIstanbulInstructionSet()
 	berlinInstructionSet           = newBerlinInstructionSet()
-	aleutInstructionSet            = newAleutInstructionSet()
+	londonInstructionSet           = newLondonInstructionSet()
 )
 
 // JumpTable contains the EVM opcodes supported at a given fork.
 type JumpTable [256]*operation
 
-// newAleutInstructionSet returns the frontier, homestead, byzantium,
-// contantinople, istanbul, petersburg, berlin, and aleut instructions.
-func newAleutInstructionSet() JumpTable {
+// newLondonInstructionSet returns the frontier, homestead, byzantium,
+// contantinople, istanbul, petersburg, berlin, and london instructions.
+func newLondonInstructionSet() JumpTable {
 	instructionSet := newBerlinInstructionSet()
 	enable3198(&instructionSet) // Base fee opcode https://eips.ethereum.org/EIPS/eip-3198
 	return instructionSet
diff --git a/params/config.go b/params/config.go
index a90a196c54..62a9a9fc21 100644
--- a/params/config.go
+++ b/params/config.go
@@ -558,12 +558,12 @@ func (c *ChainConfig) IsBerlin(num uint64) bool {
 	return isForked(c.BerlinBlock, num)
 }
 
-// IsAleut returns whether num represents a block number after the Aleut fork
+// IsLondon returns whether num represents a block number after the Aleut fork
 func (c *ChainConfig) IsAleut(num uint64) bool {
 	return isForked(c.AleutBlock, num)
 }
 
-// IsBaikal returns whether num represents a block number after the Aleut fork
+// IsBaikal returns whether num represents a block number after the Baikal fork
 func (c *ChainConfig) IsBaikal(num uint64) bool {
 	return isForked(c.AleutBlock, num)
 }
-- 
GitLab