Skip to main content

p3_fri/
proof.rs

1use alloc::vec::Vec;
2
3use p3_commit::Mmcs;
4use p3_field::Field;
5use serde::{Deserialize, Serialize};
6
7#[derive(Serialize, Deserialize, Clone)]
8#[serde(bound(
9    serialize = "Witness: Serialize, InputProof: Serialize",
10    deserialize = "Witness: Deserialize<'de>, InputProof: Deserialize<'de>"
11))]
12pub struct FriProof<F: Field, M: Mmcs<F>, Witness, InputProof> {
13    pub commit_phase_commits: Vec<M::Commitment>,
14    pub commit_pow_witnesses: Vec<Witness>,
15    pub query_proofs: Vec<QueryProof<F, M, InputProof>>,
16    pub final_poly: Vec<F>,
17    pub query_pow_witness: Witness,
18}
19
20#[derive(Serialize, Deserialize, Clone)]
21#[serde(bound(
22    serialize = "InputProof: Serialize",
23    deserialize = "InputProof: Deserialize<'de>",
24))]
25pub struct QueryProof<F: Field, M: Mmcs<F>, InputProof> {
26    pub input_proof: InputProof,
27    /// For each commit phase commitment, this contains openings of a commit phase codeword at the
28    /// queried location, along with an opening proof.
29    pub commit_phase_openings: Vec<CommitPhaseProofStep<F, M>>,
30}
31
32#[derive(Debug, Serialize, Deserialize, Clone)]
33#[serde(bound = "")]
34pub struct CommitPhaseProofStep<F: Field, M: Mmcs<F>> {
35    /// The log2 of the folding arity used for this step.
36    pub log_arity: u8,
37    /// The openings of the commit phase codeword at the sibling locations.
38    /// For arity k, this contains k-1 sibling values.
39    pub sibling_values: Vec<F>,
40
41    pub opening_proof: M::Proof,
42}
43
44impl<F: Field, M: Mmcs<F>> CommitPhaseProofStep<F, M> {
45    /// Convert `log_arity` to `usize` and enforce the protocol bounds.
46    ///
47    /// Returns `None` when `log_arity` is zero or exceeds `max_log_arity`.
48    #[inline]
49    pub(crate) fn checked_log_arity(&self, max_log_arity: usize) -> Option<usize> {
50        let log_arity = self.log_arity as usize;
51        (1..=max_log_arity)
52            .contains(&log_arity)
53            .then_some(log_arity)
54    }
55}