Groth16Setup

Struct Groth16Setup 

Source
pub struct Groth16Setup<E: Pairing> {
    pub proving_key: ProvingKey<E>,
    pub verifying_key: VerifyingKey<E>,
    pub prepared_verifying_key: PreparedVerifyingKey<E>,
}
Expand description

Contains all necessary parameters for the Groth16 proving system.

This structure holds the proving key, verifying key, and prepared verifying key needed for generating and verifying zero-knowledge proofs.

Fields§

§proving_key: ProvingKey<E>

The proving key used to generate proofs. This contains the secret parameters and should be kept private in some applications.

§verifying_key: VerifyingKey<E>

The verification key used to verify proofs. This can be made public and distributed to verifiers.

§prepared_verifying_key: PreparedVerifyingKey<E>

A preprocessed version of the verification key that allows for more efficient proof verification.

Implementations§

Source§

impl Groth16Setup<Bn254>

Source

pub fn new( num_constraints: usize, num_variables: usize, ) -> Result<Self, Groth16Error>

Creates a new Groth16 setup for a circuit with the specified parameters.

This function generates the proving and verification keys necessary for creating and verifying zero-knowledge proofs.

§Arguments
  • num_constraints - Number of constraints in the arithmetic circuit
  • num_variables - Number of variables used in the circuit
§Returns
  • Result<Self, Groth16Error> - The setup parameters or an error
§Example
let setup = Groth16Setup::new(3, 2)?;
Source

pub fn prove( &self, inputs: &[Fr], witness: &[Fr], ) -> Result<ArkProof<Bn254>, Groth16Error>

Generates a zero-knowledge proof using the provided inputs and witness.

§Arguments
  • inputs - Public inputs to the circuit
  • witness - Private witness values
§Returns
  • Result<ArkProof<Bn254>, Groth16Error> - The generated proof or an error
§Example
let proof = setup.prove(&inputs, &witness)?;
Source

pub fn verify( &self, proof: &ArkProof<Bn254>, public_inputs: &[Fr], ) -> Result<bool, Groth16Error>

Verifies a zero-knowledge proof against the provided public inputs.

§Arguments
  • proof - The proof to verify
  • public_inputs - Public inputs used in the proof
§Returns
  • Result<bool, Groth16Error> - Whether the proof is valid
§Example
let is_valid = setup.verify(&proof, &public_inputs)?;
assert!(is_valid);
Source

pub fn proof_to_evm_format( proof: &ArkProof<Bn254>, ) -> Result<Vec<u8>, Groth16Error>

Converts a proof to EVM-compatible format for on-chain verification.

§Arguments
  • proof - The proof to convert
§Returns
  • Result<Vec<u8>, Groth16Error> - The serialized proof bytes
Source

pub fn estimate_verification_gas(proof_size: usize, num_inputs: usize) -> u64

Estimates the gas cost for verifying a proof on Ethereum.

§Arguments
  • proof_size - Size of the proof in bytes
  • num_inputs - Number of public inputs
§Returns
  • u64 - Estimated gas cost in units

Trait Implementations§

Source§

impl<E: Debug + Pairing> Debug for Groth16Setup<E>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, 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

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more