2021-02-09 21:25:21 -08:00
|
|
|
use crate::field::field::Field;
|
2021-02-26 13:18:41 -08:00
|
|
|
use crate::target::Target;
|
2021-04-06 19:11:21 -07:00
|
|
|
use crate::gadgets::merkle_proofs::{MerkleProofTarget, MerkleProof};
|
2021-02-09 21:25:21 -08:00
|
|
|
|
2021-03-25 15:20:14 -07:00
|
|
|
/// Represents a ~256 bit hash output.
|
2021-03-31 21:15:24 -07:00
|
|
|
#[derive(Copy, Clone, Debug)]
|
2021-02-09 21:25:21 -08:00
|
|
|
pub struct Hash<F: Field> {
|
2021-03-25 15:20:14 -07:00
|
|
|
pub(crate) elements: [F; 4],
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<F: Field> Hash<F> {
|
|
|
|
|
pub(crate) fn from_partial(mut elements: Vec<F>) -> Self {
|
|
|
|
|
debug_assert!(elements.len() <= 4);
|
|
|
|
|
while elements.len() < 4 {
|
|
|
|
|
elements.push(F::ZERO);
|
|
|
|
|
}
|
|
|
|
|
Self { elements: [elements[0], elements[1], elements[2], elements[3]] }
|
|
|
|
|
}
|
2021-02-09 21:25:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct HashTarget {
|
2021-03-31 21:15:24 -07:00
|
|
|
pub(crate) elements: Vec<Target>,
|
2021-02-09 21:25:21 -08:00
|
|
|
}
|
|
|
|
|
|
2021-03-30 10:02:00 -07:00
|
|
|
pub struct Proof<F: Field> {
|
2021-02-09 21:25:21 -08:00
|
|
|
/// Merkle root of LDEs of wire values.
|
|
|
|
|
pub wires_root: Hash<F>,
|
|
|
|
|
/// Merkle root of LDEs of Z, in the context of Plonk's permutation argument.
|
2021-04-01 12:49:31 -07:00
|
|
|
pub plonk_zs_root: Hash<F>,
|
2021-02-09 21:25:21 -08:00
|
|
|
/// Merkle root of LDEs of the quotient polynomial components.
|
2021-04-01 12:49:31 -07:00
|
|
|
pub quotient_polys_root: Hash<F>,
|
2021-02-09 21:25:21 -08:00
|
|
|
|
|
|
|
|
/// Purported values of each polynomial at each challenge point.
|
|
|
|
|
pub openings: Vec<OpeningSet<F>>,
|
|
|
|
|
|
2021-04-06 19:11:21 -07:00
|
|
|
/// A FRI argument for each FRI query.
|
|
|
|
|
pub fri_proofs: Vec<FriProof<F>>,
|
2021-02-09 21:25:21 -08:00
|
|
|
}
|
|
|
|
|
|
2021-03-30 10:02:00 -07:00
|
|
|
pub struct ProofTarget {
|
2021-02-09 21:25:21 -08:00
|
|
|
/// 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.
|
2021-04-01 12:49:31 -07:00
|
|
|
pub plonk_zs_root: HashTarget,
|
2021-02-09 21:25:21 -08:00
|
|
|
/// Merkle root of LDEs of the quotient polynomial components.
|
2021-04-01 12:49:31 -07:00
|
|
|
pub quotient_polys_root: HashTarget,
|
2021-02-09 21:25:21 -08:00
|
|
|
|
|
|
|
|
/// Purported values of each polynomial at each challenge point.
|
|
|
|
|
pub openings: Vec<OpeningSetTarget>,
|
|
|
|
|
|
2021-02-26 13:18:41 -08:00
|
|
|
/// A FRI argument for each FRI query.
|
|
|
|
|
pub fri_proofs: Vec<FriProofTarget>,
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-06 19:11:21 -07:00
|
|
|
pub struct FriProof<F: Field> {
|
2021-04-07 09:10:06 -07:00
|
|
|
/// A Merkle root for each reduced polynomial in the commit phase.
|
|
|
|
|
pub commit_phase_merkle_roots: Vec<Hash<F>>,
|
2021-04-06 19:11:21 -07:00
|
|
|
/// Merkle proofs for the original purported codewords, i.e. the subject of the LDT.
|
|
|
|
|
pub initial_merkle_proofs: Vec<MerkleProof<F>>,
|
|
|
|
|
/// Merkle proofs for the reduced polynomials that were sent in the commit phase.
|
|
|
|
|
pub intermediate_merkle_proofs: Vec<MerkleProof<F>>,
|
|
|
|
|
/// The final polynomial in coefficient form.
|
|
|
|
|
pub final_poly: Vec<F>,
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-26 13:18:41 -08:00
|
|
|
/// Represents a single FRI query, i.e. a path through the reduction tree.
|
|
|
|
|
pub struct FriProofTarget {
|
2021-04-07 09:10:06 -07:00
|
|
|
/// A Merkle root for each reduced polynomial in the commit phase.
|
|
|
|
|
pub commit_phase_merkle_roots: Vec<HashTarget>,
|
2021-02-26 13:18:41 -08:00
|
|
|
/// Merkle proofs for the original purported codewords, i.e. the subject of the LDT.
|
|
|
|
|
pub initial_merkle_proofs: Vec<MerkleProofTarget>,
|
|
|
|
|
/// Merkle proofs for the reduced polynomials that were sent in the commit phase.
|
|
|
|
|
pub intermediate_merkle_proofs: Vec<MerkleProofTarget>,
|
2021-04-06 19:11:21 -07:00
|
|
|
/// The final polynomial in coefficient form.
|
2021-02-26 13:18:41 -08:00
|
|
|
pub final_poly: Vec<Target>,
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-09 21:25:21 -08:00
|
|
|
/// The purported values of each polynomial at a single point.
|
|
|
|
|
pub struct OpeningSet<F: Field> {
|
|
|
|
|
pub constants: Vec<F>,
|
|
|
|
|
pub plonk_sigmas: Vec<F>,
|
|
|
|
|
pub wires: Vec<F>,
|
2021-04-01 12:49:31 -07:00
|
|
|
pub plonk_zs: Vec<F>,
|
|
|
|
|
pub quotient_polys: Vec<F>,
|
2021-02-09 21:25:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// The purported values of each polynomial at a single point.
|
|
|
|
|
pub struct OpeningSetTarget {
|
2021-02-26 13:18:41 -08:00
|
|
|
pub constants: Vec<Target>,
|
|
|
|
|
pub plonk_sigmas: Vec<Target>,
|
|
|
|
|
pub wires: Vec<Target>,
|
2021-04-01 12:49:31 -07:00
|
|
|
pub plonk_zs: Vec<Target>,
|
|
|
|
|
pub quotient_polys: Vec<Target>,
|
2021-02-09 21:25:21 -08:00
|
|
|
}
|