haloumi_core/
info_traits.rs

1//! Adaptor traits that clients need to implement in order to integrate with the frontend.
2
3use ff::Field;
4
5use crate::{
6    expressions::{EvaluableExpr, ExprBuilder, ExpressionInfo},
7    lookups::LookupData,
8    query::QueryKind,
9    table::{Cell, Rotation},
10};
11
12/// Trait for querying information about the constraint system derived during configuration.
13pub trait ConstraintSystemInfo<F: Field> {
14    /// Type for polynomial expressions.
15    type Polynomial: EvaluableExpr<F> + Clone + ExpressionInfo + ExprBuilder<F>;
16
17    /// Notifies the constraint system that the circuit has completed synthesis.
18    fn synthesis_completed(&mut self) {}
19
20    /// Returns the list of gates defined in the system.
21    fn gates(&self) -> Vec<&dyn GateInfo<Self::Polynomial>>;
22
23    /// Returns a list with data about the lookups defined in the system.
24    fn lookups<'cs>(&'cs self) -> Vec<LookupData<'cs, Self::Polynomial>>;
25}
26
27/// Trait for querying information about the a gate in the constraint system.
28pub trait GateInfo<P> {
29    /// Returns the name of the gate.
30    fn name(&self) -> &str;
31
32    /// Returns the list of polynomials that make up the gate.
33    fn polynomials(&self) -> &[P];
34}
35
36/// Trait for retrieving information about cell queries.
37pub trait QueryInfo {
38    /// The kind of query this implementation provides information about.
39    type Kind: QueryKind;
40
41    /// Returns the rotation offset.
42    fn rotation(&self) -> Rotation;
43
44    /// Returns the index of the column the queried cell belongs to.
45    fn column_index(&self) -> usize;
46}
47
48/// Trait for constructing queries as expressions.
49pub trait CreateQuery<E> {
50    /// Constructs an expression representing the query.
51    fn query_expr(index: usize, at: Rotation) -> E;
52}
53
54/// Trait for retrieving information about a selector.
55pub trait SelectorInfo {
56    /// Returns the identifier of the selector.
57    fn id(&self) -> usize;
58}
59
60/// Trait for retrieving information about a challenge.
61pub trait ChallengeInfo {
62    /// Returns the index of the challenge.
63    fn index(&self) -> usize;
64
65    /// Returns the phase number of the challenge.
66    fn phase(&self) -> u8;
67}
68
69/// Trait for retrieving information about group annotations.
70pub trait GroupInfo {
71    /// Returns the inputs of the group.
72    fn inputs(&self) -> impl Iterator<Item = Cell> + '_;
73
74    /// Returns the outputs of the group.
75    fn outputs(&self) -> impl Iterator<Item = Cell> + '_;
76}