1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright 2024 Ulvetanna Inc.

use crate::Error;
use binius_field::{Field, PackedField};
use binius_math::EvaluationDomain;
use tracing::instrument;

/// Describes the shape of the zerocheck computation.
#[derive(Clone, Debug)]
pub struct ZerocheckRoundParameters {
	pub round: usize,
	pub n_vars: usize,
	pub cols: usize,
	pub degree: usize,
	pub small_field_width: Option<usize>,
}

/// Represents input data of the computation round.
#[derive(Clone, Debug)]
pub struct ZerocheckRoundInput<'a, F, PW, FDomain>
where
	F: Field,
	PW: PackedField,
	PW::Scalar: From<F> + Into<F>,
	FDomain: Field,
{
	pub zc_challenges: &'a [F],
	pub eq_ind: &'a [PW],
	pub query: Option<&'a [PW]>,
	pub current_round_sum: F,
	pub mixing_challenge: F,
	pub domain: &'a EvaluationDomain<FDomain>,
	pub underlier_data: Option<Vec<Option<Vec<u8>>>>,
}

/// A callback interface to handle the zerocheck computation on the CPU.
pub trait ZerocheckCpuBackendHelper<F, PW, FDomain>
where
	F: Field,
	PW: PackedField,
	PW::Scalar: From<F> + Into<F>,
	FDomain: Field,
{
	/// Perform the zerocheck evaluation for this round,
	/// and convert them to coefficients.
	fn handle_zerocheck_round(
		&mut self,
		params: &ZerocheckRoundParameters,
		input: &ZerocheckRoundInput<F, PW, FDomain>,
	) -> Result<Vec<PW::Scalar>, Error>;

	/// Drop `smaller_domain_optimization`.
	#[instrument(skip_all)]
	fn remove_smaller_domain_optimization(&mut self);
}