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

feat: implement Prague and Pascal for bsc #211

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 31 additions & 29 deletions Cargo.lock

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

34 changes: 17 additions & 17 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -625,20 +625,20 @@ tikv-jemallocator = "0.6"
tracy-client = "0.17.3"

[patch.crates-io]
revm = { git = "https://github.com/bnb-chain/revm", tag = "v1.0.6" }
revm-interpreter = { git = "https://github.com/bnb-chain/revm", tag = "v1.0.6" }
revm-primitives = { git = "https://github.com/bnb-chain/revm", tag = "v1.0.6" }
alloy-rpc-types-eth = { git = "https://github.com/bnb-chain/alloy", tag = "v1.0.3" }
alloy-consensus = { git = "https://github.com/bnb-chain/alloy", tag = "v1.0.3" }
alloy-eips = { git = "https://github.com/bnb-chain/alloy", tag = "v1.0.3" }
alloy-network = { git = "https://github.com/bnb-chain/alloy", tag = "v1.0.3" }
alloy-network-primitives = { git = "https://github.com/bnb-chain/alloy", tag = "v1.0.3" }
alloy-serde = { git = "https://github.com/bnb-chain/alloy", tag = "v1.0.3" }
alloy-signer = { git = "https://github.com/bnb-chain/alloy", tag = "v1.0.3" }
alloy-signer-local = { git = "https://github.com/bnb-chain/alloy", tag = "v1.0.3" }
alloy-provider = { git = "https://github.com/bnb-chain/alloy", tag = "v1.0.3" }
alloy-transport = { git = "https://github.com/bnb-chain/alloy", tag = "v1.0.3" }
alloy-transport-http = { git = "https://github.com/bnb-chain/alloy", tag = "v1.0.3" }
alloy-json-rpc = { git = "https://github.com/bnb-chain/alloy", tag = "v1.0.3" }
alloy-rpc-client = { git = "https://github.com/bnb-chain/alloy", tag = "v1.0.3" }
alloy-rpc-types-engine = { git = "https://github.com/bnb-chain/alloy", tag = "v1.0.3" }
revm = { git = "https://github.com/bnb-chain/revm", rev = "d24ce213417fdba02f15b18fd2d9bf0b099f060d" }
revm-interpreter = { git = "https://github.com/bnb-chain/revm", rev = "d24ce213417fdba02f15b18fd2d9bf0b099f060d" }
revm-primitives = { git = "https://github.com/bnb-chain/revm", rev = "d24ce213417fdba02f15b18fd2d9bf0b099f060d" }
alloy-rpc-types-eth = { git = "https://github.com/bnb-chain/alloy", rev = "e1e4a2d299350eb4210e89836e2ca8dce81f4004" }
alloy-consensus = { git = "https://github.com/bnb-chain/alloy", rev = "e1e4a2d299350eb4210e89836e2ca8dce81f4004" }
alloy-eips = { git = "https://github.com/bnb-chain/alloy", rev = "e1e4a2d299350eb4210e89836e2ca8dce81f4004" }
alloy-network = { git = "https://github.com/bnb-chain/alloy", rev = "e1e4a2d299350eb4210e89836e2ca8dce81f4004" }
alloy-network-primitives = { git = "https://github.com/bnb-chain/alloy", rev = "e1e4a2d299350eb4210e89836e2ca8dce81f4004" }
alloy-serde = { git = "https://github.com/bnb-chain/alloy", rev = "e1e4a2d299350eb4210e89836e2ca8dce81f4004" }
alloy-signer = { git = "https://github.com/bnb-chain/alloy", rev = "e1e4a2d299350eb4210e89836e2ca8dce81f4004" }
alloy-signer-local = { git = "https://github.com/bnb-chain/alloy", rev = "e1e4a2d299350eb4210e89836e2ca8dce81f4004" }
alloy-provider = { git = "https://github.com/bnb-chain/alloy", rev = "e1e4a2d299350eb4210e89836e2ca8dce81f4004" }
alloy-transport = { git = "https://github.com/bnb-chain/alloy", rev = "e1e4a2d299350eb4210e89836e2ca8dce81f4004" }
alloy-transport-http = { git = "https://github.com/bnb-chain/alloy", rev = "e1e4a2d299350eb4210e89836e2ca8dce81f4004" }
alloy-json-rpc = { git = "https://github.com/bnb-chain/alloy", rev = "e1e4a2d299350eb4210e89836e2ca8dce81f4004" }
alloy-rpc-client = { git = "https://github.com/bnb-chain/alloy", rev = "e1e4a2d299350eb4210e89836e2ca8dce81f4004" }
alloy-rpc-types-engine = { git = "https://github.com/bnb-chain/alloy", rev = "e1e4a2d299350eb4210e89836e2ca8dce81f4004" }
166 changes: 165 additions & 1 deletion crates/bsc/chainspec/res/genesis/bsc_rialto.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions crates/bsc/chainspec/src/bsc_rialto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ pub static BSC_RIALTO: Lazy<Arc<BscChainSpec>> = Lazy::new(|| {
genesis: serde_json::from_str(include_str!("../res/genesis/bsc_rialto.json"))
.expect("Can't deserialize BSC Rialto genesis json"),
genesis_hash: once_cell_set(b256!(
"281bcec9447d74982bb746f753eecd1320a9b7f4fdbd2cfaf1ae7170a93cff50"
"f58dd0f71313a12b473b50988ac7dd06cc9664aad3c8d7d3716ffaf680e305b4"
)),
paris_block_and_final_difficulty: Some((0, U256::from(0))),
hardforks: BscHardfork::bsc_qa(),
deposit_contract: None,
base_fee_params: BaseFeeParamsKind::Constant(BaseFeeParams::new(1, 1)),
base_fee_params: BaseFeeParamsKind::Constant(BaseFeeParams::ethereum()),
prune_delete_limit: 3500,
..Default::default()
},
Expand Down
8 changes: 8 additions & 0 deletions crates/bsc/consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,14 @@ impl Parlia {
return Err(ConsensusError::ParentBeaconBlockRootUnexpected)
}

if self.chain_spec.is_prague_active_at_timestamp(header.timestamp) {
if header.requests_hash.is_none() {
return Err(ConsensusError::RequestsHashMissing)
}
} else if header.requests_hash.is_some() {
return Err(ConsensusError::RequestsHashUnexpected)
}

Ok(())
}

Expand Down
16 changes: 10 additions & 6 deletions crates/bsc/consensus/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,16 @@ pub fn encode_header_with_chain_id(header: &Header, out: &mut dyn BufMut, chain_
Encodable::encode(&header.mix_hash, out);
Encodable::encode(&header.nonce, out);

if header.parent_beacon_block_root.is_some() &&
header.parent_beacon_block_root.unwrap() == B256::default()
{
if header.parent_beacon_block_root.is_some() {
Encodable::encode(&U256::from(header.base_fee_per_gas.unwrap()), out);
Encodable::encode(&header.withdrawals_root.unwrap(), out);
Encodable::encode(&header.blob_gas_used.unwrap(), out);
Encodable::encode(&header.excess_blob_gas.unwrap(), out);
Encodable::encode(&header.parent_beacon_block_root.unwrap(), out);

if header.requests_hash.is_some() {
Encodable::encode(&header.requests_hash.unwrap(), out);
}
}
}

Expand All @@ -82,14 +84,16 @@ fn rlp_header(header: &Header, chain_id: u64) -> alloy_rlp::Header {
rlp_head.payload_length += header.mix_hash.length(); // mix_hash
rlp_head.payload_length += header.nonce.length(); // nonce

if header.parent_beacon_block_root.is_some() &&
header.parent_beacon_block_root.unwrap() == B256::default()
{
if header.parent_beacon_block_root.is_some() {
rlp_head.payload_length += U256::from(header.base_fee_per_gas.unwrap()).length();
rlp_head.payload_length += header.withdrawals_root.unwrap().length();
rlp_head.payload_length += header.blob_gas_used.unwrap().length();
rlp_head.payload_length += header.excess_blob_gas.unwrap().length();
rlp_head.payload_length += header.parent_beacon_block_root.unwrap().length();

if header.requests_hash.is_some() {
rlp_head.payload_length += header.requests_hash.unwrap().length();
}
}
rlp_head
}
Expand Down
3 changes: 3 additions & 0 deletions crates/bsc/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ reth-bsc-primitives.workspace = true
alloy-consensus.workspace = true
alloy-genesis.workspace = true
alloy-primitives.workspace = true
alloy-eips.workspace = true
revm-primitives.workspace = true

# misc
Expand All @@ -49,6 +50,8 @@ blst = "0.3.12"
# async
tokio = { workspace = true, features = ["sync", "time"] }

derivative = "2.2"

[dev-dependencies]
reth-revm = { workspace = true, features = ["test-utils"] }
reth-provider = { workspace = true, features = ["test-utils"] }
Expand Down
12 changes: 10 additions & 2 deletions crates/bsc/evm/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ pub fn revm_spec_by_timestamp_after_shanghai(
chain_spec: &ChainSpec,
timestamp: u64,
) -> revm_primitives::SpecId {
if chain_spec.fork(BscHardfork::Bohr).active_at_timestamp(timestamp) {
if chain_spec.fork(BscHardfork::Pascal).active_at_timestamp(timestamp) ||
chain_spec.fork(EthereumHardfork::Prague).active_at_timestamp(timestamp)
{
revm_primitives::PRAGUE
} else if chain_spec.fork(BscHardfork::Bohr).active_at_timestamp(timestamp) {
revm_primitives::BOHR
} else if chain_spec.fork(BscHardfork::HaberFix).active_at_timestamp(timestamp) {
revm_primitives::HABER_FIX
Expand All @@ -29,7 +33,11 @@ pub fn revm_spec_by_timestamp_after_shanghai(

/// return `revm_spec` from spec configuration.
pub fn revm_spec(chain_spec: &ChainSpec, block: &Head) -> revm_primitives::SpecId {
if chain_spec.fork(BscHardfork::Bohr).active_at_head(block) {
if chain_spec.fork(BscHardfork::Pascal).active_at_head(block) ||
chain_spec.fork(EthereumHardfork::Prague).active_at_head(block)
{
revm_primitives::PRAGUE
} else if chain_spec.fork(BscHardfork::Bohr).active_at_head(block) {
revm_primitives::BOHR
} else if chain_spec.fork(BscHardfork::HaberFix).active_at_head(block) {
revm_primitives::HABER_FIX
Expand Down
Loading
Loading