Skip to content

Commit

Permalink
Problem: eth_sender transaction's base fee is not capped (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-nguy committed Jul 10, 2024
1 parent df44414 commit 6b8ae3c
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/lib/config/src/configs/eth_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ impl EthConfig {
proof_loading_mode: ProofLoadingMode::OldProofFromDb,
pubdata_sending_mode: PubdataSendingMode::Calldata,
signing_mode: SigningMode::PrivateKey,
max_acceptable_base_fee_in_wei: 100000000000,
}),
gas_adjuster: Some(GasAdjusterConfig {
default_priority_fee_per_gas: 1000000000,
Expand Down Expand Up @@ -133,6 +134,9 @@ pub struct SenderConfig {

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

/// Max acceptable base fee the sender is allowed to use to send L1 txs.
pub max_acceptable_base_fee_in_wei: u64,
}

impl SenderConfig {
Expand Down
1 change: 1 addition & 0 deletions core/lib/config/src/testonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ impl Distribution<configs::eth_sender::SenderConfig> for EncodeDist {
proof_loading_mode: self.sample(rng),
pubdata_sending_mode: PubdataSendingMode::Calldata,
signing_mode: SigningMode::PrivateKey,
max_acceptable_base_fee_in_wei: self.sample(rng),
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions core/lib/dal/sqlx-data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"db": "PostgreSQL"
}
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 @@ -65,6 +65,7 @@ mod tests {
proof_loading_mode: ProofLoadingMode::OldProofFromDb,
pubdata_sending_mode: PubdataSendingMode::Calldata,
signing_mode: SigningMode::PrivateKey,
max_acceptable_base_fee_in_wei: 100_000_000_000,
}),
gas_adjuster: Some(GasAdjusterConfig {
default_priority_fee_per_gas: 20000000000,
Expand Down Expand Up @@ -126,6 +127,7 @@ mod tests {
ETH_SENDER_SENDER_PUBDATA_SENDING_MODE="Calldata"
ETH_SENDER_SENDER_SIGNING_MODE="PrivateKey"
ETH_CLIENT_WEB3_URL="http://127.0.0.1:8545"
ETH_SENDER_SENDER_MAX_ACCEPTABLE_BASE_FEE_IN_WEI="100000000000"
"#;
lock.set_env(config);
Expand Down
3 changes: 3 additions & 0 deletions core/lib/protobuf_config/src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ impl ProtoRepr for proto::Sender {
.and_then(|x| Ok(proto::SigningMode::try_from(*x)?))
.context("signing_mode")?
.parse(),
max_acceptable_base_fee_in_wei: *required(&self.max_acceptable_base_fee_in_wei)
.context("max_acceptable_base_fee_in_wei")?,
})
}

Expand Down Expand Up @@ -190,6 +192,7 @@ impl ProtoRepr for proto::Sender {
),
proof_loading_mode: Some(proto::ProofLoadingMode::new(&this.proof_loading_mode).into()),
signing_mode: Some(proto::SigningMode::new(&this.signing_mode).into()),
max_acceptable_base_fee_in_wei: Some(this.max_acceptable_base_fee_in_wei),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions core/lib/protobuf_config/src/proto/config/eth_sender.proto
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ message Sender {
optional PubdataSendingMode pubdata_sending_mode = 18; // required
optional ProofLoadingMode proof_loading_mode = 19;
optional SigningMode signing_mode = 99; // required
optional uint64 max_acceptable_base_fee_in_wei = 100; // required; wei
}

message GasAdjuster {
Expand Down
2 changes: 2 additions & 0 deletions core/node/eth_sender/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ pub enum ETHSenderError {
EthereumGateWayError(#[from] zksync_eth_client::Error),
#[error("Token parsing Error: {0}")]
ParseError(#[from] contract::Error),
#[error("Max base fee exceeded")]
ExceedMaxBaseFee,
}
11 changes: 11 additions & 0 deletions core/node/eth_sender/src/eth_tx_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use zksync_types::{
use zksync_utils::time::seconds_since_epoch;

use super::{metrics::METRICS, ETHSenderError};
use crate::ETHSenderError::ExceedMaxBaseFee;

#[derive(Debug)]
struct EthFee {
Expand Down Expand Up @@ -244,6 +245,16 @@ impl EthTxManager {
blob_base_fee_per_gas,
} = self.calculate_fee(storage, tx, time_in_mempool).await?;

if base_fee_per_gas > self.config.max_acceptable_base_fee_in_wei {
tracing::info!(
"base fee per gas: {} exceed max acceptable fee in configuration: {}, skip transaction",
base_fee_per_gas,
self.config.max_acceptable_base_fee_in_wei
);

return Err(ExceedMaxBaseFee);
}

METRICS.used_base_fee_per_gas.observe(base_fee_per_gas);
METRICS
.used_priority_fee_per_gas
Expand Down
3 changes: 3 additions & 0 deletions etc/env/base/eth_sender.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ pubdata_sending_mode = "Blobs"

signing_mode = "PrivateKey"

# Max acceptable base fee for sending tx to L1
max_acceptable_base_fee_in_wei = 1000000000000

[eth_sender.gas_adjuster]
# Priority fee to be used by GasAdjuster (in wei).
default_priority_fee_per_gas = 1_000_000_000
Expand Down
1 change: 1 addition & 0 deletions etc/env/file_based/general.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ eth:
max_acceptable_priority_fee_in_gwei: 100000000000
proof_loading_mode: OLD_PROOF_FROM_DB
pubdata_sending_mode: BLOBS
max_acceptable_base_fee_in_wei: 100000000000
gas_adjuster:
default_priority_fee_per_gas: 1000000000
max_base_fee_samples: 10000
Expand Down

0 comments on commit 6b8ae3c

Please sign in to comment.