Skip to content

core: enable Shanghai EIPs#1970

Merged
brilliant-lx merged 3 commits intobnb-chain:developfrom
buddh0:shanghai_hardfork
Nov 20, 2023
Merged

core: enable Shanghai EIPs#1970
brilliant-lx merged 3 commits intobnb-chain:developfrom
buddh0:shanghai_hardfork

Conversation

@buddh0
Copy link
Copy Markdown
Contributor

@buddh0 buddh0 commented Nov 6, 2023

Description

core: enable Shanghai EIPs

Rationale

more compatible with ethereum/evm, 6 points need to check

  1. BEP-216: Implement EIP 3855 PUSH0 instruction
  2. BEP-217: Implement EIP3860 Limit and meter initcode
  3. BEP-311: Implement EIP-3651 Warm COINBASE
  4. BEP-312: Announce EIP-6049 Deprecate SELFDESTRUCT
  5. disable EIP-4895 after code upstream
  6. use time based hardfork

Example

  1. to disable EIP-4895, need confirm 3 points:
    a. Parlia.FinalizeAndAssemble ignore Withdrawals
    b. Parlia.verifyHeader ensure header.WithdrawalsHash == nil
    c. ValidateBody ensure block.Withdrawals()==nil
  2. test BEP-216, BEP-217 and BEP-310
    reuse handreds of test cases in https://github.com/ethereum/tests
cd bsc
git submodule update --init --depth 1 --recursive
cd tests
go test -run TestBlockchain -v
go test -run TestState -v
  1. because consensus/parlia: hardfork block can be epoch block, so Shanghai can use time based hardfork

PS: BEP-312 just used as a way to announce, no code need to change

Changes

Notable changes:

  • add each change in a bullet point here
  • ...

return new(big.Int).SetUint64(params.InitialBaseFee)
}

// If the current block is the first EIP-1559 block, return the InitialBaseFee.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useful to reuse test caes in ./tests

contract2 = common.Address{0xff}
abiStr = `[{"inputs":[],"name":"log0","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"t1","type":"uint256"}],"name":"log1","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"t1","type":"uint256"},{"internalType":"uint256","name":"t2","type":"uint256"}],"name":"log2","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"t1","type":"uint256"},{"internalType":"uint256","name":"t2","type":"uint256"},{"internalType":"uint256","name":"t3","type":"uint256"}],"name":"log3","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"t1","type":"uint256"},{"internalType":"uint256","name":"t2","type":"uint256"},{"internalType":"uint256","name":"t3","type":"uint256"},{"internalType":"uint256","name":"t4","type":"uint256"}],"name":"log4","outputs":[],"stateMutability":"nonpayable","type":"function"}]`
// BaseFee in BSC is 0 now, use 1Gwei instead for test here to avoid 0 gasPrice
gasPrice1Gwei = big.NewInt(params.GWei)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because we change logic in func CalcBaseFee
so we revert this test case, and keep it align with go-ethereum

skiploadpat []*regexp.Regexp
slowpat []*regexp.Regexp
runonlylistpat *regexp.Regexp
runonlylistpat []*regexp.Regexp
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make runonlylistpat is a list of patterns, so we can add more than one pattern

root := statedb.IntermediateRoot(config.IsEIP158(block.Number()))
statedb.SetExpectedStateRoot(root)
root, _, err = statedb.Commit(block.NumberU64(), nil)
root, _, _ = statedb.Commit(block.NumberU64(), nil)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep align with go-ethereum,
otherwise some cases will fail

@Mister-EA
Copy link
Copy Markdown
Contributor

Are we enabling the running of the testcases under ./tests somewhere?

@buddh0
Copy link
Copy Markdown
Contributor Author

buddh0 commented Nov 7, 2023

Are we enabling the running of the testcases under ./tests somewhere?

when bsc fork from go-ethereum, many cases in ./tests failed, so they are exclude from unit test at the birth of bsc.
there are hundreds of thousands in ./tests.
in this PR , I will include cases in ./tests, but with limited cases

@buddh0 buddh0 added the r4r ready for review label Nov 8, 2023
@emailtovamos
Copy link
Copy Markdown
Contributor

Which parts specifically refer to enabling Shanghai EIPs apart from the instructionSet code change? I see changes in tests and String() but couldn't quite understand the portions which actually turn Shanghai ON.

@buddh0
Copy link
Copy Markdown
Contributor Author

buddh0 commented Nov 17, 2023

Which parts specifically refer to enabling Shanghai EIPs apart from the instructionSet code change? I see changes in tests and String() but couldn't quite understand the portions which actually turn Shanghai ON.

define ShanghaiTime in ChapelChainConfig and BSCChainConfig,
but the real time is not determined, it will be filled upon the release for the kepler hardfork

Copy link
Copy Markdown
Contributor

@brilliant-lx brilliant-lx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bnb-alexlucaci bnb-alexlucaci self-requested a review November 20, 2023 11:17
@brilliant-lx brilliant-lx merged commit 0224d48 into bnb-chain:develop Nov 20, 2023
weiihann pushed a commit to weiihann/bsc that referenced this pull request Dec 5, 2023
@buddh0 buddh0 deleted the shanghai_hardfork branch December 12, 2023 02:21
ziogaschr added a commit to ziogaschr/bsc that referenced this pull request Jun 27, 2025
ziogaschr added a commit to coredao-org/core-chain that referenced this pull request Jun 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

r4r ready for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants