binius_core/protocols/gkr_exp/
common.rs

1// Copyright 2025 Irreducible Inc.
2
3use binius_field::Field;
4
5use crate::protocols::sumcheck::prove::eq_ind::{EqIndSumcheckProver, EqIndSumcheckProverBuilder};
6
7/// LayerClaim is a claim about the evaluation of the kth layer-multilinear at a specific evaluation
8/// point
9///
10/// Notation:
11/// * The kth layer-multilinear is the multilinear polynomial whose evaluations are the intermediate
12///   values of the kth layer of the evaluated circuit.
13#[derive(Debug, Clone, Default)]
14pub struct LayerClaim<F: Field> {
15	pub eval_point: Vec<F>,
16	pub eval: F,
17}
18
19impl<F: Field> LayerClaim<F> {
20	pub fn isomorphic<FI>(self) -> LayerClaim<FI>
21	where
22		F: Into<FI>,
23		FI: Field,
24	{
25		let Self { eval_point, eval } = self;
26
27		LayerClaim {
28			eval_point: eval_point.into_iter().map(|x| x.into()).collect::<Vec<_>>(),
29			eval: eval.into(),
30		}
31	}
32}
33
34/// ExpClaim is a claim about the evaluation of the first layer-multilinear at a specific evaluation
35/// point.
36#[derive(Clone)]
37pub struct ExpClaim<F: Field> {
38	pub eval_point: Vec<F>,
39	pub eval: F,
40	/// The number of bits used to represent the integer.
41	pub exponent_bit_width: usize,
42	pub n_vars: usize,
43	/// - `true`: Indicates that the dynamic base is used
44	/// - `false`: Indicates that the static base is used.
45	pub static_base: Option<F>,
46}
47
48impl<F: Field> From<ExpClaim<F>> for LayerClaim<F> {
49	fn from(value: ExpClaim<F>) -> Self {
50		Self {
51			eval: value.eval,
52			eval_point: value.eval_point,
53		}
54	}
55}
56
57impl<F: Field> ExpClaim<F> {
58	pub fn isomorphic<FI: Field + From<F>>(self) -> ExpClaim<FI> {
59		let Self {
60			eval_point,
61			eval,
62			exponent_bit_width,
63			n_vars,
64			static_base,
65		} = self;
66
67		ExpClaim {
68			eval_point: eval_point.into_iter().map(|x| x.into()).collect::<Vec<_>>(),
69			eval: eval.into(),
70			exponent_bit_width,
71			n_vars,
72			static_base: static_base.map(|base| base.into()),
73		}
74	}
75}
76
77pub struct BaseExpReductionOutput<F: Field> {
78	/// Reduced evalcheck claims for every prover for each layer.
79	///
80	/// The first dimension of the vector represents each layer,
81	/// and the second dimension represents the LayerClaims.
82	///
83	/// Since [super::batch_prove] works with exponents of different widths and different types of
84	/// base, the length of each layer can vary.
85	pub layers_claims: Vec<Vec<LayerClaim<F>>>,
86}
87
88impl<F: Field> BaseExpReductionOutput<F> {
89	pub fn isomorphic<FI>(self) -> BaseExpReductionOutput<FI>
90	where
91		F: Into<FI>,
92		FI: Field,
93	{
94		let Self { layers_claims } = self;
95
96		BaseExpReductionOutput {
97			layers_claims: layers_claims
98				.into_iter()
99				.map(|claims| {
100					claims
101						.into_iter()
102						.map(|claim| claim.isomorphic())
103						.collect::<Vec<_>>()
104				})
105				.collect::<Vec<_>>(),
106		}
107	}
108}
109
110pub type GKRExpProverBuilder<'a, P, M, Backend> = EqIndSumcheckProverBuilder<'a, P, M, Backend>;
111
112pub type GKRExpProver<'a, FDomain, P, Composition, M, Backend> =
113	EqIndSumcheckProver<'a, FDomain, P, Composition, M, Backend>;