Skip to content

Commit afdbdfc

Browse files
feat: add extra data calculation (#691)
* feat: add extra data calculation * bump version * test: add extra data encoding tests
1 parent e027ec8 commit afdbdfc

File tree

7 files changed

+69
-16
lines changed

7 files changed

+69
-16
lines changed

Cargo.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ resolver = "2"
1212
default-members = ["node"]
1313

1414
[workspace.package]
15-
version = "1.21.8"
15+
version = "1.21.9"
1616
edition = "2024"
1717
repository = "https://github.com/NethermindEth/Catalyst"
1818
license = "MIT"

shasta/src/l1/execution_layer.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// TODO remove allow dead_code when the module is used
22
#![allow(dead_code)]
33

4+
use super::protocol_config::ProtocolConfig;
45
use crate::l1::config::ContractAddresses;
56
use alloy::primitives::Bytes;
67
use alloy::{eips::BlockNumberOrTag, primitives::Address, providers::DynProvider};
@@ -239,4 +240,20 @@ impl ExecutionLayer {
239240
pub async fn is_transaction_in_progress(&self) -> Result<bool, Error> {
240241
self.transaction_monitor.is_transaction_in_progress().await
241242
}
243+
244+
pub async fn fetch_protocol_config(&self) -> Result<ProtocolConfig, Error> {
245+
let shasta_inbox = IInbox::new(self.contract_addresses.shasta_inbox, self.provider.clone());
246+
let shasta_config = shasta_inbox
247+
.getConfig()
248+
.call()
249+
.await
250+
.map_err(|e| anyhow::anyhow!("Failed to call getConfig for Inbox: {e}"))?;
251+
252+
info!(
253+
"Shasta config: basefeeSharingPctg: {}",
254+
shasta_config.basefeeSharingPctg,
255+
);
256+
257+
Ok(ProtocolConfig::from(&shasta_config))
258+
}
242259
}

shasta/src/l1/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ pub mod config;
33
pub mod event_indexer;
44
pub mod execution_layer;
55
pub mod proposal_tx_builder;
6+
pub mod protocol_config;

shasta/src/l1/protocol_config.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use taiko_bindings::i_inbox::IInbox::Config;
2+
3+
#[derive(Clone, Default)]
4+
pub struct ProtocolConfig {
5+
basefee_sharing_pctg: u8,
6+
}
7+
8+
impl ProtocolConfig {
9+
pub fn from(shasta_config: &Config) -> Self {
10+
Self {
11+
basefee_sharing_pctg: shasta_config.basefeeSharingPctg,
12+
}
13+
}
14+
15+
pub fn get_basefee_sharing_pctg(&self) -> u8 {
16+
self.basefee_sharing_pctg
17+
}
18+
}

shasta/src/l2/taiko.rs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#![allow(dead_code)]
33

44
use super::execution_layer::L2ExecutionLayer;
5+
use crate::l1::protocol_config::ProtocolConfig;
56
use crate::utils::proposal::Proposal;
67
use alloy::{
78
consensus::BlockHeader,
@@ -25,7 +26,6 @@ use common::{
2526
l2_tx_lists::{self, PreBuiltTxList},
2627
},
2728
};
28-
use pacaya::l1::protocol_config::ProtocolConfig;
2929
use pacaya::l2::config::TaikoConfig;
3030
use std::{sync::Arc, time::Duration};
3131
use tracing::{debug, trace};
@@ -85,7 +85,7 @@ impl Taiko {
8585
.get_pending_l2_tx_list(
8686
base_fee,
8787
batches_ready_to_send,
88-
self.get_protocol_config().get_block_max_gas_limit(),
88+
15000000, // TODO fix gas limit
8989
)
9090
.await
9191
}
@@ -252,8 +252,6 @@ impl Taiko {
252252

253253
let timestamp = proposal.get_last_block_timestamp()?;
254254

255-
let sharing_pctg = 0; // TODO
256-
257255
let anchor_tx = self
258256
.l2_execution_layer
259257
.construct_anchor_tx(proposal, l2_slot_info)
@@ -263,12 +261,14 @@ impl Taiko {
263261
.collect::<Vec<_>>();
264262

265263
let tx_list_bytes = l2_tx_lists::encode_and_compress(&tx_list)?;
266-
let extra_data = vec![sharing_pctg];
264+
265+
let sharing_pctg = self.protocol_config.get_basefee_sharing_pctg();
266+
let extra_data = Self::encode_extra_data(sharing_pctg, false);
267267

268268
let executable_data = ExecutableData {
269269
base_fee_per_gas: l2_slot_info.base_fee(),
270270
block_number: l2_slot_info.parent_id() + 1,
271-
extra_data: format!("0x{:0>64}", hex::encode(extra_data)),
271+
extra_data: format!("0x{:0>64x}", extra_data),
272272
fee_recipient: proposal.coinbase.to_string(),
273273
gas_limit: 241_000_000u64,
274274
parent_hash: format!("0x{}", hex::encode(l2_slot_info.parent_hash())),
@@ -286,6 +286,10 @@ impl Taiko {
286286
.preconf_blocks(request_body, operation_type)
287287
.await
288288
}
289+
290+
fn encode_extra_data(basefee_sharing_pctg: u8, is_low_bond_proposal: bool) -> u16 {
291+
u16::from(basefee_sharing_pctg) << 8 | u16::from(is_low_bond_proposal)
292+
}
289293
}
290294

291295
impl Bridgeable for Taiko {
@@ -308,3 +312,16 @@ impl Bridgeable for Taiko {
308312
.await
309313
}
310314
}
315+
316+
mod tests {
317+
#[test]
318+
fn test_encode_extra_data() {
319+
use super::Taiko;
320+
321+
let extra_data = Taiko::encode_extra_data(30, true);
322+
assert_eq!(extra_data, 0b00011110_00000001);
323+
324+
let extra_data = Taiko::encode_extra_data(50, false);
325+
assert_eq!(extra_data, 0b00110010_00000000);
326+
}
327+
}

shasta/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ pub async fn create_shasta_node(
5959
taiko_config.signer.get_address(),
6060
)?)
6161
.map_err(|e| anyhow::anyhow!("Failed to create L2Engine: {}", e))?;
62+
let protocol_config = ethereum_l1.execution_layer.fetch_protocol_config().await?;
6263

6364
let taiko = crate::l2::taiko::Taiko::new(
6465
ethereum_l1.slot_clock.clone(),
65-
// TODO fetch actual protocol config
66-
pacaya::l1::protocol_config::ProtocolConfig::default(),
66+
protocol_config,
6767
metrics.clone(),
6868
taiko_config,
6969
l2_engine,

0 commit comments

Comments
 (0)