-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] Move Mainnet KZG group and Lazy<KzgSettings> (#368)
* modification Eip1559Estimation return type * chore: fmt * done with trusted_setup_point * mod: done with env_settings * mod: fmt * fix CI prompts * debuging CI (no_std) * fmt * del .DS_store * fmt * touchup --------- Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com>
- Loading branch information
1 parent
98e9012
commit 936f065
Showing
9 changed files
with
4,392 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
.vscode | ||
.idea | ||
.env | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
use crate::eip4844::trusted_setup_points::{G1_POINTS, G2_POINTS}; | ||
use c_kzg::KzgSettings; | ||
use std::{ | ||
hash::{Hash, Hasher}, | ||
sync::Arc, | ||
}; | ||
|
||
/// KZG Settings that allow us to specify a custom trusted setup. | ||
/// or use hardcoded default settings. | ||
#[derive(Debug, Clone, Default, Eq)] | ||
pub enum EnvKzgSettings { | ||
/// Default mainnet trusted setup | ||
#[default] | ||
Default, | ||
/// Custom trusted setup. | ||
Custom(Arc<KzgSettings>), | ||
} | ||
|
||
// Implement PartialEq and Hash manually because `c_kzg::KzgSettings` does not implement them | ||
impl PartialEq for EnvKzgSettings { | ||
fn eq(&self, other: &Self) -> bool { | ||
match (self, other) { | ||
(Self::Default, Self::Default) => true, | ||
(Self::Custom(a), Self::Custom(b)) => Arc::ptr_eq(a, b), | ||
_ => false, | ||
} | ||
} | ||
} | ||
|
||
impl Hash for EnvKzgSettings { | ||
fn hash<H: Hasher>(&self, state: &mut H) { | ||
core::mem::discriminant(self).hash(state); | ||
match self { | ||
Self::Default => {} | ||
Self::Custom(settings) => Arc::as_ptr(settings).hash(state), | ||
} | ||
} | ||
} | ||
|
||
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 => { | ||
let load = || { | ||
KzgSettings::load_trusted_setup(G1_POINTS.as_ref(), G2_POINTS.as_ref()) | ||
.expect("failed to load default trusted setup") | ||
}; | ||
#[cfg(feature = "std")] | ||
{ | ||
use once_cell as _; | ||
use std::sync::OnceLock; | ||
|
||
static DEFAULT: OnceLock<KzgSettings> = OnceLock::new(); | ||
DEFAULT.get_or_init(load) | ||
} | ||
#[cfg(not(feature = "std"))] | ||
{ | ||
use once_cell::race::OnceBox; | ||
static DEFAULT: OnceBox<KzgSettings> = OnceBox::new(); | ||
DEFAULT.get_or_init(|| alloc::boxed::Box::new(load)) | ||
} | ||
} | ||
Self::Custom(settings) => settings, | ||
} | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.