diff --git a/Cargo.lock b/Cargo.lock index 0b584dc9a2e..45d34bfcd8f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5645,9 +5645,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.97" +version = "1.0.107" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bdf3bf93142acad5821c99197022e170842cdbc1c30482b98750c688c640842a" +checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" dependencies = [ "itoa", "ryu", @@ -7640,6 +7640,7 @@ name = "zksync_basic_types" version = "0.1.0" dependencies = [ "serde", + "serde_json", "web3", ] diff --git a/core/bin/external_node/src/config/mod.rs b/core/bin/external_node/src/config/mod.rs index 35b1e91bc08..66f4e54ff57 100644 --- a/core/bin/external_node/src/config/mod.rs +++ b/core/bin/external_node/src/config/mod.rs @@ -52,13 +52,14 @@ impl RemoteENConfig { .get_main_contract() .await .context("Failed to fetch L1 contract address")?; - let l2_chain_id = L2ChainId( + let l2_chain_id = L2ChainId::try_from( client .chain_id() .await .context("Failed to fetch L2 chain ID")? - .as_u64() as u16, - ); + .as_u64(), + ) + .unwrap(); let l1_chain_id = L1ChainId( client .l1_chain_id() @@ -396,14 +397,14 @@ impl ExternalNodeConfig { .await .context("Unable to check L1 chain ID through the configured L1 client")?; - let l2_chain_id: u16 = env_var("EN_L2_CHAIN_ID"); + let l2_chain_id: L2ChainId = env_var("EN_L2_CHAIN_ID"); let l1_chain_id: u64 = env_var("EN_L1_CHAIN_ID"); - if l2_chain_id != remote.l2_chain_id.0 { + if l2_chain_id != remote.l2_chain_id { anyhow::bail!( "Configured L2 chain id doesn't match the one from main node. Make sure your configuration is correct and you are corrected to the right main node. - Main node L2 chain id: {}. Local config value: {}", - remote.l2_chain_id.0, l2_chain_id + Main node L2 chain id: {:?}. Local config value: {:?}", + remote.l2_chain_id, l2_chain_id ); } if l1_chain_id != remote.l1_chain_id.0 { diff --git a/core/bin/system-constants-generator/src/utils.rs b/core/bin/system-constants-generator/src/utils.rs index afb00b5cda7..d55a73d4e8f 100644 --- a/core/bin/system-constants-generator/src/utils.rs +++ b/core/bin/system-constants-generator/src/utils.rs @@ -92,7 +92,7 @@ pub(super) fn get_l2_tx(contract_address: Address, signer: &H256, pubdata_price: gas_per_pubdata_limit: pubdata_price.into(), }, U256::from(0), - L2ChainId(270), + L2ChainId::from(270), signer, None, Default::default(), diff --git a/core/lib/basic_types/Cargo.toml b/core/lib/basic_types/Cargo.toml index e96dd0c0ce2..4e8d8af8c15 100644 --- a/core/lib/basic_types/Cargo.toml +++ b/core/lib/basic_types/Cargo.toml @@ -12,3 +12,4 @@ categories = ["cryptography"] [dependencies] web3 = { version= "0.19.0", default-features = false, features = ["http-rustls-tls", "test", "signing"] } serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" diff --git a/core/lib/basic_types/src/lib.rs b/core/lib/basic_types/src/lib.rs index a8f7cacbae5..3223dfddf59 100644 --- a/core/lib/basic_types/src/lib.rs +++ b/core/lib/basic_types/src/lib.rs @@ -7,7 +7,7 @@ mod macros; pub mod network; -use serde::{Deserialize, Serialize}; +use serde::{de, Deserialize, Deserializer, Serialize}; use std::convert::{Infallible, TryFrom, TryInto}; use std::fmt; use std::num::ParseIntError; @@ -76,6 +76,85 @@ impl TryFrom for AccountTreeId { } } +/// ChainId in the ZkSync network. +#[derive(Copy, Clone, Debug, Serialize, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub struct L2ChainId(u64); + +impl<'de> Deserialize<'de> for L2ChainId { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let s: String = Deserialize::deserialize(deserializer)?; + s.parse().map_err(de::Error::custom) + } +} + +impl FromStr for L2ChainId { + type Err = String; + + fn from_str(s: &str) -> Result { + // Parse the string as a U64 + // try to parse as decimal first + let number = match U64::from_dec_str(s) { + Ok(u) => u, + Err(_) => { + // try to parse as hex + s.parse::() + .map_err(|err| format!("Failed to parse L2ChainId: Err {err}"))? + } + }; + + if number.as_u64() > L2ChainId::max().0 { + return Err(format!("Too big chain ID. MAX: {}", L2ChainId::max().0)); + } + Ok(L2ChainId(number.as_u64())) + } +} + +impl L2ChainId { + /// The maximum value of the L2 chain ID. + // 2^53 - 1 is a max safe integer in JS. In ethereum JS libs chain ID should be the safe integer. + // Next arithmetic operation: subtract 36 and divide by 2 comes from `v` calculation: + // v = 2*chainId + 36, that should be save integer as well. + const MAX: u64 = ((1 << 53) - 1 - 36) / 2; + + pub fn max() -> Self { + Self(Self::MAX) + } + + pub fn as_u64(&self) -> u64 { + self.0 + } +} + +impl Default for L2ChainId { + fn default() -> Self { + Self(270) + } +} + +impl TryFrom for L2ChainId { + type Error = String; + + fn try_from(val: u64) -> Result { + if val > L2ChainId::max().0 { + return Err(format!( + "Cannot convert given value {} into L2ChainId. It's greater than MAX: {},", + val, + L2ChainId::max().0, + )); + } + Ok(Self(val)) + } +} + +impl From for L2ChainId { + fn from(value: u32) -> Self { + Self(value as u64) + } +} + basic_type!( /// zkSync network block sequential index. MiniblockNumber, @@ -112,12 +191,6 @@ basic_type!( u64 ); -basic_type!( - /// ChainId in the ZkSync network. - L2ChainId, - u16 -); - #[allow(clippy::derivable_impls)] impl Default for MiniblockNumber { fn default() -> Self { @@ -139,15 +212,78 @@ impl Default for L1BlockNumber { } } -impl Default for L2ChainId { - fn default() -> Self { - Self(270) - } -} - #[allow(clippy::derivable_impls)] impl Default for PriorityOpId { fn default() -> Self { Self(0) } } + +#[cfg(test)] +mod tests { + use super::*; + use serde_json::from_str; + + #[test] + fn test_from_str_valid_decimal() { + let input = "42"; + let result = L2ChainId::from_str(input); + assert_eq!(result.unwrap().as_u64(), 42); + } + + #[test] + fn test_from_str_valid_hexadecimal() { + let input = "0x2A"; + let result = L2ChainId::from_str(input); + assert_eq!(result.unwrap().as_u64(), 42); + } + + #[test] + fn test_from_str_too_big_chain_id() { + let input = "18446744073709551615"; // 2^64 - 1 + let result = L2ChainId::from_str(input); + assert_eq!( + result, + Err(format!("Too big chain ID. MAX: {}", L2ChainId::max().0)) + ); + } + + #[test] + fn test_from_str_invalid_input() { + let input = "invalid"; // Invalid input that cannot be parsed as a number + let result = L2ChainId::from_str(input); + + assert!(result.is_err()); + assert!(result + .unwrap_err() + .contains("Failed to parse L2ChainId: Err ")); + } + + #[test] + fn test_deserialize_valid_decimal() { + let input_json = "\"42\""; + + let result: Result = from_str(input_json); + assert_eq!(result.unwrap().as_u64(), 42); + } + + #[test] + fn test_deserialize_valid_hex() { + let input_json = "\"0x2A\""; + + let result: Result = from_str(input_json); + assert_eq!(result.unwrap().as_u64(), 42); + } + + #[test] + fn test_deserialize_invalid() { + let input_json = "\"invalid\""; + + let result: Result = from_str(input_json); + assert!(result.is_err()); + assert!(result + .unwrap_err() + .to_string() + .contains("Failed to parse L2ChainId: Err Invalid character ")); + } +} diff --git a/core/lib/config/src/configs/chain.rs b/core/lib/config/src/configs/chain.rs index 3e680b435e4..afb92871694 100644 --- a/core/lib/config/src/configs/chain.rs +++ b/core/lib/config/src/configs/chain.rs @@ -5,7 +5,7 @@ use serde::Deserialize; use std::time::Duration; // Local uses use zksync_basic_types::network::Network; -use zksync_basic_types::{Address, H256}; +use zksync_basic_types::{Address, L2ChainId, H256}; use zksync_contracts::BaseSystemContractsHashes; use super::envy_load; @@ -47,7 +47,7 @@ pub struct NetworkConfig { pub zksync_network: String, /// ID of current zkSync network treated as ETH network ID. /// Used to distinguish zkSync from other Web3-capable networks. - pub zksync_network_id: u16, + pub zksync_network_id: L2ChainId, } impl NetworkConfig { @@ -202,7 +202,7 @@ mod tests { network: NetworkConfig { network: "localhost".parse().unwrap(), zksync_network: "localhost".to_string(), - zksync_network_id: 270, + zksync_network_id: L2ChainId::from(270), }, state_keeper: StateKeeperConfig { transaction_slots: 50, diff --git a/core/lib/dal/src/blocks_web3_dal.rs b/core/lib/dal/src/blocks_web3_dal.rs index 301f6940d1a..03ec1c1930f 100644 --- a/core/lib/dal/src/blocks_web3_dal.rs +++ b/core/lib/dal/src/blocks_web3_dal.rs @@ -623,7 +623,7 @@ mod tests { for block_id in block_ids { let block = conn .blocks_web3_dal() - .get_block_by_web3_block_id(block_id, false, L2ChainId(270)) + .get_block_by_web3_block_id(block_id, false, L2ChainId::from(270)) .await; let block = block.unwrap().unwrap(); assert!(block.transactions.is_empty()); @@ -650,7 +650,7 @@ mod tests { for block_id in non_existing_block_ids { let block = conn .blocks_web3_dal() - .get_block_by_web3_block_id(block_id, false, L2ChainId(270)) + .get_block_by_web3_block_id(block_id, false, L2ChainId::from(270)) .await; assert!(block.unwrap().is_none()); diff --git a/core/lib/dal/src/models/storage_transaction.rs b/core/lib/dal/src/models/storage_transaction.rs index 738cf3356f3..554d33649f2 100644 --- a/core/lib/dal/src/models/storage_transaction.rs +++ b/core/lib/dal/src/models/storage_transaction.rs @@ -389,7 +389,7 @@ impl<'r> FromRow<'r, PgRow> for StorageApiTransaction { .unwrap_or_default() .map(U64::from), access_list: None, - chain_id: U256::from(0), + chain_id: 0, l1_batch_number: db_row .try_get::("l1_batch_number_tx") .ok() @@ -502,7 +502,7 @@ pub fn web3_transaction_select_sql() -> &'static str { pub fn extract_web3_transaction(db_row: PgRow, chain_id: L2ChainId) -> api::Transaction { let mut storage_api_tx = StorageApiTransaction::from_row(&db_row).unwrap(); - storage_api_tx.inner_api_transaction.chain_id = U256::from(chain_id.0); + storage_api_tx.inner_api_transaction.chain_id = chain_id.as_u64(); storage_api_tx.into() } diff --git a/core/lib/dal/src/tests/mod.rs b/core/lib/dal/src/tests/mod.rs index 3f39f98a45a..fecd33f4761 100644 --- a/core/lib/dal/src/tests/mod.rs +++ b/core/lib/dal/src/tests/mod.rs @@ -59,7 +59,7 @@ pub(crate) fn mock_l2_transaction() -> L2Tx { zksync_types::Nonce(0), fee, Default::default(), - L2ChainId(270), + L2ChainId::from(270), &H256::random(), None, Default::default(), diff --git a/core/lib/dal/src/transactions_web3_dal.rs b/core/lib/dal/src/transactions_web3_dal.rs index c9a6ee8bf76..8ad983a2218 100644 --- a/core/lib/dal/src/transactions_web3_dal.rs +++ b/core/lib/dal/src/transactions_web3_dal.rs @@ -417,7 +417,7 @@ mod tests { for transaction_id in transaction_ids { let web3_tx = conn .transactions_web3_dal() - .get_transaction(transaction_id, L2ChainId(270)) + .get_transaction(transaction_id, L2ChainId::from(270)) .await; let web3_tx = web3_tx.unwrap().unwrap(); assert_eq!(web3_tx.hash, tx_hash); @@ -431,7 +431,7 @@ mod tests { for transaction_id in transactions_with_bogus_index { let web3_tx = conn .transactions_web3_dal() - .get_transaction(transaction_id, L2ChainId(270)) + .get_transaction(transaction_id, L2ChainId::from(270)) .await; assert!(web3_tx.unwrap().is_none()); } @@ -448,7 +448,7 @@ mod tests { for transaction_id in transactions_with_bogus_block { let web3_tx = conn .transactions_web3_dal() - .get_transaction(transaction_id, L2ChainId(270)) + .get_transaction(transaction_id, L2ChainId::from(270)) .await; assert!(web3_tx.unwrap().is_none()); } diff --git a/core/lib/state/src/in_memory.rs b/core/lib/state/src/in_memory.rs index 3ae72a9f4e9..e44187e34d9 100644 --- a/core/lib/state/src/in_memory.rs +++ b/core/lib/state/src/in_memory.rs @@ -9,7 +9,7 @@ use zksync_types::{ use zksync_utils::u256_to_h256; /// Network ID we use by defailt for in memory storage. -pub const IN_MEMORY_STORAGE_DEFAULT_NETWORK_ID: u16 = 270; +pub const IN_MEMORY_STORAGE_DEFAULT_NETWORK_ID: u32 = 270; /// In-memory storage. #[derive(Debug, Default)] @@ -22,7 +22,7 @@ impl InMemoryStorage { /// Constructs a storage that contains system smart contracts. pub fn with_system_contracts(bytecode_hasher: impl Fn(&[u8]) -> H256) -> Self { Self::with_system_contracts_and_chain_id( - L2ChainId(IN_MEMORY_STORAGE_DEFAULT_NETWORK_ID), + L2ChainId::from(IN_MEMORY_STORAGE_DEFAULT_NETWORK_ID), bytecode_hasher, ) } diff --git a/core/lib/test_account/src/lib.rs b/core/lib/test_account/src/lib.rs index 9c94e3f49cf..509402b7b6b 100644 --- a/core/lib/test_account/src/lib.rs +++ b/core/lib/test_account/src/lib.rs @@ -77,7 +77,7 @@ impl Account { nonce, fee.unwrap_or_else(|| self.default_fee()), value, - L2ChainId(270), + L2ChainId::default(), &self.private_key, factory_deps, Default::default(), diff --git a/core/lib/types/src/api/mod.rs b/core/lib/types/src/api/mod.rs index c9b157c6629..6c65356081b 100644 --- a/core/lib/types/src/api/mod.rs +++ b/core/lib/types/src/api/mod.rs @@ -505,7 +505,7 @@ pub struct Transaction { pub max_priority_fee_per_gas: Option, /// Id of the current chain #[serde(rename = "chainId")] - pub chain_id: U256, + pub chain_id: u64, /// Number of the l1 batch this transaction was included within. #[serde( rename = "l1BatchNumber", diff --git a/core/lib/types/src/l2/mod.rs b/core/lib/types/src/l2/mod.rs index 973c5a30b10..b1ef8ca07a7 100644 --- a/core/lib/types/src/l2/mod.rs +++ b/core/lib/types/src/l2/mod.rs @@ -93,7 +93,7 @@ impl L2TxCommonData { self.input = Some(InputData { hash, data: input }) } - pub fn extract_chain_id(&self) -> Option { + pub fn extract_chain_id(&self) -> Option { let bytes = self.input_data()?; let chain_id = match bytes.first() { Some(x) if *x >= 0x80 => { @@ -226,7 +226,7 @@ impl L2Tx { pub fn get_rlp_bytes(&self, chain_id: L2ChainId) -> Bytes { let mut rlp_stream = RlpStream::new(); let tx: TransactionRequest = self.clone().into(); - tx.rlp(&mut rlp_stream, chain_id.0, None); + tx.rlp(&mut rlp_stream, chain_id.as_u64(), None); Bytes(rlp_stream.as_raw().to_vec()) } @@ -329,7 +329,7 @@ impl From for TransactionRequest { transaction_type: None, access_list: None, eip712_meta: None, - chain_id: tx.common_data.extract_chain_id().unwrap_or_default().into(), + chain_id: tx.common_data.extract_chain_id(), }; match tx_type as u8 { LEGACY_TX_TYPE => {} @@ -389,7 +389,7 @@ impl From for api::Transaction { Self { hash: tx.hash(), - chain_id: tx.common_data.extract_chain_id().unwrap_or_default().into(), + chain_id: tx.common_data.extract_chain_id().unwrap_or_default(), nonce: U256::from(tx.common_data.nonce.0), from: Some(tx.common_data.initiator_address), to: Some(tx.recipient_account()), diff --git a/core/lib/types/src/storage/mod.rs b/core/lib/types/src/storage/mod.rs index b1ed25dad97..bf790b58d3d 100644 --- a/core/lib/types/src/storage/mod.rs +++ b/core/lib/types/src/storage/mod.rs @@ -103,7 +103,7 @@ pub fn get_system_context_init_logs(chain_id: L2ChainId) -> Vec { vec![ StorageLog::new_write_log( get_system_context_key(SYSTEM_CONTEXT_CHAIN_ID_POSITION), - H256::from_low_u64_be(chain_id.0 as u64), + H256::from_low_u64_be(chain_id.as_u64()), ), StorageLog::new_write_log( get_system_context_key(SYSTEM_CONTEXT_BLOCK_GAS_LIMIT_POSITION), diff --git a/core/lib/types/src/transaction_request.rs b/core/lib/types/src/transaction_request.rs index 0516081434d..c9af634c3e4 100644 --- a/core/lib/types/src/transaction_request.rs +++ b/core/lib/types/src/transaction_request.rs @@ -168,7 +168,7 @@ pub enum SerializationTransactionError { #[error("invalid signature")] MalformedSignature, #[error("wrong chain id {}", .0.unwrap_or_default())] - WrongChainId(Option), + WrongChainId(Option), #[error("malformed paymaster params")] MalforedPaymasterParams, #[error("factory dependency #{0} is invalid: {1}")] @@ -233,7 +233,7 @@ pub struct TransactionRequest { pub eip712_meta: Option, /// Chain ID #[serde(default, skip_serializing_if = "Option::is_none")] - pub chain_id: Option, + pub chain_id: Option, } #[derive(Default, Serialize, Deserialize, Clone, PartialEq, Debug, Eq)] @@ -426,7 +426,7 @@ impl TransactionRequest { pub fn get_signed_bytes(&self, signature: &PackedEthSignature, chain_id: L2ChainId) -> Vec { let mut rlp = RlpStream::new(); - self.rlp(&mut rlp, *chain_id, Some(signature)); + self.rlp(&mut rlp, chain_id.as_u64(), Some(signature)); let mut data = rlp.out().to_vec(); if let Some(tx_type) = self.transaction_type { data.insert(0, tx_type.as_u64() as u8); @@ -438,7 +438,7 @@ impl TransactionRequest { self.transaction_type.is_none() || self.transaction_type == Some(LEGACY_TX_TYPE.into()) } - pub fn rlp(&self, rlp: &mut RlpStream, chain_id: u16, signature: Option<&PackedEthSignature>) { + pub fn rlp(&self, rlp: &mut RlpStream, chain_id: u64, signature: Option<&PackedEthSignature>) { rlp.begin_unbounded_list(); match self.transaction_type { @@ -553,7 +553,7 @@ impl TransactionRequest { pub fn from_bytes( bytes: &[u8], - chain_id: u16, + chain_id: L2ChainId, ) -> Result<(Self, H256), SerializationTransactionError> { let rlp; let mut tx = match bytes.first() { @@ -567,7 +567,7 @@ impl TransactionRequest { let v = rlp.val_at(6)?; let (_, tx_chain_id) = PackedEthSignature::unpack_v(v) .map_err(|_| SerializationTransactionError::MalformedSignature)?; - if tx_chain_id.is_some() && tx_chain_id != Some(chain_id) { + if tx_chain_id.is_some() && tx_chain_id != Some(chain_id.as_u64()) { return Err(SerializationTransactionError::WrongChainId(tx_chain_id)); } Self { @@ -592,7 +592,7 @@ impl TransactionRequest { } let tx_chain_id = rlp.val_at(0).ok(); - if tx_chain_id != Some(chain_id) { + if tx_chain_id != Some(chain_id.as_u64()) { return Err(SerializationTransactionError::WrongChainId(tx_chain_id)); } Self { @@ -613,7 +613,7 @@ impl TransactionRequest { )); } let tx_chain_id = rlp.val_at(10).ok(); - if tx_chain_id.is_some() && tx_chain_id != Some(chain_id) { + if tx_chain_id.is_some() && tx_chain_id != Some(chain_id.as_u64()) { return Err(SerializationTransactionError::WrongChainId(tx_chain_id)); } @@ -658,21 +658,20 @@ impl TransactionRequest { None => tx.recover_default_signer(default_signed_message).ok(), }; - let hash = - tx.get_tx_hash_with_signed_message(&default_signed_message, L2ChainId(chain_id))?; + let hash = tx.get_tx_hash_with_signed_message(&default_signed_message, chain_id)?; Ok((tx, hash)) } fn get_default_signed_message( &self, - chain_id: Option, + chain_id: Option, ) -> Result { if self.is_eip712_tx() { let tx_chain_id = chain_id.ok_or(SerializationTransactionError::WrongChainId(chain_id))?; Ok(PackedEthSignature::typed_data_to_signed_bytes( - &Eip712Domain::new(L2ChainId(tx_chain_id)), + &Eip712Domain::new(L2ChainId::try_from(tx_chain_id).unwrap()), self, )) } else { @@ -707,7 +706,7 @@ impl TransactionRequest { } pub fn get_tx_hash(&self, chain_id: L2ChainId) -> Result { - let default_signed_message = self.get_default_signed_message(Some(chain_id.0))?; + let default_signed_message = self.get_default_signed_message(Some(chain_id.as_u64()))?; self.get_tx_hash_with_signed_message(&default_signed_message, chain_id) } @@ -979,8 +978,11 @@ mod tests { access_list: None, }; let signed_tx = accounts.sign_transaction(tx.clone(), &key).await.unwrap(); - let (tx2, _) = - TransactionRequest::from_bytes(signed_tx.raw_transaction.0.as_slice(), 270).unwrap(); + let (tx2, _) = TransactionRequest::from_bytes( + signed_tx.raw_transaction.0.as_slice(), + L2ChainId::from(270), + ) + .unwrap(); assert_eq!(tx.gas, tx2.gas); assert_eq!(tx.gas_price.unwrap(), tx2.gas_price); assert_eq!(tx.nonce.unwrap(), tx2.nonce); @@ -1013,16 +1015,13 @@ mod tests { let mut rlp = RlpStream::new(); tx.rlp(&mut rlp, 270, Some(&signature)); let data = rlp.out().to_vec(); - let (tx2, _) = TransactionRequest::from_bytes(&data, 270).unwrap(); + let (tx2, _) = TransactionRequest::from_bytes(&data, L2ChainId::from(270)).unwrap(); assert_eq!(tx.gas, tx2.gas); assert_eq!(tx.gas_price, tx2.gas_price); assert_eq!(tx.nonce, tx2.nonce); assert_eq!(tx.input, tx2.input); assert_eq!(tx.value, tx2.value); - assert_eq!( - tx2.v.unwrap().as_u32() as u16, - signature.v_with_chain_id(270) - ); + assert_eq!(tx2.v.unwrap().as_u64(), signature.v_with_chain_id(270)); assert_eq!(tx2.s.unwrap(), signature.s().into()); assert_eq!(tx2.r.unwrap(), signature.r().into()); assert_eq!(address, tx2.from.unwrap()); @@ -1056,8 +1055,10 @@ mod tests { ..Default::default() }; - let msg = - PackedEthSignature::typed_data_to_signed_bytes(&Eip712Domain::new(L2ChainId(270)), &tx); + let msg = PackedEthSignature::typed_data_to_signed_bytes( + &Eip712Domain::new(L2ChainId::from(270)), + &tx, + ); let signature = PackedEthSignature::sign_raw(&private_key, &msg).unwrap(); let mut rlp = RlpStream::new(); @@ -1069,7 +1070,7 @@ mod tests { tx.r = Some(U256::from_big_endian(signature.r())); tx.s = Some(U256::from_big_endian(signature.s())); - let (tx2, _) = TransactionRequest::from_bytes(&data, 270).unwrap(); + let (tx2, _) = TransactionRequest::from_bytes(&data, L2ChainId::from(270)).unwrap(); assert_eq!(tx, tx2); } @@ -1098,14 +1099,15 @@ mod tests { chain_id: Some(270), ..Default::default() }; - let domain = Eip712Domain::new(L2ChainId(270)); + let domain = Eip712Domain::new(L2ChainId::from(270)); let signature = PackedEthSignature::sign_typed_data(&private_key, &domain, &transaction_request) .unwrap(); - let encoded_tx = transaction_request.get_signed_bytes(&signature, L2ChainId(270)); + let encoded_tx = transaction_request.get_signed_bytes(&signature, L2ChainId::from(270)); - let (decoded_tx, _) = TransactionRequest::from_bytes(encoded_tx.as_slice(), 270).unwrap(); + let (decoded_tx, _) = + TransactionRequest::from_bytes(encoded_tx.as_slice(), L2ChainId::from(270)).unwrap(); let recovered_signer = decoded_tx.from.unwrap(); assert_eq!(address, recovered_signer); } @@ -1137,14 +1139,15 @@ mod tests { chain_id: Some(270), ..Default::default() }; - let domain = Eip712Domain::new(L2ChainId(270)); + let domain = Eip712Domain::new(L2ChainId::from(270)); let signature = PackedEthSignature::sign_typed_data(&private_key, &domain, &transaction_request) .unwrap(); - let encoded_tx = transaction_request.get_signed_bytes(&signature, L2ChainId(270)); + let encoded_tx = transaction_request.get_signed_bytes(&signature, L2ChainId::from(270)); - let decoded_tx = TransactionRequest::from_bytes(encoded_tx.as_slice(), 272); + let decoded_tx = + TransactionRequest::from_bytes(encoded_tx.as_slice(), L2ChainId::from(272)); assert_eq!( decoded_tx, Err(SerializationTransactionError::WrongChainId(Some(270))) @@ -1184,7 +1187,8 @@ mod tests { let mut data = rlp.out().to_vec(); data.insert(0, EIP_1559_TX_TYPE); - let (decoded_tx, _) = TransactionRequest::from_bytes(data.as_slice(), 270).unwrap(); + let (decoded_tx, _) = + TransactionRequest::from_bytes(data.as_slice(), L2ChainId::from(270)).unwrap(); let recovered_signer = decoded_tx.from.unwrap(); assert_eq!(address, recovered_signer); } @@ -1221,7 +1225,7 @@ mod tests { let mut data = rlp.out().to_vec(); data.insert(0, EIP_1559_TX_TYPE); - let decoded_tx = TransactionRequest::from_bytes(data.as_slice(), 270); + let decoded_tx = TransactionRequest::from_bytes(data.as_slice(), L2ChainId::from(270)); assert_eq!( decoded_tx, Err(SerializationTransactionError::WrongChainId(Some(272))) @@ -1261,7 +1265,7 @@ mod tests { let mut data = rlp.out().to_vec(); data.insert(0, EIP_1559_TX_TYPE); - let res = TransactionRequest::from_bytes(data.as_slice(), 270); + let res = TransactionRequest::from_bytes(data.as_slice(), L2ChainId::from(270)); assert_eq!( res, Err(SerializationTransactionError::AccessListsNotSupported) @@ -1298,7 +1302,7 @@ mod tests { let mut data = rlp.out().to_vec(); data.insert(0, EIP_2930_TX_TYPE); - let res = TransactionRequest::from_bytes(data.as_slice(), 270); + let res = TransactionRequest::from_bytes(data.as_slice(), L2ChainId::from(270)); assert_eq!( res, Err(SerializationTransactionError::AccessListsNotSupported) @@ -1419,8 +1423,10 @@ mod tests { ..Default::default() }; - let msg = - PackedEthSignature::typed_data_to_signed_bytes(&Eip712Domain::new(L2ChainId(270)), &tx); + let msg = PackedEthSignature::typed_data_to_signed_bytes( + &Eip712Domain::new(L2ChainId::from(270)), + &tx, + ); let signature = PackedEthSignature::sign_raw(&private_key, &msg).unwrap(); let mut rlp = RlpStream::new(); @@ -1431,7 +1437,8 @@ mod tests { tx.v = Some(U64::from(signature.v())); tx.r = Some(U256::from_big_endian(signature.r())); tx.s = Some(U256::from_big_endian(signature.s())); - let request = TransactionRequest::from_bytes(data.as_slice(), 270).unwrap(); + let request = + TransactionRequest::from_bytes(data.as_slice(), L2ChainId::from(270)).unwrap(); assert!(matches!( L2Tx::from_request(request.0, random_tx_max_size), Err(SerializationTransactionError::OversizedData(_, _)) diff --git a/core/lib/types/src/tx/primitives/eip712_signature/typed_structure.rs b/core/lib/types/src/tx/primitives/eip712_signature/typed_structure.rs index 5ad48995a5c..999afbbe604 100644 --- a/core/lib/types/src/tx/primitives/eip712_signature/typed_structure.rs +++ b/core/lib/types/src/tx/primitives/eip712_signature/typed_structure.rs @@ -170,7 +170,7 @@ impl Eip712Domain { Self { name: Self::NAME.to_string(), version: Self::VERSION.to_string(), - chain_id: U256::from(*chain_id), + chain_id: U256::from(chain_id.as_u64()), } } } diff --git a/core/lib/types/src/tx/primitives/packed_eth_signature.rs b/core/lib/types/src/tx/primitives/packed_eth_signature.rs index 63f4911ea47..b249d151ef5 100644 --- a/core/lib/types/src/tx/primitives/packed_eth_signature.rs +++ b/core/lib/types/src/tx/primitives/packed_eth_signature.rs @@ -150,12 +150,10 @@ impl PackedEthSignature { pub fn v(&self) -> u8 { self.0.v() } - pub fn v_with_chain_id(&self, chain_id: u16) -> u16 { - self.0.v() as u16 + 35 + chain_id * 2 + pub fn v_with_chain_id(&self, chain_id: u64) -> u64 { + self.0.v() as u64 + 35 + chain_id * 2 } - pub fn unpack_v(v: u64) -> Result<(u8, Option), ParityCryptoError> { - use std::convert::TryInto; - + pub fn unpack_v(v: u64) -> Result<(u8, Option), ParityCryptoError> { if v == 27 { return Ok((0, None)); } else if v == 28 { @@ -163,9 +161,6 @@ impl PackedEthSignature { } else if v >= 35 { let chain_id = (v - 35) >> 1; let v = v - 35 - chain_id * 2; - let chain_id = chain_id - .try_into() - .map_err(|_| ParityCryptoError::Custom("Invalid chain_id".to_string()))?; if v == 0 { return Ok((0, Some(chain_id))); } else if v == 1 { diff --git a/core/lib/vm/src/tests/l1_tx_execution.rs b/core/lib/vm/src/tests/l1_tx_execution.rs index 5afe6af7918..a231d8aba0b 100644 --- a/core/lib/vm/src/tests/l1_tx_execution.rs +++ b/core/lib/vm/src/tests/l1_tx_execution.rs @@ -41,7 +41,7 @@ fn test_l1_tx_execution() { is_service: true, tx_number_in_block: 0, sender: BOOTLOADER_ADDRESS, - key: tx_data.tx_hash(L2ChainId(0)), + key: tx_data.tx_hash(L2ChainId::from(0)), value: u256_to_h256(U256::from(1u32)), }]; diff --git a/core/lib/vm/src/tests/require_eip712.rs b/core/lib/vm/src/tests/require_eip712.rs index d77e4d6a33a..4c2515ae2ef 100644 --- a/core/lib/vm/src/tests/require_eip712.rs +++ b/core/lib/vm/src/tests/require_eip712.rs @@ -52,7 +52,7 @@ async fn test_require_eip712() { assert_eq!(vm.get_eth_balance(beneficiary.address), U256::from(0)); - let chain_id: u16 = 270; + let chain_id: u32 = 270; // First, let's set the owners of the AA account to the private_address. // (so that messages signed by private_address, are authorized to act on behalf of the AA account). @@ -94,7 +94,7 @@ async fn test_require_eip712() { }; let aa_tx = private_account.sign_legacy_tx(aa_raw_tx).await; - let (tx_request, hash) = TransactionRequest::from_bytes(&aa_tx, 270).unwrap(); + let (tx_request, hash) = TransactionRequest::from_bytes(&aa_tx, L2ChainId::from(270)).unwrap(); let mut l2_tx: L2Tx = L2Tx::from_request(tx_request, 10000).unwrap(); l2_tx.set_input(aa_tx, hash); @@ -134,15 +134,16 @@ async fn test_require_eip712() { let transaction_request: TransactionRequest = tx_712.into(); - let domain = Eip712Domain::new(L2ChainId(chain_id)); + let domain = Eip712Domain::new(L2ChainId::from(chain_id)); let signature = private_account .get_pk_signer() .sign_typed_data(&domain, &transaction_request) .await .unwrap(); - let encoded_tx = transaction_request.get_signed_bytes(&signature, L2ChainId(chain_id)); + let encoded_tx = transaction_request.get_signed_bytes(&signature, L2ChainId::from(chain_id)); - let (aa_txn_request, aa_hash) = TransactionRequest::from_bytes(&encoded_tx, chain_id).unwrap(); + let (aa_txn_request, aa_hash) = + TransactionRequest::from_bytes(&encoded_tx, L2ChainId::from(chain_id)).unwrap(); let mut l2_tx = L2Tx::from_request(aa_txn_request, 100000).unwrap(); l2_tx.set_input(encoded_tx, aa_hash); diff --git a/core/lib/vm/src/tests/tester/vm_tester.rs b/core/lib/vm/src/tests/tester/vm_tester.rs index 19450244120..07dbf89a8eb 100644 --- a/core/lib/vm/src/tests/tester/vm_tester.rs +++ b/core/lib/vm/src/tests/tester/vm_tester.rs @@ -142,7 +142,7 @@ impl VmTesterBuilder { gas_limit: BLOCK_GAS_LIMIT, execution_mode: TxExecutionMode::VerifyExecute, default_validation_computational_gas_limit: BLOCK_GAS_LIMIT, - chain_id: L2ChainId(270), + chain_id: L2ChainId::from(270), }, deployer: None, rich_accounts: vec![], diff --git a/core/lib/zksync_core/src/api_server/web3/namespaces/eth.rs b/core/lib/zksync_core/src/api_server/web3/namespaces/eth.rs index 89434de7911..b68cfc247be 100644 --- a/core/lib/zksync_core/src/api_server/web3/namespaces/eth.rs +++ b/core/lib/zksync_core/src/api_server/web3/namespaces/eth.rs @@ -369,7 +369,7 @@ impl EthNamespace { #[tracing::instrument(skip(self))] pub fn chain_id_impl(&self) -> U64 { - self.state.api_config.l2_chain_id.0.into() + self.state.api_config.l2_chain_id.as_u64().into() } #[tracing::instrument(skip(self))] diff --git a/core/lib/zksync_core/src/api_server/web3/namespaces/net.rs b/core/lib/zksync_core/src/api_server/web3/namespaces/net.rs index b31279ab693..88a732505ab 100644 --- a/core/lib/zksync_core/src/api_server/web3/namespaces/net.rs +++ b/core/lib/zksync_core/src/api_server/web3/namespaces/net.rs @@ -11,7 +11,7 @@ impl NetNamespace { } pub fn version_impl(&self) -> String { - self.zksync_network_id.to_string() + self.zksync_network_id.as_u64().to_string() } pub fn peer_count_impl(&self) -> U256 { diff --git a/core/lib/zksync_core/src/api_server/web3/state.rs b/core/lib/zksync_core/src/api_server/web3/state.rs index 8ea44db4a63..6ed90ec1d3c 100644 --- a/core/lib/zksync_core/src/api_server/web3/state.rs +++ b/core/lib/zksync_core/src/api_server/web3/state.rs @@ -65,7 +65,7 @@ impl InternalApiConfig { ) -> Self { Self { l1_chain_id: eth_config.network.chain_id(), - l2_chain_id: L2ChainId(eth_config.zksync_network_id), + l2_chain_id: eth_config.zksync_network_id, max_tx_size: web3_config.max_tx_size, estimate_gas_scale_factor: web3_config.estimate_gas_scale_factor, estimate_gas_acceptable_overestimation: web3_config @@ -195,7 +195,7 @@ impl Clone for RpcState { impl RpcState { pub fn parse_transaction_bytes(&self, bytes: &[u8]) -> Result<(L2Tx, H256), Web3Error> { let chain_id = self.api_config.l2_chain_id; - let (tx_request, hash) = api::TransactionRequest::from_bytes(bytes, chain_id.0)?; + let (tx_request, hash) = api::TransactionRequest::from_bytes(bytes, chain_id)?; Ok(( L2Tx::from_request(tx_request, self.api_config.max_tx_size)?, diff --git a/core/lib/zksync_core/src/genesis.rs b/core/lib/zksync_core/src/genesis.rs index f613b2b6a48..ccc9e949d2d 100644 --- a/core/lib/zksync_core/src/genesis.rs +++ b/core/lib/zksync_core/src/genesis.rs @@ -389,7 +389,7 @@ mod tests { first_l1_verifier_config: L1VerifierConfig::default(), first_verifier_address: Address::random(), }; - ensure_genesis_state(&mut conn, L2ChainId(270), ¶ms) + ensure_genesis_state(&mut conn, L2ChainId::from(270), ¶ms) .await .unwrap(); @@ -403,8 +403,34 @@ mod tests { assert_ne!(root_hash, H256::zero()); // Check that `ensure_genesis_state()` doesn't panic on repeated runs. - ensure_genesis_state(&mut conn, L2ChainId(270), ¶ms) + ensure_genesis_state(&mut conn, L2ChainId::from(270), ¶ms) .await .unwrap(); } + + #[db_test] + async fn running_genesis_with_big_chain_id(pool: ConnectionPool) { + let mut conn: StorageProcessor<'_> = pool.access_storage().await.unwrap(); + conn.blocks_dal().delete_genesis().await.unwrap(); + + let params = GenesisParams { + protocol_version: ProtocolVersionId::latest(), + first_validator: Address::random(), + base_system_contracts: BaseSystemContracts::load_from_disk(), + system_contracts: get_system_smart_contracts(), + first_l1_verifier_config: L1VerifierConfig::default(), + first_verifier_address: Address::random(), + }; + ensure_genesis_state(&mut conn, L2ChainId::max(), ¶ms) + .await + .unwrap(); + + assert!(!conn.blocks_dal().is_genesis_needed().await.unwrap()); + let metadata = conn + .blocks_dal() + .get_l1_batch_metadata(L1BatchNumber(0)) + .await; + let root_hash = metadata.unwrap().unwrap().metadata.root_hash; + assert_ne!(root_hash, H256::zero()); + } } diff --git a/core/lib/zksync_core/src/lib.rs b/core/lib/zksync_core/src/lib.rs index f40074d600c..028a746ced0 100644 --- a/core/lib/zksync_core/src/lib.rs +++ b/core/lib/zksync_core/src/lib.rs @@ -42,7 +42,7 @@ use zksync_types::{ proofs::AggregationRound, protocol_version::{L1VerifierConfig, VerifierParams}, system_contracts::get_system_smart_contracts, - Address, L2ChainId, PackedEthSignature, ProtocolVersionId, + Address, PackedEthSignature, ProtocolVersionId, }; use zksync_verification_key_server::get_cached_commitments; @@ -124,7 +124,7 @@ pub async fn genesis_init( genesis::ensure_genesis_state( &mut storage, - L2ChainId(network_config.zksync_network_id), + network_config.zksync_network_id, &genesis::GenesisParams { // We consider the operator to be the first validator for now. first_validator: operator_address, @@ -365,7 +365,7 @@ pub async fn initialize_components( let tx_sender_config = TxSenderConfig::new( &state_keeper_config, &api_config.web3_json_rpc, - L2ChainId(network_config.zksync_network_id), + network_config.zksync_network_id, ); let internal_api_config = InternalApiConfig::new( &network_config, diff --git a/core/lib/zksync_core/src/metadata_calculator/helpers.rs b/core/lib/zksync_core/src/metadata_calculator/helpers.rs index bd79b8866f4..0abcc30c644 100644 --- a/core/lib/zksync_core/src/metadata_calculator/helpers.rs +++ b/core/lib/zksync_core/src/metadata_calculator/helpers.rs @@ -366,7 +366,7 @@ mod tests { async fn loaded_logs_equivalence_basics(pool: ConnectionPool) { ensure_genesis_state( &mut pool.access_storage().await.unwrap(), - L2ChainId(270), + L2ChainId::from(270), &mock_genesis_params(), ) .await @@ -389,7 +389,7 @@ mod tests { #[db_test] async fn loaded_logs_equivalence_with_zero_no_op_logs(pool: ConnectionPool) { let mut storage = pool.access_storage().await.unwrap(); - ensure_genesis_state(&mut storage, L2ChainId(270), &mock_genesis_params()) + ensure_genesis_state(&mut storage, L2ChainId::from(270), &mock_genesis_params()) .await .unwrap(); @@ -467,7 +467,7 @@ mod tests { #[db_test] async fn loaded_logs_equivalence_with_non_zero_no_op_logs(pool: ConnectionPool) { let mut storage = pool.access_storage().await.unwrap(); - ensure_genesis_state(&mut storage, L2ChainId(270), &mock_genesis_params()) + ensure_genesis_state(&mut storage, L2ChainId::from(270), &mock_genesis_params()) .await .unwrap(); @@ -514,7 +514,7 @@ mod tests { #[db_test] async fn loaded_logs_equivalence_with_protective_reads(pool: ConnectionPool) { let mut storage = pool.access_storage().await.unwrap(); - ensure_genesis_state(&mut storage, L2ChainId(270), &mock_genesis_params()) + ensure_genesis_state(&mut storage, L2ChainId::from(270), &mock_genesis_params()) .await .unwrap(); diff --git a/core/lib/zksync_core/src/metadata_calculator/tests.rs b/core/lib/zksync_core/src/metadata_calculator/tests.rs index 00d34d7f870..e5e6e1f43ba 100644 --- a/core/lib/zksync_core/src/metadata_calculator/tests.rs +++ b/core/lib/zksync_core/src/metadata_calculator/tests.rs @@ -397,7 +397,7 @@ async fn setup_calculator_with_options( let mut storage = pool.access_storage().await.unwrap(); if storage.blocks_dal().is_genesis_needed().await.unwrap() { - let chain_id = L2ChainId(270); + let chain_id = L2ChainId::from(270); let protocol_version = ProtocolVersionId::latest(); let base_system_contracts = BaseSystemContracts::load_from_disk(); let system_contracts = get_system_smart_contracts(); @@ -650,7 +650,7 @@ async fn deduplication_works_as_expected(pool: ConnectionPool) { let first_verifier_address = Address::zero(); ensure_genesis_state( &mut storage, - L2ChainId(270), + L2ChainId::from(270), &GenesisParams { protocol_version, first_validator, diff --git a/core/lib/zksync_core/src/state_keeper/batch_executor/tests/tester.rs b/core/lib/zksync_core/src/state_keeper/batch_executor/tests/tester.rs index 2fd2df20e6c..d41b0c98a82 100644 --- a/core/lib/zksync_core/src/state_keeper/batch_executor/tests/tester.rs +++ b/core/lib/zksync_core/src/state_keeper/batch_executor/tests/tester.rs @@ -28,7 +28,7 @@ use crate::state_keeper::{ }; const DEFAULT_GAS_PER_PUBDATA: u32 = 100; -const CHAIN_ID: L2ChainId = L2ChainId(270); +const CHAIN_ID: u32 = 270; /// Representation of configuration parameters used by the state keeper. /// Has sensible defaults for most tests, each of which can be overridden. @@ -144,7 +144,7 @@ impl Tester { create_genesis_l1_batch( &mut storage, self.fee_account, - CHAIN_ID, + L2ChainId::from(CHAIN_ID), ProtocolVersionId::latest(), &BASE_SYSTEM_CONTRACTS, &get_system_smart_contracts(), diff --git a/core/lib/zksync_core/src/state_keeper/io/tests/tester.rs b/core/lib/zksync_core/src/state_keeper/io/tests/tester.rs index 5f1881afb3f..fb9ec33c54b 100644 --- a/core/lib/zksync_core/src/state_keeper/io/tests/tester.rs +++ b/core/lib/zksync_core/src/state_keeper/io/tests/tester.rs @@ -91,7 +91,7 @@ impl Tester { Duration::from_secs(1), l2_erc20_bridge_addr, BLOCK_GAS_LIMIT, - L2ChainId(270), + L2ChainId::from(270), ) .await; @@ -108,7 +108,7 @@ impl Tester { create_genesis_l1_batch( &mut storage, Address::repeat_byte(0x01), - L2ChainId(270), + L2ChainId::from(270), ProtocolVersionId::latest(), &self.base_system_contracts, &get_system_smart_contracts(), diff --git a/core/lib/zksync_core/src/state_keeper/mod.rs b/core/lib/zksync_core/src/state_keeper/mod.rs index 5ccae06a3f4..8eef5d6adbc 100644 --- a/core/lib/zksync_core/src/state_keeper/mod.rs +++ b/core/lib/zksync_core/src/state_keeper/mod.rs @@ -8,7 +8,6 @@ use zksync_config::{ ContractsConfig, DBConfig, }; use zksync_dal::ConnectionPool; -use zksync_types::L2ChainId; mod batch_executor; pub(crate) mod extractors; @@ -71,7 +70,7 @@ where mempool_config.delay_interval(), contracts_config.l2_erc20_bridge_addr, state_keeper_config.validation_computational_gas_limit, - L2ChainId(network_config.zksync_network_id), + network_config.zksync_network_id, ) .await; diff --git a/core/lib/zksync_core/src/state_keeper/tests/mod.rs b/core/lib/zksync_core/src/state_keeper/tests/mod.rs index 4f8f1fe364d..d269b1fea67 100644 --- a/core/lib/zksync_core/src/state_keeper/tests/mod.rs +++ b/core/lib/zksync_core/src/state_keeper/tests/mod.rs @@ -58,7 +58,7 @@ pub(super) fn default_system_env() -> SystemEnv { gas_limit: BLOCK_GAS_LIMIT, execution_mode: TxExecutionMode::VerifyExecute, default_validation_computational_gas_limit: BLOCK_GAS_LIMIT, - chain_id: L2ChainId(270), + chain_id: L2ChainId::from(270), } } @@ -147,7 +147,7 @@ pub(super) fn create_l2_transaction(fee_per_gas: u64, gas_per_pubdata: u32) -> L Nonce(0), fee, U256::zero(), - L2ChainId(271), + L2ChainId::from(271), &H256::repeat_byte(0x11), None, PaymasterParams::default(), diff --git a/core/lib/zksync_core/src/state_keeper/tests/tester.rs b/core/lib/zksync_core/src/state_keeper/tests/tester.rs index b855ce54560..62bd4307b4e 100644 --- a/core/lib/zksync_core/src/state_keeper/tests/tester.rs +++ b/core/lib/zksync_core/src/state_keeper/tests/tester.rs @@ -286,7 +286,7 @@ pub(crate) fn pending_batch_data( gas_limit: BLOCK_GAS_LIMIT, execution_mode: TxExecutionMode::VerifyExecute, default_validation_computational_gas_limit: BLOCK_GAS_LIMIT, - chain_id: L2ChainId(270), + chain_id: L2ChainId::from(270), }, pending_miniblocks, } @@ -601,7 +601,7 @@ impl StateKeeperIO for TestIO { gas_limit: BLOCK_GAS_LIMIT, execution_mode: TxExecutionMode::VerifyExecute, default_validation_computational_gas_limit: BLOCK_GAS_LIMIT, - chain_id: L2ChainId(270), + chain_id: L2ChainId::from(270), }, L1BatchEnv { previous_batch_hash: Some(H256::zero()), diff --git a/core/multivm_deps/vm_1_3_2/src/test_utils.rs b/core/multivm_deps/vm_1_3_2/src/test_utils.rs index 2ebaebb4e37..5acefe94a4b 100644 --- a/core/multivm_deps/vm_1_3_2/src/test_utils.rs +++ b/core/multivm_deps/vm_1_3_2/src/test_utils.rs @@ -172,7 +172,7 @@ pub fn mock_loadnext_test_call( nonce, fee, Default::default(), - L2ChainId(270), + L2ChainId::from(270), ð_private_key, None, Default::default(), @@ -209,7 +209,7 @@ pub fn mock_loadnext_gas_burn_call( nonce, fee, Default::default(), - L2ChainId(270), + L2ChainId::from(270), ð_private_key, None, Default::default(), @@ -276,7 +276,7 @@ pub fn get_deploy_tx( nonce, fee, U256::zero(), - L2ChainId(270), + L2ChainId::from(270), &account_private_key, Some(factory_deps), Default::default(), @@ -303,7 +303,7 @@ pub fn get_error_tx( nonce, fee, U256::zero(), - L2ChainId(270), + L2ChainId::from(270), &account_private_key, Some(factory_deps), Default::default(), diff --git a/core/multivm_deps/vm_m5/src/test_utils.rs b/core/multivm_deps/vm_m5/src/test_utils.rs index 13cb91a5782..83ef7575805 100644 --- a/core/multivm_deps/vm_m5/src/test_utils.rs +++ b/core/multivm_deps/vm_m5/src/test_utils.rs @@ -171,7 +171,7 @@ pub fn mock_loadnext_test_call( nonce, fee, Default::default(), - L2ChainId(270), + L2ChainId::from(270), ð_private_key, None, Default::default(), @@ -208,7 +208,7 @@ pub fn mock_loadnext_gas_burn_call( nonce, fee, Default::default(), - L2ChainId(270), + L2ChainId::from(270), ð_private_key, None, Default::default(), @@ -275,7 +275,7 @@ pub fn get_deploy_tx( nonce, fee, U256::zero(), - L2ChainId(270), + L2ChainId::from(270), &account_private_key, Some(factory_deps), Default::default(), @@ -302,7 +302,7 @@ pub fn get_error_tx( nonce, fee, U256::zero(), - L2ChainId(270), + L2ChainId::from(270), &account_private_key, Some(factory_deps), Default::default(), diff --git a/core/multivm_deps/vm_m6/src/test_utils.rs b/core/multivm_deps/vm_m6/src/test_utils.rs index b196ed9e357..7d7b98685ef 100644 --- a/core/multivm_deps/vm_m6/src/test_utils.rs +++ b/core/multivm_deps/vm_m6/src/test_utils.rs @@ -171,7 +171,7 @@ pub fn mock_loadnext_test_call( nonce, fee, Default::default(), - L2ChainId(270), + L2ChainId::from(270), ð_private_key, None, Default::default(), @@ -208,7 +208,7 @@ pub fn mock_loadnext_gas_burn_call( nonce, fee, Default::default(), - L2ChainId(270), + L2ChainId::from(270), ð_private_key, None, Default::default(), @@ -275,7 +275,7 @@ pub fn get_deploy_tx( nonce, fee, U256::zero(), - L2ChainId(270), + L2ChainId::from(270), &account_private_key, Some(factory_deps), Default::default(), @@ -302,7 +302,7 @@ pub fn get_error_tx( nonce, fee, U256::zero(), - L2ChainId(270), + L2ChainId::from(270), &account_private_key, Some(factory_deps), Default::default(), diff --git a/core/tests/loadnext/src/account_pool.rs b/core/tests/loadnext/src/account_pool.rs index c19765d2bb3..556bee7f402 100644 --- a/core/tests/loadnext/src/account_pool.rs +++ b/core/tests/loadnext/src/account_pool.rs @@ -1,4 +1,4 @@ -use std::{collections::VecDeque, str::FromStr, sync::Arc, time::Duration}; +use std::{collections::VecDeque, convert::TryFrom, str::FromStr, sync::Arc, time::Duration}; use once_cell::sync::OnceCell; use rand::Rng; @@ -90,7 +90,7 @@ pub struct AccountPool { impl AccountPool { /// Generates all the required test accounts and prepares `Wallet` objects. pub async fn new(config: &LoadtestConfig) -> anyhow::Result { - let l2_chain_id = L2ChainId(config.l2_chain_id); + let l2_chain_id = L2ChainId::try_from(config.l2_chain_id).unwrap(); // Create a client for pinging the rpc. let client = HttpClientBuilder::default() .build(&config.l2_rpc_address) diff --git a/core/tests/loadnext/src/config.rs b/core/tests/loadnext/src/config.rs index 1c4b5ae7733..d62f4cdb63e 100644 --- a/core/tests/loadnext/src/config.rs +++ b/core/tests/loadnext/src/config.rs @@ -103,7 +103,7 @@ pub struct LoadtestConfig { /// Chain id of L2 node. #[serde(default = "default_l2_chain_id")] - pub l2_chain_id: u16, + pub l2_chain_id: u64, /// RPC address of L2 node. #[serde(default = "default_l2_rpc_address")] @@ -227,9 +227,9 @@ fn default_seed() -> Option { result } -fn default_l2_chain_id() -> u16 { +fn default_l2_chain_id() -> u64 { // 270 for rinkeby - let result = *L2ChainId::default(); + let result = L2ChainId::default().as_u64(); tracing::info!("Using default L2_CHAIN_ID: {result}"); result } diff --git a/core/tests/vm-benchmark/harness/src/lib.rs b/core/tests/vm-benchmark/harness/src/lib.rs index 55b4eb238d7..e439e1359fb 100644 --- a/core/tests/vm-benchmark/harness/src/lib.rs +++ b/core/tests/vm-benchmark/harness/src/lib.rs @@ -84,7 +84,7 @@ impl BenchmarkingVm { gas_limit: BLOCK_GAS_LIMIT, execution_mode: TxExecutionMode::VerifyExecute, default_validation_computational_gas_limit: BLOCK_GAS_LIMIT, - chain_id: L2ChainId(270), + chain_id: L2ChainId::from(270), }, Rc::new(RefCell::new(StorageView::new(&*STORAGE))), HistoryEnabled, @@ -120,7 +120,7 @@ pub fn get_deploy_tx(code: &[u8]) -> Transaction { gas_per_pubdata_limit: U256::from(MAX_GAS_PER_PUBDATA_BYTE), }, U256::zero(), - L2ChainId(270), + L2ChainId::from(270), &PRIVATE_KEY, Some(vec![code.to_vec()]), // maybe not needed? Default::default(),