diff --git a/Cargo.lock b/Cargo.lock index f0aeba0ee07..f2590256616 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3515,6 +3515,7 @@ dependencies = [ "ethrex-blockchain", "ethrex-common 3.0.0", "ethrex-config", + "ethrex-crypto", "ethrex-dev", "ethrex-l2", "ethrex-l2-common", diff --git a/cmd/ethrex/Cargo.toml b/cmd/ethrex/Cargo.toml index bf33fdb179e..ae946ed1ec1 100644 --- a/cmd/ethrex/Cargo.toml +++ b/cmd/ethrex/Cargo.toml @@ -13,6 +13,7 @@ ethrex-config.workspace = true ethrex-blockchain.workspace = true ethrex-rpc.workspace = true ethrex-common.workspace = true +ethrex-crypto.workspace = true ethrex-p2p.workspace = true ethrex-storage.workspace = true ethrex-vm.workspace = true @@ -70,6 +71,7 @@ c-kzg = [ "ethrex-common/c-kzg", "ethrex-blockchain/c-kzg", "ethrex-p2p/c-kzg", + "ethrex-crypto/c-kzg", ] metrics = ["ethrex-blockchain/metrics", "ethrex-l2/metrics"] rocksdb = ["ethrex-storage/rocksdb", "ethrex-p2p/rocksdb"] diff --git a/cmd/ethrex/initializers.rs b/cmd/ethrex/initializers.rs index a269688b856..d7b0238a22a 100644 --- a/cmd/ethrex/initializers.rs +++ b/cmd/ethrex/initializers.rs @@ -403,6 +403,8 @@ pub async fn init_l1( display_chain_initialization(&genesis); raise_fd_limit()?; + debug!("Preloading KZG trusted setup"); + ethrex_crypto::kzg::warm_up_trusted_setup(); let store = init_store(datadir, genesis).await; diff --git a/crates/common/crypto/kzg.rs b/crates/common/crypto/kzg.rs index 5f87483c2d9..016ea209893 100644 --- a/crates/common/crypto/kzg.rs +++ b/crates/common/crypto/kzg.rs @@ -15,6 +15,14 @@ type Blob = [u8; BYTES_PER_BLOB]; type Commitment = Bytes48; type Proof = Bytes48; +/// Ensures the Ethereum trusted setup is loaded so later KZG operations avoid the first-call cost. +pub fn warm_up_trusted_setup() { + #[cfg(feature = "c-kzg")] + { + let _ = c_kzg::ethereum_kzg_settings(8); + } +} + #[derive(thiserror::Error, Debug)] pub enum KzgError { #[cfg(feature = "c-kzg")]