From b75d8bddebd22ef47ea0fb8008d33e19f15b9daa Mon Sep 17 00:00:00 2001 From: EchoAlice Date: Wed, 27 Sep 2023 10:17:29 -0600 Subject: [PATCH] Create ProofAndEvaluation struct. Simplify verify...batch() logic --- .../src/deneb/polynomial_commitments.rs | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/ethereum-consensus/src/deneb/polynomial_commitments.rs b/ethereum-consensus/src/deneb/polynomial_commitments.rs index 3e5752fcd..c5d77f28e 100644 --- a/ethereum-consensus/src/deneb/polynomial_commitments.rs +++ b/ethereum-consensus/src/deneb/polynomial_commitments.rs @@ -1,9 +1,6 @@ -#![allow(unused)] -use crate::{crypto::hash, primitives, ssz::prelude::ByteVector}; +use crate::{primitives, ssz::prelude::*}; use alloy_primitives::{uint, U256}; -use blst::min_pk::PublicKey; use c_kzg::{Bytes32, Bytes48, Error, KzgSettings}; -use ssz_rs::prelude::*; use std::ops::Deref; pub const BLS_MODULUS: U256 = @@ -20,14 +17,13 @@ pub type VersionedHash = primitives::Bytes32; pub type BLSFieldElement = U256; pub type Polynomial = Vec; // Should this polynomial type be an array? -const fn create_g1_point_at_infinity() -> [u8; 48] { - let mut arr: [u8; 48] = [0; 48]; - arr[0] = 0xc0; - arr -} - pub struct Blob(ByteVector); +pub struct ProofAndEvaluation { + proof: KzgProof, + evaluation: Bytes32, +} + #[derive(SimpleSerialize, Default, Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct KzgCommitment(ByteVector); @@ -58,14 +54,16 @@ fn compute_kzg_proof( blob: Blob, z_bytes: Bytes32, kzg_settings: &KzgSettings, -) -> Result<(KzgProof, Bytes32), Error> { +) -> Result { let inner = blob.0.as_ref(); let blob = c_kzg::Blob::from_bytes(inner).unwrap(); let (proof, evaluation) = c_kzg::KzgProof::compute_kzg_proof(&blob, &z_bytes, kzg_settings)?; let proof = ByteVector::try_from(proof.to_bytes().as_ref()).unwrap(); - Ok((KzgProof(proof), evaluation)) + let result = ProofAndEvaluation { proof: KzgProof(proof), evaluation }; + + Ok(result) } fn compute_blob_kzg_proof( @@ -130,17 +128,17 @@ fn verify_blob_kzg_proof_batch( ) -> Result { let mut c_kzg_blobs = Vec::with_capacity(blobs.len()); - for bytes in blobs.iter().map(|blob| blob.0.as_ref()) { - let blob = c_kzg::Blob::from_bytes(bytes)?; + for blob in blobs { + let inner = blob.0.as_ref(); + let blob = c_kzg::Blob::from_bytes(inner)?; c_kzg_blobs.push(blob); } - let out = c_kzg::KzgProof::verify_blob_kzg_proof_batch( + c_kzg::KzgProof::verify_blob_kzg_proof_batch( &c_kzg_blobs, commitments_bytes, proofs_bytes, kzg_settings, - )?; - - Ok(out) + ) + .map_err(Into::into) }