Blob references in ckzg (#4723)

* Move to using references in ckzg functions

* cleanup TrustedSetup a bit

* Remove BYTES_PER_FIELD_ELEMENT from KzgPreset
This commit is contained in:
Pawan Dhananjay
2023-09-13 19:14:30 -07:00
committed by GitHub
parent 4a31e369bf
commit 2cfcb51207
6 changed files with 72 additions and 73 deletions

View File

@@ -1,4 +1,4 @@
use c_kzg::{BYTES_PER_G1_POINT, BYTES_PER_G2_POINT, FIELD_ELEMENTS_PER_BLOB};
use c_kzg::{BYTES_PER_G1_POINT, BYTES_PER_G2_POINT};
use serde::{
de::{self, Deserializer, Visitor},
Deserialize, Serialize,
@@ -22,7 +22,6 @@ struct G2Point([u8; BYTES_PER_G2_POINT]);
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct TrustedSetup {
#[serde(rename = "setup_G1_lagrange")]
#[serde(deserialize_with = "deserialize_g1_points")]
g1_points: Vec<G1Point>,
#[serde(rename = "setup_G2")]
g2_points: Vec<G2Point>,
@@ -134,23 +133,6 @@ impl<'de> Deserialize<'de> for G2Point {
}
}
fn deserialize_g1_points<'de, D>(deserializer: D) -> Result<Vec<G1Point>, D::Error>
where
D: Deserializer<'de>,
{
let mut decoded: Vec<G1Point> = serde::de::Deserialize::deserialize(deserializer)?;
// FIELD_ELEMENTS_PER_BLOB is a compile time parameter that
// depends on whether lighthouse is compiled with minimal or mainnet features.
// Minimal and mainnet trusted setup parameters differ only by the
// number of G1 points they contain.
//
// Hence, we truncate the number of G1 points after deserialisation
// to ensure that we have the right number of g1 points in the
// trusted setup.
decoded.truncate(FIELD_ELEMENTS_PER_BLOB);
Ok(decoded)
}
fn strip_prefix(s: &str) -> &str {
if let Some(stripped) = s.strip_prefix("0x") {
stripped