From ac34cc9f609b20ded6f271a68d0cfab63c2fc4cb Mon Sep 17 00:00:00 2001 From: blxdyx Date: Tue, 24 Sep 2024 17:44:12 +0800 Subject: [PATCH 1/9] fix integration test --- Makefile | 1 + tests/0001-diff-go-ethereum.patch | 67 +++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 tests/0001-diff-go-ethereum.patch diff --git a/Makefile b/Makefile index acc2a7218e0..d255a33dd11 100644 --- a/Makefile +++ b/Makefile @@ -166,6 +166,7 @@ db-tools: @echo "Run \"$(GOBIN)/mdbx_stat -h\" to get info about mdbx db file." test-erigon-lib: + @git apply tests/0001-diff-go-ethereum.patch @cd erigon-lib && $(MAKE) test test-erigon-ext: diff --git a/tests/0001-diff-go-ethereum.patch b/tests/0001-diff-go-ethereum.patch new file mode 100644 index 00000000000..b1459843871 --- /dev/null +++ b/tests/0001-diff-go-ethereum.patch @@ -0,0 +1,67 @@ +From 32329440626abd6e9668c2d5bd2e7b719e951e01 Mon Sep 17 00:00:00 2001 +From: NathanBSC +Date: Wed, 31 Jul 2024 15:01:28 +0800 +Subject: [PATCH] diff go ethereum + +--- + core/vm/contracts.go | 10 ---------- + core/vm/jump_table.go | 2 +- + params/protocol_params.go | 2 +- + 3 files changed, 2 insertions(+), 12 deletions(-) + +diff --git a/core/vm/contracts.go b/core/vm/contracts.go +index 38a6cac24..7eb29c3ed 100644 +--- a/core/vm/contracts.go ++++ b/core/vm/contracts.go +@@ -84,9 +84,6 @@ var PrecompiledContractsIstanbul = map[common.Address]PrecompiledContract{ + common.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{}, + common.BytesToAddress([]byte{8}): &bn256PairingIstanbul{}, + common.BytesToAddress([]byte{9}): &blake2F{}, +- +- common.BytesToAddress([]byte{100}): &tmHeaderValidate{}, +- common.BytesToAddress([]byte{101}): &iavlMerkleProofValidate{}, + } + + var PrecompiledContractsNano = map[common.Address]PrecompiledContract{ +@@ -239,13 +236,6 @@ var PrecompiledContractsCancun = map[common.Address]PrecompiledContract{ + common.BytesToAddress([]byte{8}): &bn256PairingIstanbul{}, + common.BytesToAddress([]byte{9}): &blake2F{}, + common.BytesToAddress([]byte{0x0a}): &kzgPointEvaluation{}, +- +- common.BytesToAddress([]byte{100}): &tmHeaderValidate{}, +- common.BytesToAddress([]byte{101}): &iavlMerkleProofValidatePlato{}, +- common.BytesToAddress([]byte{102}): &blsSignatureVerify{}, +- common.BytesToAddress([]byte{103}): &cometBFTLightBlockValidateHertz{}, +- common.BytesToAddress([]byte{104}): &verifyDoubleSignEvidence{}, +- common.BytesToAddress([]byte{105}): &secp256k1SignatureRecover{}, + } + + // PrecompiledContractsHaber contains the default set of pre-compiled Ethereum +diff --git a/core/vm/jump_table.go b/core/vm/jump_table.go +index 70c543f14..65716f944 100644 +--- a/core/vm/jump_table.go ++++ b/core/vm/jump_table.go +@@ -91,7 +91,7 @@ func newCancunInstructionSet() JumpTable { + } + + func newShanghaiInstructionSet() JumpTable { +- instructionSet := newLondonInstructionSet() ++ instructionSet := newMergeInstructionSet() + enable3855(&instructionSet) // PUSH0 instruction + enable3860(&instructionSet) // Limit and meter initcode + +diff --git a/params/protocol_params.go b/params/protocol_params.go +index 65b2d942c..bb085512f 100644 +--- a/params/protocol_params.go ++++ b/params/protocol_params.go +@@ -23,7 +23,7 @@ import ( + ) + + const ( +- GasLimitBoundDivisor uint64 = 256 // The bound divisor of the gas limit, used in update calculations. ++ GasLimitBoundDivisor uint64 = 1024 // The bound divisor of the gas limit, used in update calculations. + MinGasLimit uint64 = 5000 // Minimum the gas limit may ever be. + MaxGasLimit uint64 = 0x7fffffffffffffff // Maximum the gas limit (2^63-1). + GenesisGasLimit uint64 = 4712388 // Gas limit of the Genesis block. +-- +2.41.0 From 6d387e9593e99734d8e0deafd7366f2723565058 Mon Sep 17 00:00:00 2001 From: blxdyx Date: Tue, 24 Sep 2024 18:17:41 +0800 Subject: [PATCH 2/9] fix integration test --- Makefile | 1 - core/vm/contracts.go | 17 ++++++++ core/vm/evm.go | 6 ++- tests/0001-diff-go-ethereum.patch | 67 ------------------------------- 4 files changed, 22 insertions(+), 69 deletions(-) delete mode 100644 tests/0001-diff-go-ethereum.patch diff --git a/Makefile b/Makefile index d255a33dd11..acc2a7218e0 100644 --- a/Makefile +++ b/Makefile @@ -166,7 +166,6 @@ db-tools: @echo "Run \"$(GOBIN)/mdbx_stat -h\" to get info about mdbx db file." test-erigon-lib: - @git apply tests/0001-diff-go-ethereum.patch @cd erigon-lib && $(MAKE) test test-erigon-ext: diff --git a/core/vm/contracts.go b/core/vm/contracts.go index 02b52a7807f..e436752037b 100644 --- a/core/vm/contracts.go +++ b/core/vm/contracts.go @@ -169,6 +169,19 @@ var PrecompiledContractsCancun = map[libcommon.Address]PrecompiledContract{ libcommon.BytesToAddress([]byte{0x08}): &bn256PairingIstanbul{}, libcommon.BytesToAddress([]byte{0x09}): &blake2F{}, libcommon.BytesToAddress([]byte{0x0a}): &pointEvaluation{}, +} + +var PrecompiledContractsCancunForBsc = map[libcommon.Address]PrecompiledContract{ + libcommon.BytesToAddress([]byte{0x01}): &ecrecover{}, + libcommon.BytesToAddress([]byte{0x02}): &sha256hash{}, + libcommon.BytesToAddress([]byte{0x03}): &ripemd160hash{}, + libcommon.BytesToAddress([]byte{0x04}): &dataCopy{}, + libcommon.BytesToAddress([]byte{0x05}): &bigModExp{eip2565: true}, + libcommon.BytesToAddress([]byte{0x06}): &bn256AddIstanbul{}, + libcommon.BytesToAddress([]byte{0x07}): &bn256ScalarMulIstanbul{}, + libcommon.BytesToAddress([]byte{0x08}): &bn256PairingIstanbul{}, + libcommon.BytesToAddress([]byte{0x09}): &blake2F{}, + libcommon.BytesToAddress([]byte{0x0a}): &pointEvaluation{}, libcommon.BytesToAddress([]byte{100}): &tmHeaderValidate{}, libcommon.BytesToAddress([]byte{101}): &iavlMerkleProofValidatePlato{}, @@ -340,6 +353,7 @@ var ( PrecompiledAddressesPrague []libcommon.Address PrecompiledAddressesNapoli []libcommon.Address PrecompiledAddressesCancun []libcommon.Address + PrecompiledAddressesCancunForBSC []libcommon.Address PrecompiledAddressesBerlin []libcommon.Address PrecompiledAddressesIstanbul []libcommon.Address PrecompiledAddressesIstanbulForBSC []libcommon.Address @@ -387,6 +401,9 @@ func init() { for k := range PrecompiledContractsCancun { PrecompiledAddressesCancun = append(PrecompiledAddressesCancun, k) } + for k := range PrecompiledContractsCancunForBsc { + PrecompiledAddressesCancun = append(PrecompiledAddressesCancunForBSC, k) + } for k := range PrecompiledContractsHaber { PrecompiledAddressesHaber = append(PrecompiledAddressesHaber, k) } diff --git a/core/vm/evm.go b/core/vm/evm.go index 92ade30771f..7d6c7e8303b 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -47,7 +47,11 @@ func (evm *EVM) precompile(addr libcommon.Address) (PrecompiledContract, bool) { case evm.chainRules.IsHaber: precompiles = PrecompiledContractsHaber case evm.chainRules.IsCancun: - precompiles = PrecompiledContractsCancun + if evm.chainRules.IsParlia { + precompiles = PrecompiledContractsCancunForBsc + } else { + precompiles = PrecompiledContractsCancun + } case evm.chainRules.IsFeynman: precompiles = PrecompiledContractsFeynman case evm.chainRules.IsHertz: diff --git a/tests/0001-diff-go-ethereum.patch b/tests/0001-diff-go-ethereum.patch deleted file mode 100644 index b1459843871..00000000000 --- a/tests/0001-diff-go-ethereum.patch +++ /dev/null @@ -1,67 +0,0 @@ -From 32329440626abd6e9668c2d5bd2e7b719e951e01 Mon Sep 17 00:00:00 2001 -From: NathanBSC -Date: Wed, 31 Jul 2024 15:01:28 +0800 -Subject: [PATCH] diff go ethereum - ---- - core/vm/contracts.go | 10 ---------- - core/vm/jump_table.go | 2 +- - params/protocol_params.go | 2 +- - 3 files changed, 2 insertions(+), 12 deletions(-) - -diff --git a/core/vm/contracts.go b/core/vm/contracts.go -index 38a6cac24..7eb29c3ed 100644 ---- a/core/vm/contracts.go -+++ b/core/vm/contracts.go -@@ -84,9 +84,6 @@ var PrecompiledContractsIstanbul = map[common.Address]PrecompiledContract{ - common.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{}, - common.BytesToAddress([]byte{8}): &bn256PairingIstanbul{}, - common.BytesToAddress([]byte{9}): &blake2F{}, -- -- common.BytesToAddress([]byte{100}): &tmHeaderValidate{}, -- common.BytesToAddress([]byte{101}): &iavlMerkleProofValidate{}, - } - - var PrecompiledContractsNano = map[common.Address]PrecompiledContract{ -@@ -239,13 +236,6 @@ var PrecompiledContractsCancun = map[common.Address]PrecompiledContract{ - common.BytesToAddress([]byte{8}): &bn256PairingIstanbul{}, - common.BytesToAddress([]byte{9}): &blake2F{}, - common.BytesToAddress([]byte{0x0a}): &kzgPointEvaluation{}, -- -- common.BytesToAddress([]byte{100}): &tmHeaderValidate{}, -- common.BytesToAddress([]byte{101}): &iavlMerkleProofValidatePlato{}, -- common.BytesToAddress([]byte{102}): &blsSignatureVerify{}, -- common.BytesToAddress([]byte{103}): &cometBFTLightBlockValidateHertz{}, -- common.BytesToAddress([]byte{104}): &verifyDoubleSignEvidence{}, -- common.BytesToAddress([]byte{105}): &secp256k1SignatureRecover{}, - } - - // PrecompiledContractsHaber contains the default set of pre-compiled Ethereum -diff --git a/core/vm/jump_table.go b/core/vm/jump_table.go -index 70c543f14..65716f944 100644 ---- a/core/vm/jump_table.go -+++ b/core/vm/jump_table.go -@@ -91,7 +91,7 @@ func newCancunInstructionSet() JumpTable { - } - - func newShanghaiInstructionSet() JumpTable { -- instructionSet := newLondonInstructionSet() -+ instructionSet := newMergeInstructionSet() - enable3855(&instructionSet) // PUSH0 instruction - enable3860(&instructionSet) // Limit and meter initcode - -diff --git a/params/protocol_params.go b/params/protocol_params.go -index 65b2d942c..bb085512f 100644 ---- a/params/protocol_params.go -+++ b/params/protocol_params.go -@@ -23,7 +23,7 @@ import ( - ) - - const ( -- GasLimitBoundDivisor uint64 = 256 // The bound divisor of the gas limit, used in update calculations. -+ GasLimitBoundDivisor uint64 = 1024 // The bound divisor of the gas limit, used in update calculations. - MinGasLimit uint64 = 5000 // Minimum the gas limit may ever be. - MaxGasLimit uint64 = 0x7fffffffffffffff // Maximum the gas limit (2^63-1). - GenesisGasLimit uint64 = 4712388 // Gas limit of the Genesis block. --- -2.41.0 From a5c3b977d4f3adfe01837400d7c47c5c7991061a Mon Sep 17 00:00:00 2001 From: blxdyx Date: Tue, 24 Sep 2024 19:05:59 +0800 Subject: [PATCH 3/9] fix integration test --- core/chain_makers.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/chain_makers.go b/core/chain_makers.go index 96fba3c5cf9..c707d278c2f 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -586,8 +586,9 @@ func MakeEmptyHeader(parent *types.Header, chainConfig *chain.Config, timestamp // Set baseFee and GasLimit if we are on an EIP-1559 chain if chainConfig.IsLondon(header.Number.Uint64()) { header.BaseFee = misc.CalcBaseFee(chainConfig, parent) - if !chainConfig.IsLondon(parent.Number.Uint64()) { + if chainConfig.Parlia == nil && !chainConfig.IsLondon(parent.Number.Uint64()) { parentGasLimit = parent.GasLimit * params.ElasticityMultiplier + parentGasLimit = CalcGasLimit(parentGasLimit, parentGasLimit) } } if targetGasLimit != nil { From fdebd8ef1f6188496f6751915ebaaf71f4cb6441 Mon Sep 17 00:00:00 2001 From: blxdyx Date: Tue, 24 Sep 2024 19:31:02 +0800 Subject: [PATCH 4/9] fix integration test --- core/chain_makers.go | 1 - 1 file changed, 1 deletion(-) diff --git a/core/chain_makers.go b/core/chain_makers.go index c707d278c2f..f2f7bc1c581 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -588,7 +588,6 @@ func MakeEmptyHeader(parent *types.Header, chainConfig *chain.Config, timestamp header.BaseFee = misc.CalcBaseFee(chainConfig, parent) if chainConfig.Parlia == nil && !chainConfig.IsLondon(parent.Number.Uint64()) { parentGasLimit = parent.GasLimit * params.ElasticityMultiplier - parentGasLimit = CalcGasLimit(parentGasLimit, parentGasLimit) } } if targetGasLimit != nil { From 835dcac287c4296be5b64010f41db10565051c6d Mon Sep 17 00:00:00 2001 From: blxdyx Date: Tue, 24 Sep 2024 20:12:18 +0800 Subject: [PATCH 5/9] fix integration test --- core/vm/contracts.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/core/vm/contracts.go b/core/vm/contracts.go index e436752037b..9f20d092b3b 100644 --- a/core/vm/contracts.go +++ b/core/vm/contracts.go @@ -402,13 +402,13 @@ func init() { PrecompiledAddressesCancun = append(PrecompiledAddressesCancun, k) } for k := range PrecompiledContractsCancunForBsc { - PrecompiledAddressesCancun = append(PrecompiledAddressesCancunForBSC, k) + PrecompiledAddressesCancunForBSC = append(PrecompiledAddressesCancunForBSC, k) } for k := range PrecompiledContractsHaber { PrecompiledAddressesHaber = append(PrecompiledAddressesHaber, k) } for k := range PrecompiledContractsNapoli { - PrecompiledAddressesPrague = append(PrecompiledAddressesNapoli, k) + PrecompiledAddressesNapoli = append(PrecompiledAddressesNapoli, k) } for k := range PrecompiledContractsPrague { PrecompiledAddressesPrague = append(PrecompiledAddressesPrague, k) @@ -425,6 +425,9 @@ func ActivePrecompiles(rules *chain.Rules) []libcommon.Address { case rules.IsHaber: return PrecompiledAddressesHaber case rules.IsCancun: + if rules.IsParlia { + return PrecompiledAddressesCancunForBSC + } return PrecompiledAddressesCancun case rules.IsFeynman: return PrecompiledAddressesFeynman From fca8b8fcbaf5db57661c3e90f4def510abb717c6 Mon Sep 17 00:00:00 2001 From: blxdyx Date: Tue, 24 Sep 2024 21:38:52 +0800 Subject: [PATCH 6/9] fix integration test --- core/chain_makers.go | 2 +- core/state_transition.go | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/core/chain_makers.go b/core/chain_makers.go index f2f7bc1c581..96fba3c5cf9 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -586,7 +586,7 @@ func MakeEmptyHeader(parent *types.Header, chainConfig *chain.Config, timestamp // Set baseFee and GasLimit if we are on an EIP-1559 chain if chainConfig.IsLondon(header.Number.Uint64()) { header.BaseFee = misc.CalcBaseFee(chainConfig, parent) - if chainConfig.Parlia == nil && !chainConfig.IsLondon(parent.Number.Uint64()) { + if !chainConfig.IsLondon(parent.Number.Uint64()) { parentGasLimit = parent.GasLimit * params.ElasticityMultiplier } } diff --git a/core/state_transition.go b/core/state_transition.go index 6f9b9a1a29d..d79c356cf6a 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -505,6 +505,13 @@ func (st *StateTransition) TransitionDb(refunds bool, gasBailout bool) (*evmtype } else { st.state.AddBalance(coinbase, amount, tracing.BalanceIncreaseRewardTransactionFee) } + if !msg.IsFree() && rules.IsLondon { + burntContractAddress := st.evm.ChainConfig().GetBurntContract(st.evm.Context.BlockNumber) + if burntContractAddress != nil { + burnAmount := new(uint256.Int).Mul(new(uint256.Int).SetUint64(st.gasUsed()), st.evm.Context.BaseFee) + st.state.AddBalance(*burntContractAddress, burnAmount, tracing.BalanceChangeUnspecified) + } + } result := &evmtypes.ExecutionResult{ UsedGas: st.gasUsed(), From 7ac21312347a1b434150673b7bfb1a3bc3ba9742 Mon Sep 17 00:00:00 2001 From: blxdyx Date: Tue, 24 Sep 2024 23:55:07 +0800 Subject: [PATCH 7/9] fix integration test --- core/chain_makers.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/chain_makers.go b/core/chain_makers.go index 96fba3c5cf9..6bf72f43d44 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -401,7 +401,7 @@ func GenerateChain(config *chain.Config, parent *types.Block, engine consensus.E // Recreating block to make sure Root makes it into the header block := types.NewBlockForAsembling(b.header, b.txs, b.uncles, b.receipts, nil /* withdrawals */, nil /*requests*/) - if config.IsCancun(block.Number().Uint64(), block.Time()) { + if config.Parlia != nil && config.IsCancun(block.Number().Uint64(), block.Time()) { block = block.WithSidecars(b.sidecars) } return block, b.receipts, nil From c9c4a9a62f2eb11732d57c076fe792bc68145e1e Mon Sep 17 00:00:00 2001 From: blxdyx Date: Wed, 25 Sep 2024 09:54:41 +0800 Subject: [PATCH 8/9] fix integration test --- erigon-lib/chain/chain_config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erigon-lib/chain/chain_config.go b/erigon-lib/chain/chain_config.go index cc92bfefd0d..b406bf24445 100644 --- a/erigon-lib/chain/chain_config.go +++ b/erigon-lib/chain/chain_config.go @@ -802,7 +802,7 @@ func (c *Config) Rules(num uint64, time uint64) *Rules { IsBohr: c.IsBohr(num, time), IsOsaka: c.IsOsaka(time), IsAura: c.Aura != nil, - IsParlia: true, + IsParlia: c.Parlia != nil, } } From e18a0eccc02169bd0defb322fdb1b6c569866d0c Mon Sep 17 00:00:00 2001 From: blxdyx Date: Wed, 25 Sep 2024 10:19:44 +0800 Subject: [PATCH 9/9] fix integration test --- core/chain_makers.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/chain_makers.go b/core/chain_makers.go index 6bf72f43d44..96fba3c5cf9 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -401,7 +401,7 @@ func GenerateChain(config *chain.Config, parent *types.Block, engine consensus.E // Recreating block to make sure Root makes it into the header block := types.NewBlockForAsembling(b.header, b.txs, b.uncles, b.receipts, nil /* withdrawals */, nil /*requests*/) - if config.Parlia != nil && config.IsCancun(block.Number().Uint64(), block.Time()) { + if config.IsCancun(block.Number().Uint64(), block.Time()) { block = block.WithSidecars(b.sidecars) } return block, b.receipts, nil