revm_wiring/kzg.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
cfg_if::cfg_if! {
if #[cfg(feature = "c-kzg")] {
pub use c_kzg::KzgSettings;
} else if #[cfg(feature = "kzg-rs")] {
pub use kzg_rs::KzgSettings;
}
}
/// KZG Settings that allow us to specify a custom trusted setup.
/// or use hardcoded default settings.
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub enum EnvKzgSettings {
/// Default mainnet trusted setup
#[default]
Default,
/// Custom trusted setup.
Custom(std::sync::Arc<KzgSettings>),
}
impl EnvKzgSettings {
/// Return set KZG settings.
///
/// In will initialize the default settings if it is not already loaded.
pub fn get(&self) -> &KzgSettings {
match self {
Self::Default => {
cfg_if::cfg_if! {
if #[cfg(feature = "c-kzg")] {
c_kzg::ethereum_kzg_settings()
} else if #[cfg(feature = "kzg-rs")] {
use once_cell::race::OnceBox;
use std::boxed::Box;
static DEFAULT : OnceBox<KzgSettings> = OnceBox::new();
&DEFAULT.get_or_init(|| {
Box::new(KzgSettings::load_trusted_setup_file()
.expect("failed to load default trusted setup"))
})
} else {
unimplemented!()
}
}
}
Self::Custom(settings) => settings,
}
}
}