Skip to content

Commit

Permalink
feat: enable bsc Prague and Pascal
Browse files Browse the repository at this point in the history
  • Loading branch information
j75689 committed Jan 16, 2025
1 parent 137d7b3 commit d5f5027
Show file tree
Hide file tree
Showing 67 changed files with 444 additions and 83 deletions.
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

0 comments on commit d5f5027

Please sign in to comment.