use crate::field::extension_field::Extendable; use crate::field::field::Field; use crate::merkle_proofs::{MerkleProof, MerkleProofTarget}; use crate::polynomial::commitment::{ListPolynomialCommitment, OpeningProof, EXTENSION_DEGREE}; use crate::polynomial::polynomial::PolynomialCoeffs; use crate::target::Target; use std::convert::TryInto; /// Represents a ~256 bit hash output. #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub struct Hash { pub(crate) elements: [F; 4], } impl Hash { pub(crate) fn from_vec(elements: Vec) -> Self { debug_assert!(elements.len() == 4); Self { elements: elements.try_into().unwrap(), } } pub(crate) fn from_partial(mut elements: Vec) -> Self { debug_assert!(elements.len() <= 4); while elements.len() < 4 { elements.push(F::ZERO); } Self { elements: [elements[0], elements[1], elements[2], elements[3]], } } } /// Represents a ~256 bit hash output. pub struct HashTarget { pub(crate) elements: [Target; 4], } impl HashTarget { pub(crate) fn from_vec(elements: Vec) -> Self { debug_assert!(elements.len() == 4); Self { elements: elements.try_into().unwrap(), } } pub(crate) fn from_partial(mut elements: Vec, zero: Target) -> Self { debug_assert!(elements.len() <= 4); while elements.len() < 4 { elements.push(zero); } Self { elements: [elements[0], elements[1], elements[2], elements[3]], } } } pub struct Proof> { /// Merkle root of LDEs of wire values. pub wires_root: Hash, /// Merkle root of LDEs of Z, in the context of Plonk's permutation argument. pub plonk_zs_root: Hash, /// Merkle root of LDEs of the quotient polynomial components. pub quotient_polys_root: Hash, /// Purported values of each polynomial at each challenge point. pub openings: Vec>, /// A FRI argument for each FRI query. pub opening_proof: OpeningProof, } pub struct ProofTarget { /// Merkle root of LDEs of wire values. pub wires_root: HashTarget, /// Merkle root of LDEs of Z, in the context of Plonk's permutation argument. pub plonk_zs_root: HashTarget, /// Merkle root of LDEs of the quotient polynomial components. pub quotient_polys_root: HashTarget, /// Purported values of each polynomial at each challenge point. pub openings: Vec, /// A FRI argument for each FRI query. pub fri_proofs: Vec, } /// Evaluations and Merkle proof produced by the prover in a FRI query step. // TODO: Implement FriQueryStepTarget pub struct FriQueryStep> { pub evals: Vec, pub merkle_proof: MerkleProof, } /// Evaluations and Merkle proofs of the original set of polynomials, /// before they are combined into a composition polynomial. // TODO: Implement FriInitialTreeProofTarget pub struct FriInitialTreeProof { pub evals_proofs: Vec<(Vec, MerkleProof)>, } /// Proof for a FRI query round. // TODO: Implement FriQueryRoundTarget pub struct FriQueryRound> { pub initial_trees_proof: FriInitialTreeProof, pub steps: Vec>, } pub struct FriProof> { /// A Merkle root for each reduced polynomial in the commit phase. pub commit_phase_merkle_roots: Vec>, /// Query rounds proofs pub query_round_proofs: Vec>, /// The final polynomial in coefficient form. pub final_poly: PolynomialCoeffs, /// Witness showing that the prover did PoW. pub pow_witness: F, } /// Represents a single FRI query, i.e. a path through the reduction tree. pub struct FriProofTarget { /// A Merkle root for each reduced polynomial in the commit phase. pub commit_phase_merkle_roots: Vec, /// Merkle proofs for the original purported codewords, i.e. the subject of the LDT. pub initial_merkle_proofs: Vec, /// Merkle proofs for the reduced polynomials that were sent in the commit phase. pub intermediate_merkle_proofs: Vec, /// The final polynomial in coefficient form. pub final_poly: Vec, } /// The purported values of each polynomial at a single point. pub struct OpeningSet { pub constants: Vec, pub plonk_sigmas: Vec, pub wires: Vec, pub plonk_zs: Vec, pub quotient_polys: Vec, } impl OpeningSet { pub fn new( z: F, constant_commitment: &ListPolynomialCommitment, plonk_sigmas_commitment: &ListPolynomialCommitment, wires_commitment: &ListPolynomialCommitment, plonk_zs_commitment: &ListPolynomialCommitment, quotient_polys_commitment: &ListPolynomialCommitment, ) -> Self { let eval_commitment = |z: F, c: &ListPolynomialCommitment| { c.polynomials.iter().map(|p| p.eval(z)).collect::>() }; Self { constants: eval_commitment(z, constant_commitment), plonk_sigmas: eval_commitment(z, plonk_sigmas_commitment), wires: eval_commitment(z, wires_commitment), plonk_zs: eval_commitment(z, plonk_zs_commitment), quotient_polys: eval_commitment(z, quotient_polys_commitment), } } } /// The purported values of each polynomial at a single point. pub struct OpeningSetTarget { pub constants: Vec, pub plonk_sigmas: Vec, pub wires: Vec, pub plonk_zs: Vec, pub quotient_polys: Vec, }