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 Jul 11, 2024
1 parent fd683a1 commit 4f1f359
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 4 deletions.
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 @@ -40,6 +40,7 @@ impl EthConfig {
l1_batch_min_age_before_execute_seconds: None,
max_acceptable_priority_fee_in_gwei: 100000000000,
pubdata_sending_mode: PubdataSendingMode::Calldata,
signing_mode: SigningMode::PrivateKey,
}),
gas_adjuster: Some(GasAdjusterConfig {
default_priority_fee_per_gas: 1000000000,
Expand Down Expand Up @@ -84,6 +85,13 @@ pub enum PubdataSendingMode {
Custom,
}

#[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 @@ -117,6 +125,9 @@ pub struct SenderConfig {

/// The mode in which we send pubdata: Calldata, Blobs or Custom (DA layers, Object Store, etc.)
pub pubdata_sending_mode: PubdataSendingMode,

/// Type of signing client for Ethereum transactions.
pub signing_mode: SigningMode,
}

impl SenderConfig {
Expand Down
6 changes: 5 additions & 1 deletion core/lib/config/src/testonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ use zksync_basic_types::{
use zksync_consensus_utils::EncodeDist;
use zksync_crypto_primitives::K256PrivateKey;

use crate::configs::{self, eth_sender::PubdataSendingMode};
use crate::configs::{
self,
eth_sender::{PubdataSendingMode, SigningMode},
};

trait Sample {
fn sample(rng: &mut (impl Rng + ?Sized)) -> Self;
Expand Down Expand Up @@ -379,6 +382,7 @@ impl Distribution<configs::eth_sender::SenderConfig> for EncodeDist {
l1_batch_min_age_before_execute_seconds: self.sample(rng),
max_acceptable_priority_fee_in_gwei: self.sample(rng),
pubdata_sending_mode: PubdataSendingMode::Calldata,
signing_mode: SigningMode::PrivateKey,
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions core/lib/env_config/src/eth_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ mod tests {
l1_batch_min_age_before_execute_seconds: Some(1000),
max_acceptable_priority_fee_in_gwei: 100_000_000_000,
pubdata_sending_mode: PubdataSendingMode::Calldata,
signing_mode: SigningMode::PrivateKey,
}),
gas_adjuster: Some(GasAdjusterConfig {
default_priority_fee_per_gas: 20000000000,
Expand Down Expand Up @@ -131,6 +132,7 @@ mod tests {
ETH_SENDER_SENDER_L1_BATCH_MIN_AGE_BEFORE_EXECUTE_SECONDS="1000"
ETH_SENDER_SENDER_MAX_ACCEPTABLE_PRIORITY_FEE_IN_GWEI="100000000000"
ETH_SENDER_SENDER_PUBDATA_SENDING_MODE="Calldata"
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 @@ -44,6 +44,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 @@ -111,6 +129,10 @@ impl ProtoRepr for proto::Sender {
.and_then(|x| Ok(proto::PubdataSendingMode::try_from(*x)?))
.context("pubdata_sending_mode")?
.parse(),
signing_mode: required(&self.signing_mode)
.and_then(|x| Ok(proto::SigningMode::try_from(*x)?))
.context("signing_mode")?
.parse(),
})
}

Expand Down Expand Up @@ -141,6 +163,7 @@ impl ProtoRepr for proto::Sender {
pubdata_sending_mode: Some(
proto::PubdataSendingMode::new(&this.pubdata_sending_mode).into(),
),
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 @@ -26,6 +27,11 @@ enum PubdataSendingMode {
CUSTOM = 2;
}

enum SigningMode {
PRIVATE_KEY = 0;
GCLOUD_KMS = 1;
}

message Sender {
repeated uint64 aggregated_proof_sizes = 1; // ?
optional uint64 wait_confirmations = 2; // optional
Expand All @@ -44,7 +50,9 @@ 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 SigningMode signing_mode = 99; // required
}

message GasAdjuster {
Expand Down
5 changes: 4 additions & 1 deletion core/node/node_framework/examples/main_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ use zksync_node_framework::{
l1_gas::SequencerL1GasLayer,
metadata_calculator::MetadataCalculatorLayer,
object_store::ObjectStoreLayer,
pk_signing_eth_client::PKSigningEthClientLayer,
pk_signing_eth_client::{
PKSigningEthClientLayer, SigningEthClientType::PKSigningEthClient,
},
pools_layer::PoolsLayerBuilder,
proof_data_handler::ProofDataHandlerLayer,
query_eth_client::QueryEthClientLayer,
Expand Down Expand Up @@ -94,6 +96,7 @@ impl MainNodeBuilder {
ContractsConfig::from_env()?,
genesis.l1_chain_id,
wallets.eth_sender.context("Eth sender configs")?,
PKSigningEthClient,
));
Ok(self)
}
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 4f1f359

Please sign in to comment.