Skip to content

Conversation

@JereSalo
Copy link
Contributor

Motivation

  • First time point evaluation precompile was called inside LEVM it took a long time to execute the block. This was because of the loading of the trusted setup. By doing it when initializing the node we avoid this.

Description

  • Add function to warm up trusted setup and use it in the client initialization

Closes #issue_number

@github-actions github-actions bot added the L1 Ethereum client label Oct 16, 2025
@github-actions
Copy link

Lines of code report

Total lines added: 8
Total lines removed: 0
Total lines changed: 8

Detailed view
+------------------------------------+-------+------+
| File                               | Lines | Diff |
+------------------------------------+-------+------+
| ethrex/cmd/ethrex/initializers.rs  | 445   | +2   |
+------------------------------------+-------+------+
| ethrex/crates/common/crypto/kzg.rs | 137   | +6   |
+------------------------------------+-------+------+

@edg-l
Copy link
Contributor

edg-l commented Oct 16, 2025

The function called calls this, i think this the correct thing to do.

Just one questiion, is only 8 needed? where does it come from? We could also preinit 1-15

pub fn ethereum_kzg_settings(precompute: u64) -> &'static KzgSettings {
    ethereum_kzg_settings_inner(precompute).as_ref()
}

/// Returns default Ethereum mainnet KZG settings as an `Arc`.
///
/// It is useful for sharing the settings in multiple places.
///
/// Note: Precompute values 0-15 (inclusive) are supported.
pub fn ethereum_kzg_settings_arc(precompute: u64) -> Arc<KzgSettings> {
    ethereum_kzg_settings_inner(precompute).clone()
}

fn ethereum_kzg_settings_inner(precompute: u64) -> &'static Arc<KzgSettings> {
    let cache_box = match precompute {
        0 => &CACHE_0,
        1 => &CACHE_1,
        2 => &CACHE_2,
        3 => &CACHE_3,
        4 => &CACHE_4,
        5 => &CACHE_5,
        6 => &CACHE_6,
        7 => &CACHE_7,
        8 => &CACHE_8,
        9 => &CACHE_9,
        10 => &CACHE_10,
        11 => &CACHE_11,
        12 => &CACHE_12,
        13 => &CACHE_13,
        14 => &CACHE_14,
        15 => &CACHE_15,
        _ => panic!(
            "Unsupported precompute value: {precompute}. Only values 0-15 (inclusive) are supported."
        ),
    };

    cache_box.get_or_init(|| {
        let settings = KzgSettings::load_trusted_setup(
            ETH_G1_MONOMIAL_POINTS,
            ETH_G1_LAGRANGE_POINTS,
            ETH_G2_MONOMIAL_POINTS,
            precompute,
        )
        .expect("failed to load default trusted setup");
        Box::new(Arc::new(settings))
    })
}

@github-project-automation github-project-automation bot moved this to In Review in ethrex_l1 Oct 16, 2025
@jrchatruc jrchatruc marked this pull request as ready for review October 16, 2025 15:01
@jrchatruc jrchatruc requested a review from a team as a code owner October 16, 2025 15:01
@ilitteri ilitteri added this pull request to the merge queue Oct 16, 2025
@JereSalo
Copy link
Contributor Author

@edg-l In the docs they suggest using 8 or 9. We've been using 8 in the client so I kept it as is because it made sense.
The methods they mention here are called inside other methods that we use within the client, like compute_cells.
image

Merged via the queue into main with commit a00c292 Oct 16, 2025
37 checks passed
@ilitteri ilitteri deleted the load_trusted_setup_on_init branch October 16, 2025 15:36
@github-project-automation github-project-automation bot moved this from In Review to Done in ethrex_l1 Oct 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

L1 Ethereum client

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants