Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use spin instead of once_cell #12

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,14 @@ repository = "https://github.com/succinctlabs/kzg-rs"

[dependencies]
hex = { version = "0.4.3", default-features = false, features = ["alloc"] }
once_cell = { version = "1.19.0", default-features = false, features = [
"race",
"alloc",
] }
bls12_381 = { version = "0.8.0", package = "sp1_bls12_381", default-features = false, features = [
"groups",
"pairings",
"alloc",
] }
sha2 = { version = "0.10.8", default-features = false }
ff = { version = "0.13.0", default-features = false, features = ["derive"] }
spin = { version = "0.9.8", default-features = false, features = ["once"] }

[dev-dependencies]
hex = "0.4.3"
Expand Down
Binary file modified src/g1.bin
Binary file not shown.
Binary file modified src/g2.bin
Binary file not shown.
19 changes: 9 additions & 10 deletions src/trusted_setup.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use crate::{enums::KzgError, NUM_G1_POINTS, NUM_ROOTS_OF_UNITY};

use alloc::sync::Arc;
use bls12_381::{G1Affine, G2Affine, Scalar};
use core::{
hash::{Hash, Hasher},
mem::transmute,
slice,
};
use alloc::{boxed::Box, sync::Arc};
use bls12_381::{G1Affine, G2Affine, Scalar};
use once_cell::race::OnceBox;

use crate::{enums::KzgError, NUM_G1_POINTS, NUM_ROOTS_OF_UNITY};
use spin::Once;

pub const fn get_roots_of_unity() -> &'static [Scalar] {
const ROOT_OF_UNITY_BYTES: &[u8] = include_bytes!("roots_of_unity.bin");
Expand Down Expand Up @@ -81,11 +81,10 @@ impl EnvKzgSettings {
pub fn get(&self) -> &KzgSettings {
match self {
Self::Default => {
static DEFAULT: OnceBox<KzgSettings> = OnceBox::new();
DEFAULT.get_or_init(|| {
let settings = KzgSettings::load_trusted_setup_file()
.expect("failed to load default trusted setup");
Box::new(settings)
static DEFAULT: Once<KzgSettings> = Once::new();
DEFAULT.call_once(|| {
KzgSettings::load_trusted_setup_file()
.expect("failed to load default trusted setup")
})
}
Self::Custom(settings) => settings,
Expand Down
Loading