Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: enable Shanghai EIPs #1970

Merged
merged 3 commits into from
Nov 20, 2023
Merged

Conversation

buddh0
Copy link
Collaborator

@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
Collaborator 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

@@ -118,42 +118,40 @@ func TestFilters(t *testing.T) {
contract = common.Address{0xfe}
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
Collaborator 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

@@ -93,7 +93,7 @@ type testMatcher struct {
failpat []testFailure
skiploadpat []*regexp.Regexp
slowpat []*regexp.Regexp
runonlylistpat *regexp.Regexp
runonlylistpat []*regexp.Regexp
Copy link
Collaborator 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

@@ -300,7 +300,7 @@ func (t *StateTest) RunNoVerify(subtest StateSubtest, vmconfig vm.Config, snapsh
// And _now_ get the state root
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
Collaborator 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
Contributor

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

@buddh0
Copy link
Collaborator 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
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
Collaborator 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
Collaborator

@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

@brilliant-lx brilliant-lx merged commit 0224d48 into bnb-chain:develop Nov 20, 2023
5 checks passed
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
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