Skip to content

Commit

Permalink
feat: Add eth sender signing mode (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
JayT106 committed Sep 3, 2024
1 parent 045b7bd commit b1fd44c
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 7 deletions.
24 changes: 22 additions & 2 deletions core/bin/zksync_server/src/node_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
}
Expand Down
11 changes: 11 additions & 0 deletions core/lib/config/src/configs/eth_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<usize>,
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion core/lib/config/src/testonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -412,6 +414,7 @@ impl Distribution<configs::eth_sender::SenderConfig> for EncodeDist {
pubdata_sending_mode: PubdataSendingMode::Calldata,
tx_aggregation_paused: false,
tx_aggregation_only_prove_and_execute: false,
signing_mode: SigningMode::PrivateKey,
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions core/lib/env_config/src/eth_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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"
"#;
Expand Down
23 changes: 23 additions & 0 deletions core/lib/protobuf_config/src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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(),
})
}

Expand Down Expand Up @@ -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()),
}
}
}
Expand Down
12 changes: 10 additions & 2 deletions core/lib/protobuf_config/src/proto/config/eth_sender.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions etc/env/base/eth_sender.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b1fd44c

Please sign in to comment.