Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add eth sender signing mode #50

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
max_acceptable_priority_fee_in_gwei: 100000000000,
proof_loading_mode: ProofLoadingMode::OldProofFromDb,
pubdata_sending_mode: PubdataSendingMode::Calldata,
signing_mode: SigningMode::PrivateKey,
}),
gas_adjuster: Some(GasAdjusterConfig {
default_priority_fee_per_gas: 1000000000,
Expand Down Expand Up @@ -86,6 +87,13 @@ pub enum PubdataSendingMode {
Blobs,
}

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

/// The mode in which we send pubdata, either Calldata or Blobs
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 @@ -6,7 +6,10 @@ use zksync_basic_types::{
};
use zksync_consensus_utils::EncodeDist;

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 @@ -384,6 +387,7 @@ impl Distribution<configs::eth_sender::SenderConfig> for EncodeDist {
max_acceptable_priority_fee_in_gwei: self.sample(rng),
proof_loading_mode: self.sample(rng),
pubdata_sending_mode: PubdataSendingMode::Calldata,
signing_mode: SigningMode::PrivateKey,
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion core/lib/env_config/src/eth_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl FromEnv for GasAdjusterConfig {
#[cfg(test)]
mod tests {
use zksync_config::configs::eth_sender::{
ProofLoadingMode, ProofSendingMode, PubdataSendingMode,
ProofLoadingMode, ProofSendingMode, PubdataSendingMode, SigningMode,
};

use super::*;
Expand Down Expand Up @@ -64,6 +64,7 @@ mod tests {
max_acceptable_priority_fee_in_gwei: 100_000_000_000,
proof_loading_mode: ProofLoadingMode::OldProofFromDb,
pubdata_sending_mode: PubdataSendingMode::Calldata,
signing_mode: SigningMode::PrivateKey,
}),
gas_adjuster: Some(GasAdjusterConfig {
default_priority_fee_per_gas: 20000000000,
Expand Down Expand Up @@ -123,6 +124,7 @@ mod tests {
ETH_SENDER_SENDER_MAX_ACCEPTABLE_PRIORITY_FEE_IN_GWEI="100000000000"
ETH_SENDER_SENDER_PROOF_LOADING_MODE="OldProofFromDb"
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 @@ -60,6 +60,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 @@ -136,6 +154,10 @@ impl ProtoRepr for proto::Sender {
.and_then(|x| Ok(proto::ProofLoadingMode::try_from(*x)?))
.context("proof_loading_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 @@ -167,6 +189,7 @@ impl ProtoRepr for proto::Sender {
proto::PubdataSendingMode::new(&this.pubdata_sending_mode).into(),
),
proof_loading_mode: Some(proto::ProofLoadingMode::new(&this.proof_loading_mode).into()),
signing_mode: Some(proto::SigningMode::new(&this.signing_mode).into()),
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions core/lib/protobuf_config/src/proto/config/eth_sender.proto
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ enum PubdataSendingMode {
BLOBS = 1;
}

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,6 +49,7 @@ message Sender {
optional uint64 max_acceptable_priority_fee_in_gwei = 16; // required; gwei
optional PubdataSendingMode pubdata_sending_mode = 18; // required
optional ProofLoadingMode proof_loading_mode = 19;
optional SigningMode signing_mode = 99; // required
}

message GasAdjuster {
Expand Down
Loading
Loading