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