diff --git a/Cargo.lock b/Cargo.lock index 58f5034e..9c1455ba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -148,6 +148,7 @@ dependencies = [ "hex-literal", "itoa", "ruint", + "serde", "tiny-keccak", ] @@ -2333,6 +2334,9 @@ name = "hex" version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +dependencies = [ + "serde", +] [[package]] name = "hex-literal" diff --git a/Cargo.toml b/Cargo.toml index 7a607b6e..1ca3e452 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,7 @@ futures-timer = "0.3.0" again = "0.1" # Alloy types -alloy-primitives = { version = "0.7.1", default-features = false } +alloy-primitives = { version = "0.7.1", default-features = false, features = ["serde"] } # Logging and Metrics chrono = "0.4.22" diff --git a/src/common/attributes_deposited.rs b/src/common/attributes_deposited.rs index f0d13b12..c07d87f6 100644 --- a/src/common/attributes_deposited.rs +++ b/src/common/attributes_deposited.rs @@ -96,9 +96,9 @@ impl AttributesDepositedCall { let hash = B256::from_slice(&calldata[cursor..cursor + 32]); cursor += 32; - let seq_num = U256::from_be_slice(calldata[cursor..cursor + 32].try_into()?); + let sequence_number = U256::from_be_slice(calldata[cursor..cursor + 32].try_into()?); // down-casting to u64 is safe for the sequence number - let seq_num = seq_num + let sequence_number = sequence_number .try_into() .map_err(|_| eyre::eyre!("invalid sequence number"))?; cursor += 32; @@ -116,7 +116,7 @@ impl AttributesDepositedCall { timestamp, basefee, hash, - sequence_number: seq_num, + sequence_number, batcher_hash, fee_overhead, fee_scalar, diff --git a/src/common/mod.rs b/src/common/mod.rs index 59d23489..a4789eee 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -1,7 +1,8 @@ use std::fmt::Debug; +use alloy_primitives::B256; use ethers::{ - types::{Block, Transaction, H256}, + types::{Block, Transaction}, utils::rlp::{Decodable, DecoderError, Rlp}, }; use eyre::Result; @@ -18,11 +19,11 @@ pub use attributes_deposited::AttributesDepositedCall; #[derive(Debug, Clone, Copy, Eq, PartialEq, Default, Serialize, Deserialize)] pub struct BlockInfo { /// The block hash - pub hash: H256, + pub hash: B256, /// The block number pub number: u64, /// The parent block hash - pub parent_hash: H256, + pub parent_hash: B256, /// The block timestamp pub timestamp: u64, } @@ -37,7 +38,7 @@ pub struct Epoch { /// The block number pub number: u64, /// The block hash - pub hash: H256, + pub hash: B256, /// The block timestamp pub timestamp: u64, } @@ -45,12 +46,12 @@ pub struct Epoch { impl From for Value { fn from(value: BlockInfo) -> Value { let mut dict = Dict::new(); - dict.insert("hash".to_string(), Value::from(value.hash.as_bytes())); + dict.insert("hash".to_string(), Value::from(value.hash.as_slice())); dict.insert("number".to_string(), Value::from(value.number)); dict.insert("timestamp".to_string(), Value::from(value.timestamp)); dict.insert( "parent_hash".to_string(), - Value::from(value.parent_hash.as_bytes()), + Value::from(value.parent_hash.as_slice()), ); Value::Dict(Tag::Default, dict) } @@ -70,8 +71,8 @@ impl TryFrom> for BlockInfo { Ok(BlockInfo { number, - hash, - parent_hash: block.parent_hash, + hash: B256::from_slice(hash.as_bytes()), + parent_hash: B256::from_slice(block.parent_hash.as_bytes()), timestamp: block.timestamp.as_u64(), }) } @@ -80,7 +81,7 @@ impl TryFrom> for BlockInfo { impl From for Value { fn from(value: Epoch) -> Self { let mut dict = Dict::new(); - dict.insert("hash".to_string(), Value::from(value.hash.as_bytes())); + dict.insert("hash".to_string(), Value::from(value.hash.as_slice())); dict.insert("number".to_string(), Value::from(value.number)); dict.insert("timestamp".to_string(), Value::from(value.timestamp)); Value::Dict(Tag::Default, dict) @@ -92,8 +93,8 @@ impl From<&ExecutionPayload> for BlockInfo { fn from(value: &ExecutionPayload) -> Self { Self { number: value.block_number.as_u64(), - hash: value.block_hash, - parent_hash: value.parent_hash, + hash: B256::from_slice(value.block_hash.as_bytes()), + parent_hash: B256::from_slice(value.parent_hash.as_bytes()), timestamp: value.timestamp.as_u64(), } } @@ -105,7 +106,7 @@ impl From<&AttributesDepositedCall> for Epoch { Self { number: call.number, timestamp: call.timestamp, - hash: H256::from_slice(call.hash.as_slice()), + hash: B256::from_slice(call.hash.as_slice()), } } } diff --git a/src/config/mod.rs b/src/config/mod.rs index c80a4fb5..b0d02e39 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -1,6 +1,6 @@ use std::{fmt, iter, path::PathBuf, process::exit, str::FromStr}; -use ethers::types::{Address, H256, U256}; +use alloy_primitives::{Address, B256, U256}; use figment::{ providers::{Format, Serialized, Toml}, Figment, @@ -209,12 +209,12 @@ pub struct SystemConfig { } impl SystemConfig { - /// Encodes batch sender as a H256 - pub fn batcher_hash(&self) -> H256 { - let mut batch_sender_bytes = self.batch_sender.as_bytes().to_vec(); + /// Encodes batch sender as a [B256]. + pub fn batcher_hash(&self) -> B256 { + let mut batch_sender_bytes = self.batch_sender.as_slice().to_vec(); let mut batcher_hash = iter::repeat(0).take(12).collect::>(); batcher_hash.append(&mut batch_sender_bytes); - H256::from_slice(&batcher_hash) + B256::from_slice(&batcher_hash) } } @@ -445,7 +445,7 @@ impl ChainConfig { l2_genesis: BlockInfo { hash: hash("0xf712aa9241cc24369b143cf6dce85f0902a9731e70d66818a3a5845b296c73dd"), number: 0, - parent_hash: H256::zero(), + parent_hash: B256::ZERO, timestamp: 1686789347, }, system_config: SystemConfig { @@ -485,7 +485,7 @@ impl ChainConfig { l2_genesis: BlockInfo { hash: hash("0xa3ab140f15ea7f7443a4702da64c10314eb04d488e72974e02e2d728096b4f76"), number: 0, - parent_hash: H256::zero(), + parent_hash: B256::ZERO, timestamp: 1675193616, }, system_config: SystemConfig { @@ -525,7 +525,7 @@ impl ChainConfig { l2_genesis: BlockInfo { hash: hash("0x0dcc9e089e30b90ddfc55be9a37dd15bc551aeee999d2e2b51414c54eaf934e4"), number: 0, - parent_hash: H256::zero(), + parent_hash: B256::ZERO, timestamp: 1695768288, }, system_config: SystemConfig { @@ -569,8 +569,8 @@ fn addr(s: &str) -> Address { } /// Converts a [str] to a [H256]. -fn hash(s: &str) -> H256 { - H256::from_str(s).unwrap() +fn hash(s: &str) -> B256 { + B256::from_str(s).unwrap() } /// Returns default blocktime of 2 (seconds). @@ -635,9 +635,9 @@ struct SystemConfigInfo { #[serde(rename = "batcherAddr")] batcher_addr: Address, /// The current L1 fee overhead to apply to L2 transactions cost computation. Unused after Ecotone hard fork. - overhead: H256, + overhead: B256, /// The current L1 fee scalar to apply to L2 transactions cost computation. Unused after Ecotone hard fork. - scalar: H256, + scalar: B256, /// The gas limit for L2 blocks #[serde(rename = "gasLimit")] gas_limit: u64, @@ -647,7 +647,7 @@ struct SystemConfigInfo { #[derive(Debug, Clone, Serialize, Deserialize)] struct ChainGenesisInfo { /// Genesis block number - hash: H256, + hash: B256, /// Genesis block hash number: u64, } @@ -667,15 +667,15 @@ impl From for ChainConfig { l2_genesis: BlockInfo { hash: external.genesis.l2.hash, number: external.genesis.l2.number, - parent_hash: H256::zero(), + parent_hash: B256::ZERO, timestamp: external.genesis.l2_time, }, system_config: SystemConfig { batch_sender: external.genesis.system_config.batcher_addr, gas_limit: U256::from(external.genesis.system_config.gas_limit), - l1_fee_overhead: external.genesis.system_config.overhead.0.into(), - l1_fee_scalar: external.genesis.system_config.scalar.0.into(), - unsafe_block_signer: Address::zero(), + l1_fee_overhead: external.genesis.system_config.overhead.into(), + l1_fee_scalar: external.genesis.system_config.scalar.into(), + unsafe_block_signer: Address::ZERO, }, batch_inbox: external.batch_inbox_address, deposit_contract: external.deposit_contract_address, @@ -698,18 +698,6 @@ impl From for ExternalChainConfig { /// Converts [ChainConfig] into [ExternalChainConfig] /// which is the format used in ``rollup.json`` by `op-node` fn from(chain_config: ChainConfig) -> Self { - let mut overhead = [0; 32]; - let mut scalar = [0; 32]; - - chain_config - .system_config - .l1_fee_overhead - .to_big_endian(&mut overhead); - chain_config - .system_config - .l1_fee_scalar - .to_big_endian(&mut scalar); - Self { genesis: ExternalGenesisInfo { l1: ChainGenesisInfo { @@ -723,9 +711,9 @@ impl From for ExternalChainConfig { l2_time: chain_config.l2_genesis.timestamp, system_config: SystemConfigInfo { batcher_addr: chain_config.system_config.batch_sender, - overhead: H256::from_slice(&overhead), - scalar: H256::from_slice(&scalar), - gas_limit: chain_config.system_config.gas_limit.as_u64(), + overhead: chain_config.system_config.l1_fee_overhead.into(), + scalar: chain_config.system_config.l1_fee_scalar.into(), + gas_limit: chain_config.system_config.gas_limit.try_into().unwrap(), }, }, block_time: chain_config.blocktime, @@ -809,31 +797,29 @@ mod test { chain_config.system_config.batch_sender ); - let mut overhead = [0; 32]; - let mut scalar = [0; 32]; - - chain_config + let overhead: U256 = external_config + .genesis + .system_config + .overhead + .try_into() + .unwrap(); + let scalar: U256 = external_config + .genesis .system_config - .l1_fee_overhead - .to_big_endian(&mut overhead); - chain_config + .scalar + .try_into() + .unwrap(); + let gas_limit: U256 = external_config + .genesis .system_config - .l1_fee_scalar - .to_big_endian(&mut scalar); + .gas_limit + .try_into() + .unwrap(); - assert_eq!( - external_config.genesis.system_config.overhead, - H256::from_slice(&overhead), - ); - assert_eq!( - external_config.genesis.system_config.scalar, - H256::from_slice(&scalar), - ); + assert_eq!(chain_config.system_config.l1_fee_overhead, overhead,); + assert_eq!(chain_config.system_config.l1_fee_scalar, scalar,); - assert_eq!( - external_config.genesis.system_config.gas_limit, - chain_config.system_config.gas_limit.as_u64() - ); + assert_eq!(chain_config.system_config.gas_limit, gas_limit,); } #[test] diff --git a/src/derive/stages/attributes.rs b/src/derive/stages/attributes.rs index e7e95d05..749e04e9 100644 --- a/src/derive/stages/attributes.rs +++ b/src/derive/stages/attributes.rs @@ -46,7 +46,8 @@ impl PurgeableIterator for Attributes { fn purge(&mut self) { self.block_input_iter.purge(); self.sequence_number = 0; - self.epoch_hash = self.state.read().unwrap().safe_epoch.hash; + self.epoch_hash = + ethers::types::H256::from_slice(self.state.read().unwrap().safe_epoch.hash.as_slice()); } } @@ -64,7 +65,7 @@ impl Attributes { block_input_iter, state, sequence_number: seq, - epoch_hash, + epoch_hash: H256::from_slice(epoch_hash.as_slice()), config, } } @@ -76,10 +77,11 @@ impl Attributes { tracing::debug!("deriving attributes from block: {}", input.epoch.number); tracing::debug!("batch epoch hash: {:?}", input.epoch.hash); - self.update_sequence_number(input.epoch.hash); + let epoch_hash = H256::from_slice(input.epoch.hash.as_slice()); + self.update_sequence_number(epoch_hash); let state = self.state.read().unwrap(); - let l1_info = state.l1_info_by_hash(input.epoch.hash).unwrap(); + let l1_info = state.l1_info_by_hash(epoch_hash).unwrap(); let withdrawals = if input.timestamp >= self.config.chain.canyon_time { Some(Vec::new()) @@ -98,10 +100,10 @@ impl Attributes { PayloadAttributes { timestamp, prev_randao, - suggested_fee_recipient, + suggested_fee_recipient: Address::from_slice(suggested_fee_recipient.as_slice()), transactions, no_tx_pool: true, - gas_limit: U64([l1_info.system_config.gas_limit.as_u64()]), + gas_limit: U64([l1_info.system_config.gas_limit.try_into().unwrap()]), withdrawals, epoch, l1_inclusion_block, @@ -233,8 +235,8 @@ impl From for DepositedTransaction { Self { source_hash, - from, - to, + from: Address::from_slice(from.as_slice()), + to: to.map(|t| Address::from_slice(t.as_slice())), mint: U256::zero(), value: U256::zero(), gas: attributes_deposited.gas, @@ -328,15 +330,18 @@ impl AttributesDeposited { let gas = if is_regolith { 1_000_000 } else { 150_000_000 }; + let batcher_hash = H256::from_slice(l1_info.system_config.batcher_hash().as_slice()); + let fee_overhead = U256::from(l1_info.system_config.l1_fee_overhead.to_be_bytes()); + let fee_scalar = U256::from(l1_info.system_config.l1_fee_scalar.to_be_bytes()); Self { number: l1_info.block_info.number, timestamp: l1_info.block_info.timestamp, base_fee: l1_info.block_info.base_fee, hash: l1_info.block_info.hash, sequence_number: seq, - batcher_hash: l1_info.system_config.batcher_hash(), - fee_overhead: l1_info.system_config.l1_fee_overhead, - fee_scalar: l1_info.system_config.l1_fee_scalar, + batcher_hash, + fee_overhead, + fee_scalar, gas, is_system_tx, } diff --git a/src/derive/stages/batches.rs b/src/derive/stages/batches.rs index e067ece7..7ec227eb 100644 --- a/src/derive/stages/batches.rs +++ b/src/derive/stages/batches.rs @@ -204,7 +204,7 @@ where } // check that block builds on existing chain - if batch.parent_hash != head.hash { + if alloy_primitives::B256::from_slice(batch.parent_hash.as_bytes()) != head.hash { tracing::warn!("invalid parent hash"); return BatchStatus::Drop; } @@ -226,7 +226,8 @@ where }; if let Some(batch_origin) = batch_origin { - if batch.epoch_hash != batch_origin.hash { + if alloy_primitives::B256::from_slice(batch.epoch_hash.as_bytes()) != batch_origin.hash + { tracing::warn!("invalid epoch hash"); return BatchStatus::Drop; } @@ -323,7 +324,7 @@ where // check that block builds on existing chain - if prev_l2_block.hash.as_bytes()[..20] != batch.parent_check { + if prev_l2_block.hash.as_slice()[..20] != batch.parent_check { tracing::warn!("batch parent check failed"); return BatchStatus::Drop; } @@ -341,7 +342,7 @@ where } if let Some(l1_origin) = state.epoch_by_number(end_epoch_num) { - if batch.l1_origin_check != l1_origin.hash.as_bytes()[..20] { + if batch.l1_origin_check != l1_origin.hash.as_slice()[..20] { tracing::warn!("origin check failed"); return BatchStatus::Drop; } diff --git a/src/derive/state.rs b/src/derive/state.rs index 46e5068a..c3d43c29 100644 --- a/src/derive/state.rs +++ b/src/derive/state.rs @@ -1,5 +1,6 @@ use std::{collections::BTreeMap, sync::Arc}; +use alloy_primitives::B256; use ethers::{ providers::{Http, Middleware, Provider}, types::H256, @@ -76,7 +77,7 @@ impl State { pub fn epoch_by_hash(&self, hash: H256) -> Option { self.l1_info_by_hash(hash).map(|info| Epoch { number: info.block_info.number, - hash: info.block_info.hash, + hash: B256::from_slice(info.block_info.hash.as_bytes()), timestamp: info.block_info.timestamp, }) } @@ -85,7 +86,7 @@ impl State { pub fn epoch_by_number(&self, num: u64) -> Option { self.l1_info_by_number(num).map(|info| Epoch { number: info.block_info.number, - hash: info.block_info.hash, + hash: B256::from_slice(info.block_info.hash.as_bytes()), timestamp: info.block_info.timestamp, }) } diff --git a/src/driver/engine_driver.rs b/src/driver/engine_driver.rs index 9f577feb..50c02303 100644 --- a/src/driver/engine_driver.rs +++ b/src/driver/engine_driver.rs @@ -1,5 +1,6 @@ use std::sync::Arc; +use alloy_primitives::B256; use ethers::providers::{Http, Middleware, Provider}; use ethers::types::Transaction; use ethers::{ @@ -100,8 +101,8 @@ impl EngineDriver { let new_head = BlockInfo { number: payload.block_number.as_u64(), - hash: payload.block_hash, - parent_hash: payload.parent_hash, + hash: B256::from_slice(payload.block_hash.as_bytes()), + parent_hash: B256::from_slice(payload.parent_hash.as_bytes()), timestamp: payload.timestamp.as_u64(), }; @@ -198,9 +199,9 @@ impl EngineDriver { /// - `finalized_block` = `finalized_head` fn create_forkchoice_state(&self) -> ForkchoiceState { ForkchoiceState { - head_block_hash: self.unsafe_head.hash, - safe_block_hash: self.safe_head.hash, - finalized_block_hash: self.finalized_head.hash, + head_block_hash: H256::from_slice(self.unsafe_head.hash.as_slice()), + safe_block_hash: H256::from_slice(self.safe_head.hash.as_slice()), + finalized_block_hash: H256::from_slice(self.finalized_head.hash.as_slice()), } } diff --git a/src/driver/info.rs b/src/driver/info.rs index 678c0312..36967815 100644 --- a/src/driver/info.rs +++ b/src/driver/info.rs @@ -79,8 +79,7 @@ mod test_utils { use super::*; use crate::common::{BlockInfo, Epoch}; use crate::config::{ChainConfig, Config}; - use ethers::types::H256; - use std::str::FromStr; + use alloy_primitives::b256; pub struct MockProvider { pub block: Option>, @@ -93,23 +92,16 @@ mod test_utils { pub fn default_head_info() -> HeadInfo { HeadInfo { l2_block_info: BlockInfo { - hash: H256::from_str( - "dbf6a80fef073de06add9b0d14026d6e5a86c85f6d102c36d3d8e9cf89c2afd3", - ) - .unwrap(), + hash: b256!("dbf6a80fef073de06add9b0d14026d6e5a86c85f6d102c36d3d8e9cf89c2afd3"), number: 105235063, - parent_hash: H256::from_str( - "21a168dfa5e727926063a28ba16fd5ee84c814e847c81a699c7a0ea551e4ca50", - ) - .unwrap(), + parent_hash: b256!( + "21a168dfa5e727926063a28ba16fd5ee84c814e847c81a699c7a0ea551e4ca50" + ), timestamp: 1686068903, }, l1_epoch: Epoch { number: 17422590, - hash: H256::from_str( - "438335a20d98863a4c0c97999eb2481921ccd28553eac6f913af7c12aec04108", - ) - .unwrap(), + hash: b256!("438335a20d98863a4c0c97999eb2481921ccd28553eac6f913af7c12aec04108"), timestamp: 1686068903, }, sequence_number: 0, diff --git a/src/driver/mod.rs b/src/driver/mod.rs index 49935879..522fa720 100644 --- a/src/driver/mod.rs +++ b/src/driver/mod.rs @@ -4,10 +4,8 @@ use std::{ time::Duration, }; -use ethers::{ - providers::{Http, Provider}, - types::Address, -}; +use ethers::providers::{Http, Provider}; +use ethers::types::Address; use eyre::Result; use reqwest::Url; use tokio::{ @@ -102,8 +100,8 @@ impl Driver { let _addr = rpc::run_server(config.clone()).await?; - let (unsafe_block_signer_sender, unsafe_block_signer_recv) = - watch::channel(config.chain.system_config.unsafe_block_signer); + let signer = Address::from_slice(config.chain.system_config.unsafe_block_signer.as_slice()); + let (unsafe_block_signer_sender, unsafe_block_signer_recv) = watch::channel(signer); let (block_handler, unsafe_block_recv) = BlockHandler::new(config.chain.l2_chain_id, unsafe_block_signer_recv); @@ -238,10 +236,10 @@ impl Driver { unsafe_block_num > synced_block_num && unsafe_block_num - synced_block_num < 1024 }); - let next_unsafe_payload = self - .future_unsafe_blocks - .iter() - .find(|p| p.parent_hash == self.engine_driver.unsafe_head.hash); + let next_unsafe_payload = self.future_unsafe_blocks.iter().find(|p| { + alloy_primitives::B256::from_slice(p.parent_hash.as_bytes()) + == self.engine_driver.unsafe_head.hash + }); if let Some(payload) = next_unsafe_payload { _ = self.engine_driver.handle_unsafe_payload(payload).await; @@ -271,8 +269,9 @@ impl Driver { BlockUpdate::NewBlock(l1_info) => { let num = l1_info.block_info.number; - self.unsafe_block_signer_sender - .send(l1_info.system_config.unsafe_block_signer)?; + let signer = + Address::from_slice(l1_info.system_config.unsafe_block_signer.as_slice()); + self.unsafe_block_signer_sender.send(signer)?; self.pipeline.push_batcher_transactions( // cloning `bytes::Bytes` is cheap diff --git a/src/driver/types.rs b/src/driver/types.rs index ca9288fc..9fc2f700 100644 --- a/src/driver/types.rs +++ b/src/driver/types.rs @@ -78,6 +78,7 @@ mod tests { use crate::driver::HeadInfo; use std::str::FromStr; + use alloy_primitives::b256; use ethers::{ providers::{Middleware, Provider}, types::{Block, Transaction, H256}, @@ -181,14 +182,13 @@ mod tests { let block: Block = serde_json::from_str(raw_block)?; - let expected_l2_block_hash = H256::from_str( - "0x2e4f4aff36bb7951be9742ad349fb1db84643c6bbac5014f3d196fd88fe333eb", - )?; + let expected_l2_block_hash = + b256!("2e4f4aff36bb7951be9742ad349fb1db84643c6bbac5014f3d196fd88fe333eb"); let expected_l2_block_number = 8381743; let expected_l2_block_timestamp = 1682191554; let expected_l1_epoch_hash = - H256::from_str("0444c991c5fe1d7291ff34b3f5c3b44ee861f021396d33ba3255b83df30e357d")?; + b256!("0444c991c5fe1d7291ff34b3f5c3b44ee861f021396d33ba3255b83df30e357d"); let expected_l1_epoch_block_number = 8874020; let expected_l1_epoch_timestamp = 1682191440; @@ -221,15 +221,14 @@ mod tests { if std::env::var("L1_TEST_RPC_URL").is_ok() && std::env::var("L2_TEST_RPC_URL").is_ok() { let l2_block_hash = H256::from_str( - "0x75d4a658d7b6430c874c5518752a8d90fb1503eccd6ae4cfc97fd4aedeebb939", + "75d4a658d7b6430c874c5518752a8d90fb1503eccd6ae4cfc97fd4aedeebb939", )?; let expected_l2_block_number = 8428108; let expected_l2_block_timestamp = 1682284284; - let expected_l1_epoch_hash = H256::from_str( - "0x76ab90dc2afea158bbe14a99f22d5f867b51719378aa37d1a3aa3833ace67cad", - )?; + let expected_l1_epoch_hash = + b256!("76ab90dc2afea158bbe14a99f22d5f867b51719378aa37d1a3aa3833ace67cad"); let expected_l1_epoch_block_number = 8879997; let expected_l1_epoch_timestamp = 1682284164; @@ -263,6 +262,7 @@ mod tests { use crate::driver::HeadInfo; use std::str::FromStr; + use alloy_primitives::b256; use ethers::{ providers::{Middleware, Provider}, types::H256, @@ -280,9 +280,8 @@ mod tests { let expected_l2_block_number = 21564471; let expected_l2_block_timestamp = 1708557010; - let expected_l1_epoch_hash = H256::from_str( - "0x231ac984a3fc58757efe373b0b5bff0589c0e67a969a6cbc56ec959739525b31", - )?; + let expected_l1_epoch_hash = + b256!("231ac984a3fc58757efe373b0b5bff0589c0e67a969a6cbc56ec959739525b31"); let expected_l1_epoch_block_number = 10575507; let expected_l1_epoch_timestamp = 1708556928; diff --git a/src/engine/payload.rs b/src/engine/payload.rs index 28097fc3..52b03cd5 100644 --- a/src/engine/payload.rs +++ b/src/engine/payload.rs @@ -64,7 +64,7 @@ impl TryFrom> for ExecutionPayload { Ok(ExecutionPayload { parent_hash: value.parent_hash, - fee_recipient: SystemAccounts::default().fee_vault, + fee_recipient: H160::from_slice(SystemAccounts::default().fee_vault.as_slice()), state_root: value.state_root, receipts_root: value.receipts_root, logs_bloom: value.logs_bloom.unwrap().as_bytes().to_vec().into(), diff --git a/src/l1/chain_watcher.rs b/src/l1/chain_watcher.rs index bd9d9702..852f5429 100644 --- a/src/l1/chain_watcher.rs +++ b/src/l1/chain_watcher.rs @@ -1,9 +1,10 @@ use std::{collections::HashMap, sync::Arc, time::Duration}; +use alloy_primitives::B256; use bytes::Bytes; use ethers::{ providers::{Http, HttpRateLimitRetryPolicy, Middleware, Provider, RetryClient}, - types::{Address, Block, BlockNumber, Filter, Transaction, H256, U256}, + types::{Address, Block, BlockNumber, Filter, Transaction, H256}, utils::keccak256, }; use eyre::Result; @@ -197,15 +198,18 @@ impl InnerWatcher { ) .input; - let batch_sender = Address::from_slice(&input[176..196]); - let l1_fee_overhead = U256::from(H256::from_slice(&input[196..228]).as_bytes()); - let l1_fee_scalar = U256::from(H256::from_slice(&input[228..260]).as_bytes()); + let batch_sender = alloy_primitives::Address::from_slice(&input[176..196]); + let l1_fee_overhead = alloy_primitives::U256::from_be_slice(&input[196..228]); + let l1_fee_scalar = alloy_primitives::U256::from_be_slice(&input[228..260]); + let gas_lim_slice: &mut [u8] = &mut [0; 32]; + block.gas_limit.to_big_endian(gas_lim_slice); + let gas_limit = alloy_primitives::U256::from_be_slice(gas_lim_slice); SystemConfig { batch_sender, l1_fee_overhead, l1_fee_scalar, - gas_limit: block.gas_limit, + gas_limit, // TODO: fetch from contract unsafe_block_signer: config.chain.system_config.unsafe_block_signer, } @@ -267,10 +271,10 @@ impl InnerWatcher { if l1_info.block_info.number >= self.finalized_block { let block_info = BlockInfo { - hash: l1_info.block_info.hash, + hash: B256::from_slice(l1_info.block_info.hash.as_bytes()), number: l1_info.block_info.number, timestamp: l1_info.block_info.timestamp, - parent_hash: block.parent_hash, + parent_hash: B256::from_slice(block.parent_hash.as_bytes()), }; self.unfinalized_blocks.push(block_info); @@ -298,7 +302,9 @@ impl InnerWatcher { if last_update_block < self.current_block { let to_block = last_update_block + 1000; let filter = Filter::new() - .address(self.config.chain.system_config_contract) + .address(Address::from_slice( + self.config.chain.system_config_contract.as_slice(), + )) .topic0(*CONFIG_UPDATE_TOPIC) .from_block(last_update_block + 1) .to_block(to_block); @@ -313,17 +319,26 @@ impl InnerWatcher { let mut config = self.system_config; match update { SystemConfigUpdate::BatchSender(addr) => { - config.batch_sender = addr; + config.batch_sender = + alloy_primitives::Address::from_slice(addr.as_bytes()); } SystemConfigUpdate::Fees(overhead, scalar) => { - config.l1_fee_overhead = overhead; - config.l1_fee_scalar = scalar; + let overhead_slice: &mut [u8] = &mut [0; 0]; + let scalar_slice: &mut [u8] = &mut [0; 0]; + overhead.to_big_endian(overhead_slice); + scalar.to_big_endian(scalar_slice); + config.l1_fee_overhead = + alloy_primitives::U256::from_be_slice(overhead_slice); + config.l1_fee_scalar = alloy_primitives::U256::from_be_slice(scalar_slice); } SystemConfigUpdate::Gas(gas) => { - config.gas_limit = gas; + let gas_slice: &mut [u8] = &mut [0; 0]; + gas.to_big_endian(gas_slice); + config.gas_limit = alloy_primitives::U256::from_be_slice(gas_slice); } SystemConfigUpdate::UnsafeBlockSigner(addr) => { - config.unsafe_block_signer = addr; + config.unsafe_block_signer = + alloy_primitives::Address::from_slice(addr.as_bytes()); } } @@ -398,7 +413,9 @@ impl InnerWatcher { let end_block = self.head_block.min(block_num + 1000); let deposit_filter = Filter::new() - .address(self.config.chain.deposit_contract) + .address(Address::from_slice( + self.config.chain.deposit_contract.as_slice(), + )) .topic0(*TRANSACTION_DEPOSITED_TOPIC) .from_block(block_num) .to_block(end_block); @@ -493,8 +510,9 @@ impl InnerWatcher { /// Check if a transaction was sent from the batch sender to the batch inbox. #[inline] fn is_valid_batcher_transaction(&self, tx: &Transaction) -> bool { - let batch_sender = self.config.chain.system_config.batch_sender; - let batch_inbox = self.config.chain.batch_inbox; + let batch_sender = + Address::from_slice(self.config.chain.system_config.batch_sender.as_slice()); + let batch_inbox = Address::from_slice(self.config.chain.batch_inbox.as_slice()); tx.from == batch_sender && tx.to.map(|to| to == batch_inbox).unwrap_or(false) } diff --git a/src/rpc/mod.rs b/src/rpc/mod.rs index e340d67e..8e1c8074 100644 --- a/src/rpc/mod.rs +++ b/src/rpc/mod.rs @@ -9,7 +9,7 @@ use eyre::Result; use ethers::{ providers::{Middleware, Provider}, - types::{Block, BlockId, H256}, + types::{Address, Block, BlockId, H256}, utils::keccak256, }; @@ -67,7 +67,7 @@ impl RpcServer for RpcServerImpl { let state_proof = convert_err( l2_provider .get_proof( - self.config.chain.l2_to_l1_message_passer, + Address::from_slice(self.config.chain.l2_to_l1_message_passer.as_slice()), locations, block_id, ) diff --git a/src/runner/mod.rs b/src/runner/mod.rs index b5304df1..251ceeb4 100644 --- a/src/runner/mod.rs +++ b/src/runner/mod.rs @@ -230,10 +230,13 @@ impl Runner { .await? .ok_or_else(|| eyre::eyre!("could not find block"))?; + let predeploy = ethers::types::Address::from_slice( + SystemAccounts::default().attributes_predeploy.as_slice(), + ); let sequence_number = &l2_block .transactions .iter() - .find(|tx| tx.to.unwrap() == SystemAccounts::default().attributes_predeploy) + .find(|tx| tx.to.map_or(false, |to| to == predeploy)) .expect("could not find setL1BlockValues tx in the epoch boundary search") .input .clone()