Skip to content

Commit

Permalink
chore: derive PartialEq and Hash on EnvKzgSettings (#1494)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rjected authored Jun 7, 2024
1 parent bdd1b8e commit 569c981
Showing 1 changed file with 1 addition and 23 deletions.
24 changes: 1 addition & 23 deletions crates/primitives/src/kzg/env_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ use super::{
trusted_setup_points::{G1_POINTS, G2_POINTS},
KzgSettings,
};
use core::hash::{Hash, Hasher};
use once_cell::race::OnceBox;
use std::{boxed::Box, sync::Arc};

/// KZG Settings that allow us to specify a custom trusted setup.
/// or use hardcoded default settings.
#[derive(Debug, Clone, Default, Eq)]
#[derive(Debug, Clone, Default, PartialEq, Eq, Hash)]
pub enum EnvKzgSettings {
/// Default mainnet trusted setup
#[default]
Expand All @@ -17,27 +16,6 @@ pub enum EnvKzgSettings {
Custom(Arc<c_kzg::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.
///
Expand Down

0 comments on commit 569c981

Please sign in to comment.