Skip to main content

Module iota::groth16

Module Functions

pub bls12381

Return the Curve value indicating that the BLS12-381 construction should be used in a given function.

public fun bls12381(): iota::groth16::Curve

Implementation

public fun bls12381(): Curve { Curve { id: 0 } }

pub bn254

Return the Curve value indicating that the BN254 construction should be used in a given function.

public fun bn254(): iota::groth16::Curve

Implementation

public fun bn254(): Curve { Curve { id: 1 } }

pub proof_points_from_bytes

Creates a Groth16 ProofPoints from bytes.

public fun proof_points_from_bytes(bytes: vector<u8>): iota::groth16::ProofPoints

Implementation

public fun proof_points_from_bytes(bytes: vector<u8>): ProofPoints {     ProofPoints { bytes } }

pub public_proof_inputs_from_bytes

Creates a PublicProofInputs wrapper from bytes. The bytes parameter should be a concatenation of a number of 32 bytes scalar field elements to be used as public inputs in little-endian format to a circuit.

public fun public_proof_inputs_from_bytes(bytes: vector<u8>): iota::groth16::PublicProofInputs

Implementation

public fun public_proof_inputs_from_bytes(bytes: vector<u8>): PublicProofInputs {     assert!(bytes.length() % 32 == 0, EInvalidScalar);     assert!(bytes.length() / 32 <= MaxPublicInputs, ETooManyPublicInputs);     PublicProofInputs { bytes } }

pub pvk_from_bytes

Creates a PreparedVerifyingKey from bytes.

public fun pvk_from_bytes(vk_gamma_abc_g1_bytes: vector<u8>, alpha_g1_beta_g2_bytes: vector<u8>, gamma_g2_neg_pc_bytes: vector<u8>, delta_g2_neg_pc_bytes: vector<u8>): iota::groth16::PreparedVerifyingKey

Implementation

public fun pvk_from_bytes(     vk_gamma_abc_g1_bytes: vector<u8>,     alpha_g1_beta_g2_bytes: vector<u8>,     gamma_g2_neg_pc_bytes: vector<u8>,     delta_g2_neg_pc_bytes: vector<u8>, ): PreparedVerifyingKey {     PreparedVerifyingKey {         vk_gamma_abc_g1_bytes,         alpha_g1_beta_g2_bytes,         gamma_g2_neg_pc_bytes,         delta_g2_neg_pc_bytes,     } }

prv prepare_verifying_key_internal

Native functions that flattens the inputs into an array and passes to the Rust native function. May abort with EInvalidVerifyingKey or EInvalidCurve.

fun prepare_verifying_key_internal(curve: u8, verifying_key: &vector): iota::groth16::PreparedVerifyingKey

Implementation

native fun prepare_verifying_key_internal(     curve: u8,     verifying_key: &vector, ): PreparedVerifyingKey;

prv verify_groth16_proof_internal

Native functions that flattens the inputs into arrays of vectors and passed to the Rust native function. May abort with EInvalidCurve or ETooManyPublicInputs.

fun verify_groth16_proof_internal(curve: u8, vk_gamma_abc_g1_bytes: &vector, alpha_g1_beta_g2_bytes: &vector, gamma_g2_neg_pc_bytes: &vector, delta_g2_neg_pc_bytes: &vector, public_proof_inputs: &vector, proof_points: &vector): bool

Implementation

native fun verify_groth16_proof_internal(     curve: u8,     vk_gamma_abc_g1_bytes: &vector,     alpha_g1_beta_g2_bytes: &vector,     gamma_g2_neg_pc_bytes: &vector,     delta_g2_neg_pc_bytes: &vector,     public_proof_inputs: &vector,     proof_points: &vector, ): bool;

Structs

struct Curve

Represents an elliptic curve construction to be used in the verifier. Currently we support BLS12-381 and BN254. This should be given as the first parameter to prepare_verifying_key or verify_groth16_proof.

public struct Curve has copy, drop, store

Fields
id: u8

pub prepare_verifying_key

@param curve: What elliptic curve construction to use. See bls12381 and bn254. @param verifying_key: An Arkworks canonical compressed serialization of a verifying key.

Returns four vectors of bytes representing the four components of a prepared verifying key. This step computes one pairing e(P, Q), and binds the verification to one particular proof statement. This can be used as inputs for the verify_groth16_proof function.

public fun prepare_verifying_key(curve: &iota::groth16::Curve, verifying_key: &vector): iota::groth16::PreparedVerifyingKey

Implementation

public fun prepare_verifying_key(curve: &Curve, verifying_key: &vector): PreparedVerifyingKey {     prepare_verifying_key_internal(curve.id, verifying_key) }

pub verify_groth16_proof

@param curve: What elliptic curve construction to use. See the bls12381 and bn254 functions. @param prepared_verifying_key: Consists of four vectors of bytes representing the four components of a prepared verifying key. @param public_proof_inputs: Represent inputs that are public. @param proof_points: Represent three proof points.

Returns a boolean indicating whether the proof is valid.

public fun verify_groth16_proof(curve: &iota::groth16::Curve, prepared_verifying_key: &iota::groth16::PreparedVerifyingKey, public_proof_inputs: &iota::groth16::PublicProofInputs, proof_points: &iota::groth16::ProofPoints): bool

Implementation

public fun verify_groth16_proof(     curve: &Curve,     prepared_verifying_key: &PreparedVerifyingKey,     public_proof_inputs: &PublicProofInputs,     proof_points: &ProofPoints, ): bool {     verify_groth16_proof_internal(         curve.id,         &prepared_verifying_key.vk_gamma_abc_g1_bytes,         &prepared_verifying_key.alpha_g1_beta_g2_bytes,         &prepared_verifying_key.gamma_g2_neg_pc_bytes,         &prepared_verifying_key.delta_g2_neg_pc_bytes,         &public_proof_inputs.bytes,         &proof_points.bytes,     ) }

struct PreparedVerifyingKey

A PreparedVerifyingKey consisting of four components in serialized form.

public struct PreparedVerifyingKey has copy, drop, store

Fields
vk_gamma_abc_g1_bytes: vector<u8>
alpha_g1_beta_g2_bytes: vector<u8>
gamma_g2_neg_pc_bytes: vector<u8>
delta_g2_neg_pc_bytes: vector<u8>

pub pvk_to_bytes

Returns bytes of the four components of the PreparedVerifyingKey.

public fun pvk_to_bytes(pvk: iota::groth16::PreparedVerifyingKey): vector<vector<u8>>

Implementation

public fun pvk_to_bytes(pvk: PreparedVerifyingKey): vector<vector<u8>> {     vector[         pvk.vk_gamma_abc_g1_bytes,         pvk.alpha_g1_beta_g2_bytes,         pvk.gamma_g2_neg_pc_bytes,         pvk.delta_g2_neg_pc_bytes,     ] }

struct PublicProofInputs

A PublicProofInputs wrapper around its serialized bytes.

public struct PublicProofInputs has copy, drop, store

Fields
bytes: vector<u8>

struct ProofPoints

A ProofPoints wrapper around the serialized form of three proof points.

public struct ProofPoints has copy, drop, store

Fields
bytes: vector<u8>

Constants

err EInvalidVerifyingKey

const EInvalidVerifyingKey: u64 = 0;

err EInvalidCurve

const EInvalidCurve: u64 = 1;

err ETooManyPublicInputs

const ETooManyPublicInputs: u64 = 2;

err EInvalidScalar

const EInvalidScalar: u64 = 3;

const MaxPublicInputs

const MaxPublicInputs: u64 = 8;