binius_ip_prover/sumcheck/round_state.rs
1// Copyright 2026 The Binius Developers
2
3/// The value a sumcheck-style prover carries between two consecutive protocol phases.
4///
5/// A prover alternates between two phases, once per variable:
6/// - producing the round polynomial(s) for the variable being bound,
7/// - reducing them with the verifier challenge to the claim(s) for the next variable.
8///
9/// A prover holds exactly one of the two at any time.
10/// Tracking which one lets the mandated call order be validated in a single place.
11#[derive(Debug, Clone)]
12pub enum RoundState<Coeffs, Claim> {
13 /// Round polynomial(s) already produced for this variable, awaiting the reduction step.
14 Coeffs(Coeffs),
15 /// Claim(s) awaiting the next round polynomial(s): the initial claim, or a reduction result.
16 Claim(Claim),
17}
18
19impl<Coeffs, Claim> RoundState<Coeffs, Claim> {
20 /// Borrows the carried claim, needed to start producing this round's polynomial(s).
21 ///
22 /// # Panics
23 ///
24 /// Panics when the prover still holds an unreduced round polynomial.
25 /// That means execute was called before the previous round's fold.
26 pub fn claim(&self) -> &Claim {
27 match self {
28 // A carried claim is the expected input to the round-polynomial phase.
29 Self::Claim(claim) => claim,
30 // Holding coefficients means the reduction step is still owed.
31 Self::Coeffs(_) => panic!("execute called out of order; expected fold"),
32 }
33 }
34
35 /// Borrows this round's polynomial(s), needed to start the reduction step.
36 ///
37 /// # Panics
38 ///
39 /// Panics when the prover instead holds a claim.
40 /// That means fold was called before this round's execute produced a polynomial.
41 pub fn coeffs(&self) -> &Coeffs {
42 match self {
43 // The round polynomial is the expected input to the reduction phase.
44 Self::Coeffs(coeffs) => coeffs,
45 // Holding a claim means the round polynomial is still owed.
46 Self::Claim(_) => panic!("fold called out of order; expected execute"),
47 }
48 }
49}