diff --git a/core/lib/config/src/configs/wallets.rs b/core/lib/config/src/configs/wallets.rs index 678adb674f14..7b74cd441166 100644 --- a/core/lib/config/src/configs/wallets.rs +++ b/core/lib/config/src/configs/wallets.rs @@ -1,7 +1,7 @@ use zksync_basic_types::{Address, H160, H256}; use zksync_crypto_primitives::K256PrivateKey; -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] pub struct AddressWallet { address: Address, } @@ -16,7 +16,7 @@ impl AddressWallet { } } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] pub struct Wallet { address: Address, private_key: K256PrivateKey, @@ -58,18 +58,18 @@ impl Wallet { } } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] pub struct EthSender { pub operator: Wallet, pub blob_operator: Option, } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] pub struct StateKeeper { pub fee_account: AddressWallet, } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] pub struct Wallets { pub eth_sender: Option, pub state_keeper: Option, diff --git a/core/lib/config/src/testonly.rs b/core/lib/config/src/testonly.rs index a05b3d096253..b86904315508 100644 --- a/core/lib/config/src/testonly.rs +++ b/core/lib/config/src/testonly.rs @@ -9,6 +9,7 @@ use zksync_basic_types::{ L1BatchNumber, L1ChainId, L2ChainId, }; use zksync_consensus_utils::EncodeDist; +use zksync_crypto_primitives::K256PrivateKey; use crate::configs::{self, eth_sender::PubdataSendingMode}; @@ -681,11 +682,11 @@ impl Distribution for EncodeDist { .unwrap(), patch: VersionPatch(rng.gen()), }), - genesis_root_hash: rng.gen(), - rollup_last_leaf_index: self.sample(rng), - genesis_commitment: rng.gen(), - bootloader_hash: rng.gen(), - default_aa_hash: rng.gen(), + genesis_root_hash: Some(rng.gen()), + rollup_last_leaf_index: Some(self.sample(rng)), + genesis_commitment: Some(rng.gen()), + bootloader_hash: Some(rng.gen()), + default_aa_hash: Some(rng.gen()), fee_account: rng.gen(), l1_chain_id: L1ChainId(self.sample(rng)), l2_chain_id: L2ChainId::default(), @@ -804,3 +805,56 @@ impl Distribution for EncodeDist { } } } + +impl Distribution for EncodeDist { + fn sample(&self, rng: &mut R) -> configs::wallets::Wallet { + configs::wallets::Wallet::new(K256PrivateKey::from_bytes(rng.gen()).unwrap()) + } +} + +impl Distribution for EncodeDist { + fn sample(&self, rng: &mut R) -> configs::wallets::AddressWallet { + configs::wallets::AddressWallet::from_address(rng.gen()) + } +} + +impl Distribution for EncodeDist { + fn sample(&self, rng: &mut R) -> configs::wallets::StateKeeper { + configs::wallets::StateKeeper { + fee_account: self.sample(rng), + } + } +} + +impl Distribution for EncodeDist { + fn sample(&self, rng: &mut R) -> configs::wallets::EthSender { + configs::wallets::EthSender { + operator: self.sample(rng), + blob_operator: self.sample_opt(|| self.sample(rng)), + } + } +} + +impl Distribution for EncodeDist { + fn sample(&self, rng: &mut R) -> configs::wallets::Wallets { + configs::wallets::Wallets { + state_keeper: self.sample_opt(|| self.sample(rng)), + eth_sender: self.sample_opt(|| self.sample(rng)), + } + } +} + +impl Distribution for EncodeDist { + fn sample(&self, rng: &mut R) -> configs::en_config::ENConfig { + configs::en_config::ENConfig { + l2_chain_id: L2ChainId::default(), + l1_chain_id: L1ChainId(rng.gen()), + main_node_url: format!("localhost:{}", rng.gen::()).parse().unwrap(), + l1_batch_commit_data_generator_mode: match rng.gen_range(0..2) { + 0 => L1BatchCommitmentMode::Rollup, + _ => L1BatchCommitmentMode::Validium, + }, + main_node_rate_limit_rps: self.sample_opt(|| rng.gen()), + } + } +} diff --git a/core/lib/crypto_primitives/src/ecdsa_signature.rs b/core/lib/crypto_primitives/src/ecdsa_signature.rs index 026e42307dc6..a994e0f3c134 100644 --- a/core/lib/crypto_primitives/src/ecdsa_signature.rs +++ b/core/lib/crypto_primitives/src/ecdsa_signature.rs @@ -43,7 +43,7 @@ type Public = H512; /// /// Provides a safe to use `Debug` implementation (outputting the address corresponding to the key). /// The key is zeroized on drop. -#[derive(Clone)] +#[derive(Clone, PartialEq)] pub struct K256PrivateKey(SecretKey); impl fmt::Debug for K256PrivateKey { diff --git a/core/lib/protobuf_config/src/en.rs b/core/lib/protobuf_config/src/en.rs index b72a5b142cfb..b6323de6ea61 100644 --- a/core/lib/protobuf_config/src/en.rs +++ b/core/lib/protobuf_config/src/en.rs @@ -44,7 +44,7 @@ impl ProtoRepr for proto::ExternalNode { ) .into(), ), - main_node_rate_limit_rps: this.main_node_rate_limit_rps.map(|a| a.get() as u32), + main_node_rate_limit_rps: this.main_node_rate_limit_rps.map(|a| a.get() as u64), } } } diff --git a/core/lib/protobuf_config/src/lib.rs b/core/lib/protobuf_config/src/lib.rs index f7eb19f0d60c..0fbe46414c95 100644 --- a/core/lib/protobuf_config/src/lib.rs +++ b/core/lib/protobuf_config/src/lib.rs @@ -28,7 +28,6 @@ mod secrets; mod snapshots_creator; mod snapshot_recovery; -pub mod testonly; #[cfg(test)] mod tests; mod utils; diff --git a/core/lib/protobuf_config/src/proto/config/en.proto b/core/lib/protobuf_config/src/proto/config/en.proto index ac7cb59b156a..b0ec165b2f61 100644 --- a/core/lib/protobuf_config/src/proto/config/en.proto +++ b/core/lib/protobuf_config/src/proto/config/en.proto @@ -7,6 +7,6 @@ message ExternalNode { optional string main_node_url = 1; // required optional uint64 l2_chain_id = 2; // required optional uint64 l1_chain_id = 3; // required - optional uint32 main_node_rate_limit_rps = 6; // optional + optional uint64 main_node_rate_limit_rps = 6; // optional optional config.genesis.L1BatchCommitDataGeneratorMode l1_batch_commit_data_generator_mode = 7; // optional, default to rollup } diff --git a/core/lib/protobuf_config/src/testonly.rs b/core/lib/protobuf_config/src/testonly.rs deleted file mode 100644 index 8b137891791f..000000000000 --- a/core/lib/protobuf_config/src/testonly.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/core/lib/protobuf_config/src/tests.rs b/core/lib/protobuf_config/src/tests.rs index 8c7358ac28ea..3cb18c5bbf6d 100644 --- a/core/lib/protobuf_config/src/tests.rs +++ b/core/lib/protobuf_config/src/tests.rs @@ -39,6 +39,9 @@ fn test_encoding() { test_encode_all_formats::>(rng); test_encode_all_formats::>(rng); test_encode_all_formats::>(rng); + test_encode_all_formats::>(rng); + test_encode_all_formats::>(rng); + test_encode_all_formats::>(rng); } #[test] diff --git a/core/lib/protobuf_config/src/wallets.rs b/core/lib/protobuf_config/src/wallets.rs index 1c3b7413de60..31fa63fd2702 100644 --- a/core/lib/protobuf_config/src/wallets.rs +++ b/core/lib/protobuf_config/src/wallets.rs @@ -66,12 +66,20 @@ impl ProtoRepr for proto::Wallets { .as_ref() .map(|blob| proto::PrivateKeyWallet { address: Some(format!("{:?}", blob.address())), - private_key: Some(format!("{:?}", blob.private_key())), + private_key: Some(hex::encode( + blob.private_key().expose_secret().secret_bytes(), + )), }); ( Some(proto::PrivateKeyWallet { address: Some(format!("{:?}", eth_sender.operator.address())), - private_key: Some(format!("{:?}", eth_sender.operator.private_key())), + private_key: Some(hex::encode( + eth_sender + .operator + .private_key() + .expose_secret() + .secret_bytes(), + )), }), blob, )