From 54e59fcc633cc1a84907180eb39517408f3da9bc Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Thu, 15 Aug 2024 22:17:41 +0100 Subject: [PATCH 1/3] add docs on exported types --- eip7594/src/lib.rs | 44 +++++++++++++++++++++++++++++++++++++++-- eip7594/src/verifier.rs | 4 ++-- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/eip7594/src/lib.rs b/eip7594/src/lib.rs index d3bca76c..0af89cc1 100644 --- a/eip7594/src/lib.rs +++ b/eip7594/src/lib.rs @@ -8,17 +8,57 @@ mod verifier; // Exported types // pub use errors::Error; +/// TrustedSetup contains the Structured Reference String(SRS) +/// needed to make and verify proofs. pub use trusted_setup::TrustedSetup; +/// BlobRef denotes a references to an opaque Blob. +/// +/// Note: This library never returns a Blob, which is why we +/// do not have a Blob type. pub type BlobRef<'a> = &'a [u8; BYTES_PER_BLOB]; + +/// Bytes48Ref denotes a reference to an untrusted cryptographic type +/// that can be represented in 48 bytes. This will be either a +/// purported KZGProof or a purported KZGCommitment. pub type Bytes48Ref<'a> = &'a [u8; 48]; +/// Cell contains a group of evaluations on a coset that one would like to +/// make and verify opening proofs about. +/// +/// Note: These are heap allocated. pub type Cell = Box<[u8; BYTES_PER_CELL]>; + +/// CellRef contains a reference to a Cell. +/// +/// Note: Similar to Blob, the library takes in references +/// to Cell and returns heap allocated instances as return types. pub type CellRef<'a> = &'a [u8; BYTES_PER_CELL]; +/// KZGProof denotes a 48 byte commitment to a polynomial +/// that one can use to prove that a polynomial f(x) was +/// correctly evaluated on a coset `H` and returned a set of points. pub type KZGProof = [u8; BYTES_PER_COMMITMENT]; + +/// KZGCommitment denotes a 48 byte commitment to a polynomial f(x) +/// that we would like to make and verify opening proofs about. pub type KZGCommitment = [u8; BYTES_PER_COMMITMENT]; + +/// CellIndex is reference to a Coset. +/// +/// We are able to use CellIndex instead of the coset because +/// the prover and verifier both know what the cosets are that +/// we will be making and verifying opening proofs for. pub type CellIndex = u64; -pub type RowIndex = u64; + +/// CommitmentIndex is a reference to a commitment. +/// +/// In order to make verification cheaper, the verifier will +/// deduplicate the list of commitments that they need to verify opening proofs for. +/// They will then refer to a commitment via its position in an array of deduplicated commitments +/// with the CommitmentIndex. +/// +/// Note: This is not exposed in the public API. +pub(crate) type CommitmentIndex = u64; use constants::{BYTES_PER_BLOB, BYTES_PER_CELL, BYTES_PER_COMMITMENT}; use prover::ProverContext; @@ -26,7 +66,7 @@ use rayon::ThreadPool; use std::sync::Arc; use verifier::VerifierContext; -/// The context that will be used to create and verify proofs. +/// The context that will be used to create and verify opening proofs. #[derive(Debug)] pub struct DASContext { thread_pool: Arc, diff --git a/eip7594/src/verifier.rs b/eip7594/src/verifier.rs index f5ce6c8f..64d54e46 100644 --- a/eip7594/src/verifier.rs +++ b/eip7594/src/verifier.rs @@ -203,13 +203,13 @@ mod validation { use crate::{ constants::{BYTES_PER_CELL, CELLS_PER_EXT_BLOB, EXTENSION_FACTOR}, verifier::VerifierError, - Bytes48Ref, CellIndex, CellRef, RowIndex, + Bytes48Ref, CellIndex, CellRef, CommitmentIndex, }; /// Validation logic for `verify_cell_kzg_proof_batch` pub fn verify_cell_kzg_proof_batch( deduplicated_commitments_bytes: &[Bytes48Ref], - commitment_indices: &[RowIndex], + commitment_indices: &[CommitmentIndex], cell_indices: &[CellIndex], cells: &[CellRef], proofs_bytes: &[Bytes48Ref], From 4b1a5cc184f371319acee8e5526cbeb115445499 Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Thu, 15 Aug 2024 22:29:32 +0100 Subject: [PATCH 2/3] Move CosetIndex and CommitmentIndex into kzg_multi_open --- cryptography/kzg_multi_open/src/fk20.rs | 2 +- .../kzg_multi_open/src/fk20/verifier.rs | 19 +++++++++++++++-- cryptography/kzg_multi_open/src/lib.rs | 5 ++++- eip7594/src/lib.rs | 21 ++++++------------- 4 files changed, 28 insertions(+), 19 deletions(-) diff --git a/cryptography/kzg_multi_open/src/fk20.rs b/cryptography/kzg_multi_open/src/fk20.rs index 97c3d988..25dd7b0a 100644 --- a/cryptography/kzg_multi_open/src/fk20.rs +++ b/cryptography/kzg_multi_open/src/fk20.rs @@ -13,4 +13,4 @@ mod verifier; pub use cosets::recover_evaluations_in_domain_order; pub use errors::VerifierError; pub use prover::{FK20Prover as Prover, Input as ProverInput}; -pub use verifier::FK20Verifier as Verifier; +pub use verifier::{CommitmentIndex, CosetIndex, FK20Verifier as Verifier}; diff --git a/cryptography/kzg_multi_open/src/fk20/verifier.rs b/cryptography/kzg_multi_open/src/fk20/verifier.rs index 9d8ead51..9207746c 100644 --- a/cryptography/kzg_multi_open/src/fk20/verifier.rs +++ b/cryptography/kzg_multi_open/src/fk20/verifier.rs @@ -12,6 +12,21 @@ use std::mem::size_of; use super::errors::VerifierError; +/// CosetIndex is a reference to a coset. +/// +/// Note: We are able to use CosetIndex instead of the coset because +/// the prover and verifier both know what the cosets are that +/// we will be making and verifying opening proofs for. +pub type CosetIndex = u64; + +/// CommitmentIndex is a reference to a commitment. +/// +/// In order to make verification cheaper, the verifier will +/// deduplicate the list of commitments that are needed in order to verify opening proofs. +/// They will then refer to a commitment via its position in an array of deduplicated commitments +/// with the CommitmentIndex. +pub type CommitmentIndex = u64; + /// FK20Verifier initializes all of the components needed to verify KZG multi point /// proofs that were created using the FK20Prover. /// @@ -103,9 +118,9 @@ impl FK20Verifier { &self, deduplicated_commitments: &[G1Point], - commitment_indices: &[u64], + commitment_indices: &[CommitmentIndex], - bit_reversed_coset_indices: &[u64], + bit_reversed_coset_indices: &[CosetIndex], bit_reversed_coset_evals: &[Vec], bit_reversed_proofs: &[G1Point], ) -> Result<(), VerifierError> { diff --git a/cryptography/kzg_multi_open/src/lib.rs b/cryptography/kzg_multi_open/src/lib.rs index 365123c3..6fac861d 100644 --- a/cryptography/kzg_multi_open/src/lib.rs +++ b/cryptography/kzg_multi_open/src/lib.rs @@ -2,7 +2,10 @@ pub mod commit_key; mod fk20; pub mod opening_key; -pub use fk20::{recover_evaluations_in_domain_order, Prover, ProverInput, Verifier, VerifierError}; +pub use fk20::{ + recover_evaluations_in_domain_order, CommitmentIndex, CosetIndex, Prover, ProverInput, + Verifier, VerifierError, +}; #[cfg(test)] mod naive; diff --git a/eip7594/src/lib.rs b/eip7594/src/lib.rs index 0af89cc1..3214f278 100644 --- a/eip7594/src/lib.rs +++ b/eip7594/src/lib.rs @@ -43,22 +43,13 @@ pub type KZGProof = [u8; BYTES_PER_COMMITMENT]; /// that we would like to make and verify opening proofs about. pub type KZGCommitment = [u8; BYTES_PER_COMMITMENT]; -/// CellIndex is reference to a Coset. +/// CellIndex is reference to the coset/set of points that were used to create that Cell, +/// on a particular polynomial, f(x). /// -/// We are able to use CellIndex instead of the coset because -/// the prover and verifier both know what the cosets are that -/// we will be making and verifying opening proofs for. -pub type CellIndex = u64; - -/// CommitmentIndex is a reference to a commitment. -/// -/// In order to make verification cheaper, the verifier will -/// deduplicate the list of commitments that they need to verify opening proofs for. -/// They will then refer to a commitment via its position in an array of deduplicated commitments -/// with the CommitmentIndex. -/// -/// Note: This is not exposed in the public API. -pub(crate) type CommitmentIndex = u64; +/// Note: Since the verifier and prover both know what cosets will be used +/// to evaluate the polynomials being used in opening proofs, the protocol +/// only requires an index to reference them. +pub type CellIndex = kzg_multi_open::CosetIndex; use constants::{BYTES_PER_BLOB, BYTES_PER_CELL, BYTES_PER_COMMITMENT}; use prover::ProverContext; From 1bcb75cdbbd73ee385cc49330b7dc96263b2b8c1 Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Thu, 15 Aug 2024 22:38:54 +0100 Subject: [PATCH 3/3] fix import --- eip7594/src/verifier.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/eip7594/src/verifier.rs b/eip7594/src/verifier.rs index 64d54e46..e755c411 100644 --- a/eip7594/src/verifier.rs +++ b/eip7594/src/verifier.rs @@ -200,10 +200,12 @@ impl DASContext { mod validation { use std::collections::HashSet; + use kzg_multi_open::CommitmentIndex; + use crate::{ constants::{BYTES_PER_CELL, CELLS_PER_EXT_BLOB, EXTENSION_FACTOR}, verifier::VerifierError, - Bytes48Ref, CellIndex, CellRef, CommitmentIndex, + Bytes48Ref, CellIndex, CellRef, }; /// Validation logic for `verify_cell_kzg_proof_batch`