Struct KZG

Source
pub struct KZG { /* private fields */ }
Expand description

Main interesting struct of the rust-kzg-bn254 crate. [Kzg] is a struct that holds the SRS points in monomial form, and provides methods for committing to a blob, (either via a Blob itself, or a PolynomialCoeffForm or PolynomialEvalForm), and generating and verifying proofs.

The Blob and PolynomialCoeffForm/PolynomialEvalForm structs are mostly https://en.wikipedia.org/wiki/Passive_data_structure with constructor and few helper methods.

Implementations§

Source§

impl KZG

Source

pub fn new() -> Self

Source

pub fn calculate_and_store_roots_of_unity( &mut self, length_of_data_after_padding: u64, ) -> Result<(), KzgError>

Calculates the roots of unities and assigns it to the struct

§Arguments
  • length_of_data_after_padding - Length of the blob data after padding in bytes.
§Returns
  • Result<(), KzgError>
§Details
  • Generates roots of unity needed for FFT operations
§Example
use rust_kzg_bn254_prover::kzg::KZG;
use rust_kzg_bn254_primitives::blob::Blob;
use ark_std::One;
use ark_bn254::Fr;

let mut kzg = KZG::new();
let input_blob = Blob::from_raw_data(b"test blob data");
kzg.calculate_and_store_roots_of_unity(input_blob.len().try_into().unwrap()).unwrap();
Source

pub fn get_roots_of_unities(&self) -> Vec<Fr>

Source

pub fn get_nth_root_of_unity(&self, i: usize) -> Option<&Fr>

helper function to get the

Source

pub fn commit_eval_form( &self, polynomial: &PolynomialEvalForm, srs: &SRS, ) -> Result<G1Affine, KzgError>

Commit the polynomial with the srs values loaded into [Kzg].

Source

pub fn commit_coeff_form( &self, polynomial: &PolynomialCoeffForm, srs: &SRS, ) -> Result<G1Affine, KzgError>

Commit the polynomial with the srs values loaded into [Kzg].

Source

pub fn commit_blob(&self, blob: &Blob, srs: &SRS) -> Result<G1Affine, KzgError>

commit to a Blob, by transforming it into a PolynomialEvalForm and then calling [Kzg::commit_eval_form].

Source

pub fn compute_proof_with_known_z_fr_index( &self, polynomial: &PolynomialEvalForm, index: u64, srs: &SRS, ) -> Result<G1Affine, KzgError>

Source

pub fn compute_proof( &self, polynomial: &PolynomialEvalForm, z_fr: &Fr, srs: &SRS, ) -> Result<G1Affine, KzgError>

Compute a kzg proof from a polynomial in evaluation form. We don’t currently support proofs for polynomials in coefficient form, but one can take the FFT of the polynomial in coefficient form to get the polynomial in evaluation form. This is available via the method PolynomialCoeffForm::to_eval_form. TODO(anupsv): Accept bytes instead of Fr element. Ref: https://github.com/Layr-Labs/rust-kzg-bn254/issues/29

Source

pub fn compute_quotient_eval_on_domain( &self, z_fr: &Fr, eval_fr: &[Fr], value_fr: &Fr, ) -> Fr

refer to DA for more context

Source

pub fn g1_ifft( &self, length: usize, srs: &SRS, ) -> Result<Vec<G1Affine>, KzgError>

function to compute the inverse FFT

Source

pub fn compute_blob_proof( &self, blob: &Blob, commitment: &G1Affine, srs: &SRS, ) -> Result<G1Affine, KzgError>

TODO(anupsv): Match 4844 specs w.r.t to the inputs. Ref: https://github.com/Layr-Labs/rust-kzg-bn254/issues/30

Trait Implementations§

Source§

impl Clone for KZG

Source§

fn clone(&self) -> KZG

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for KZG

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for KZG

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for KZG

Source§

fn eq(&self, other: &KZG) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for KZG

Auto Trait Implementations§

§

impl Freeze for KZG

§

impl RefUnwindSafe for KZG

§

impl Send for KZG

§

impl Sync for KZG

§

impl Unpin for KZG

§

impl UnwindSafe for KZG

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V