diff --git a/core/bin/zksync_server/src/node_builder.rs b/core/bin/zksync_server/src/node_builder.rs index 5ee5c8690..70afca4d8 100644 --- a/core/bin/zksync_server/src/node_builder.rs +++ b/core/bin/zksync_server/src/node_builder.rs @@ -3,7 +3,11 @@ use anyhow::Context; use zksync_config::{ - configs::{eth_sender::PubdataSendingMode, wallets::Wallets, GeneralConfig, Secrets}, + configs::{ + eth_sender::{PubdataSendingMode, SigningMode}, + wallets::Wallets, + GeneralConfig, Secrets, + }, ContractsConfig, GenesisConfig, }; use zksync_core_leftovers::Component; @@ -143,12 +147,28 @@ impl MainNodeBuilder { let eth_config = try_load_config!(self.configs.eth); let wallets = try_load_config!(self.wallets.eth_sender); + let eth_sender = self + .configs + .eth + .clone() + .context("eth_config")? + .sender + .context("sender")?; + + let signing_mode = eth_sender.signing_mode.clone(); + tracing::info!("Using signing mode: {:?}", signing_mode); + + let client_type = match signing_mode { + SigningMode::GcloudKms => SigningEthClientType::GKMSSigningEthClient, + SigningMode::PrivateKey => SigningEthClientType::PKSigningEthClient, + }; + self.node.add_layer(PKSigningEthClientLayer::new( eth_config, self.contracts_config.clone(), self.genesis_config.settlement_layer_id(), wallets, - SigningEthClientType::PKSigningEthClient, + client_type, )); Ok(self) } diff --git a/core/lib/config/src/configs/eth_sender.rs b/core/lib/config/src/configs/eth_sender.rs index 7e6ef2244..714a77294 100644 --- a/core/lib/config/src/configs/eth_sender.rs +++ b/core/lib/config/src/configs/eth_sender.rs @@ -42,6 +42,7 @@ impl EthConfig { pubdata_sending_mode: PubdataSendingMode::Calldata, tx_aggregation_paused: false, tx_aggregation_only_prove_and_execute: false, + signing_mode: SigningMode::PrivateKey, }), gas_adjuster: Some(GasAdjusterConfig { default_priority_fee_per_gas: 1000000000, @@ -88,6 +89,13 @@ pub enum PubdataSendingMode { RelayedL2Calldata, } +#[derive(Debug, Deserialize, Clone, Copy, PartialEq, Default)] +pub enum SigningMode { + #[default] + PrivateKey, + GcloudKms, +} + #[derive(Debug, Deserialize, Clone, PartialEq)] pub struct SenderConfig { pub aggregated_proof_sizes: Vec, @@ -127,6 +135,9 @@ pub struct SenderConfig { /// special mode specifically for gateway migration to decrease number of non-executed batches #[serde(default = "SenderConfig::default_tx_aggregation_only_prove_and_execute")] pub tx_aggregation_only_prove_and_execute: bool, + + /// Type of signing client for Ethereum transactions. + pub signing_mode: SigningMode, } impl SenderConfig { diff --git a/core/lib/config/src/testonly.rs b/core/lib/config/src/testonly.rs index 2ec91f5be..3318e9bb6 100644 --- a/core/lib/config/src/testonly.rs +++ b/core/lib/config/src/testonly.rs @@ -13,7 +13,9 @@ use zksync_consensus_utils::EncodeDist; use zksync_crypto_primitives::K256PrivateKey; use crate::configs::{ - self, eth_sender::PubdataSendingMode, external_price_api_client::ForcedPriceClientConfig, + self, + eth_sender::{PubdataSendingMode, SigningMode}, + external_price_api_client::ForcedPriceClientConfig, }; trait Sample { @@ -412,6 +414,7 @@ impl Distribution for EncodeDist { pubdata_sending_mode: PubdataSendingMode::Calldata, tx_aggregation_paused: false, tx_aggregation_only_prove_and_execute: false, + signing_mode: SigningMode::PrivateKey, } } } diff --git a/core/lib/env_config/src/eth_sender.rs b/core/lib/env_config/src/eth_sender.rs index 64e0a89d5..07d44648e 100644 --- a/core/lib/env_config/src/eth_sender.rs +++ b/core/lib/env_config/src/eth_sender.rs @@ -41,7 +41,7 @@ impl FromEnv for GasAdjusterConfig { #[cfg(test)] mod tests { - use zksync_config::configs::eth_sender::{ProofSendingMode, PubdataSendingMode}; + use zksync_config::configs::eth_sender::{ProofSendingMode, PubdataSendingMode, SigningMode}; use super::*; use crate::test_utils::{hash, EnvMutex}; @@ -58,7 +58,6 @@ mod tests { aggregated_block_execute_deadline: 4_000, max_aggregated_tx_gas: 4_000_000, max_eth_tx_data_size: 120_000, - timestamp_criteria_max_allowed_lag: 30, max_aggregated_blocks_to_commit: 3, max_aggregated_blocks_to_execute: 4, @@ -72,6 +71,7 @@ mod tests { pubdata_sending_mode: PubdataSendingMode::Calldata, tx_aggregation_only_prove_and_execute: false, tx_aggregation_paused: false, + signing_mode: SigningMode::PrivateKey, }), gas_adjuster: Some(GasAdjusterConfig { default_priority_fee_per_gas: 20000000000, @@ -136,6 +136,7 @@ mod tests { ETH_SENDER_SENDER_PUBDATA_SENDING_MODE="Calldata" ETH_WATCH_CONFIRMATIONS_FOR_ETH_EVENT="0" ETH_WATCH_ETH_NODE_POLL_INTERVAL="300" + ETH_SENDER_SENDER_SIGNING_MODE="PrivateKey" ETH_CLIENT_WEB3_URL="http://127.0.0.1:8545" "#; diff --git a/core/lib/protobuf_config/src/eth.rs b/core/lib/protobuf_config/src/eth.rs index 273b7f4e3..7eede7f7f 100644 --- a/core/lib/protobuf_config/src/eth.rs +++ b/core/lib/protobuf_config/src/eth.rs @@ -46,6 +46,24 @@ impl proto::PubdataSendingMode { } } +impl proto::SigningMode { + fn new(x: &configs::eth_sender::SigningMode) -> Self { + use configs::eth_sender::SigningMode as From; + match x { + From::PrivateKey => Self::PrivateKey, + From::GcloudKms => Self::GcloudKms, + } + } + + fn parse(&self) -> configs::eth_sender::SigningMode { + use configs::eth_sender::SigningMode as To; + match self { + Self::PrivateKey => To::PrivateKey, + Self::GcloudKms => To::GcloudKms, + } + } +} + impl ProtoRepr for proto::Eth { type Type = configs::eth_sender::EthConfig; @@ -115,6 +133,10 @@ impl ProtoRepr for proto::Sender { .parse(), tx_aggregation_only_prove_and_execute: self.tx_aggregation_paused.unwrap_or(false), tx_aggregation_paused: self.tx_aggregation_only_prove_and_execute.unwrap_or(false), + signing_mode: required(&self.signing_mode) + .and_then(|x| Ok(proto::SigningMode::try_from(*x)?)) + .context("signing_mode")? + .parse(), }) } @@ -147,6 +169,7 @@ impl ProtoRepr for proto::Sender { ), tx_aggregation_only_prove_and_execute: Some(this.tx_aggregation_only_prove_and_execute), tx_aggregation_paused: Some(this.tx_aggregation_paused), + signing_mode: Some(proto::SigningMode::new(&this.signing_mode).into()), } } } diff --git a/core/lib/protobuf_config/src/proto/config/eth_sender.proto b/core/lib/protobuf_config/src/proto/config/eth_sender.proto index b102a08be..39d3bb5ab 100644 --- a/core/lib/protobuf_config/src/proto/config/eth_sender.proto +++ b/core/lib/protobuf_config/src/proto/config/eth_sender.proto @@ -6,7 +6,8 @@ message ETH { optional Sender sender = 1; // required optional GasAdjuster gas_adjuster = 2; // required optional ETHWatch watcher = 3; // required - reserved 4; reserved "web3_url"; + reserved 4; + reserved "web3_url"; } enum ProofSendingMode { @@ -27,6 +28,11 @@ enum PubdataSendingMode { RELAYED_L2_CALLDATA = 3; } +enum SigningMode { + PRIVATE_KEY = 0; + GCLOUD_KMS = 1; +} + message Sender { repeated uint64 aggregated_proof_sizes = 1; // ? optional uint64 wait_confirmations = 2; // optional @@ -45,9 +51,11 @@ message Sender { optional uint64 l1_batch_min_age_before_execute_seconds = 15; // optional; s optional uint64 max_acceptable_priority_fee_in_gwei = 16; // required; gwei optional PubdataSendingMode pubdata_sending_mode = 18; // required - reserved 19; reserved "proof_loading_mode"; + reserved 19; + reserved "proof_loading_mode"; optional bool tx_aggregation_paused = 20; // required optional bool tx_aggregation_only_prove_and_execute = 21; // required + optional SigningMode signing_mode = 99; // required } message GasAdjuster { diff --git a/etc/env/base/eth_sender.toml b/etc/env/base/eth_sender.toml index 31fe626c8..0cead97cf 100644 --- a/etc/env/base/eth_sender.toml +++ b/etc/env/base/eth_sender.toml @@ -48,6 +48,8 @@ max_acceptable_priority_fee_in_gwei = 100000000000 pubdata_sending_mode = "Blobs" +signing_mode = "PrivateKey" + [eth_sender.gas_adjuster] # Priority fee to be used by GasAdjuster (in wei). default_priority_fee_per_gas = 1_000_000_000