mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-08 08:43:06 +00:00
95 lines
3.1 KiB
Rust
95 lines
3.1 KiB
Rust
|
|
use serde::{Deserialize, Serialize};
|
||
|
|
|
||
|
|
use crate::field::extension_field::target::ExtensionTarget;
|
||
|
|
use crate::field::extension_field::Extendable;
|
||
|
|
use crate::field::field_types::Field;
|
||
|
|
use crate::gadgets::polynomial::PolynomialCoeffsExtTarget;
|
||
|
|
use crate::hash::hash_types::{HashOut, HashOutTarget};
|
||
|
|
use crate::hash::merkle_proofs::{MerkleProof, MerkleProofTarget};
|
||
|
|
use crate::iop::target::Target;
|
||
|
|
use crate::plonk::plonk_common::PolynomialsIndexBlinding;
|
||
|
|
use crate::polynomial::polynomial::PolynomialCoeffs;
|
||
|
|
|
||
|
|
/// Evaluations and Merkle proof produced by the prover in a FRI query step.
|
||
|
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||
|
|
#[serde(bound = "")]
|
||
|
|
pub struct FriQueryStep<F: Extendable<D>, const D: usize> {
|
||
|
|
pub evals: Vec<F::Extension>,
|
||
|
|
pub merkle_proof: MerkleProof<F>,
|
||
|
|
}
|
||
|
|
|
||
|
|
#[derive(Clone)]
|
||
|
|
pub struct FriQueryStepTarget<const D: usize> {
|
||
|
|
pub evals: Vec<ExtensionTarget<D>>,
|
||
|
|
pub merkle_proof: MerkleProofTarget,
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Evaluations and Merkle proofs of the original set of polynomials,
|
||
|
|
/// before they are combined into a composition polynomial.
|
||
|
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||
|
|
#[serde(bound = "")]
|
||
|
|
pub struct FriInitialTreeProof<F: Field> {
|
||
|
|
pub evals_proofs: Vec<(Vec<F>, MerkleProof<F>)>,
|
||
|
|
}
|
||
|
|
|
||
|
|
impl<F: Field> FriInitialTreeProof<F> {
|
||
|
|
pub(crate) fn unsalted_evals(
|
||
|
|
&self,
|
||
|
|
polynomials: PolynomialsIndexBlinding,
|
||
|
|
zero_knowledge: bool,
|
||
|
|
) -> &[F] {
|
||
|
|
let evals = &self.evals_proofs[polynomials.index].0;
|
||
|
|
&evals[..evals.len() - polynomials.salt_size(zero_knowledge)]
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
#[derive(Clone)]
|
||
|
|
pub struct FriInitialTreeProofTarget {
|
||
|
|
pub evals_proofs: Vec<(Vec<Target>, MerkleProofTarget)>,
|
||
|
|
}
|
||
|
|
|
||
|
|
impl FriInitialTreeProofTarget {
|
||
|
|
pub(crate) fn unsalted_evals(
|
||
|
|
&self,
|
||
|
|
polynomials: PolynomialsIndexBlinding,
|
||
|
|
zero_knowledge: bool,
|
||
|
|
) -> &[Target] {
|
||
|
|
let evals = &self.evals_proofs[polynomials.index].0;
|
||
|
|
&evals[..evals.len() - polynomials.salt_size(zero_knowledge)]
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Proof for a FRI query round.
|
||
|
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||
|
|
#[serde(bound = "")]
|
||
|
|
pub struct FriQueryRound<F: Extendable<D>, const D: usize> {
|
||
|
|
pub initial_trees_proof: FriInitialTreeProof<F>,
|
||
|
|
pub steps: Vec<FriQueryStep<F, D>>,
|
||
|
|
}
|
||
|
|
|
||
|
|
#[derive(Clone)]
|
||
|
|
pub struct FriQueryRoundTarget<const D: usize> {
|
||
|
|
pub initial_trees_proof: FriInitialTreeProofTarget,
|
||
|
|
pub steps: Vec<FriQueryStepTarget<D>>,
|
||
|
|
}
|
||
|
|
|
||
|
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||
|
|
#[serde(bound = "")]
|
||
|
|
pub struct FriProof<F: Extendable<D>, const D: usize> {
|
||
|
|
/// A Merkle root for each reduced polynomial in the commit phase.
|
||
|
|
pub commit_phase_merkle_roots: Vec<HashOut<F>>,
|
||
|
|
/// Query rounds proofs
|
||
|
|
pub query_round_proofs: Vec<FriQueryRound<F, D>>,
|
||
|
|
/// The final polynomial in coefficient form.
|
||
|
|
pub final_poly: PolynomialCoeffs<F::Extension>,
|
||
|
|
/// Witness showing that the prover did PoW.
|
||
|
|
pub pow_witness: F,
|
||
|
|
}
|
||
|
|
|
||
|
|
pub struct FriProofTarget<const D: usize> {
|
||
|
|
pub commit_phase_merkle_roots: Vec<HashOutTarget>,
|
||
|
|
pub query_round_proofs: Vec<FriQueryRoundTarget<D>>,
|
||
|
|
pub final_poly: PolynomialCoeffsExtTarget<D>,
|
||
|
|
pub pow_witness: Target,
|
||
|
|
}
|