Skip to main content

sonobe_primitives/algebra/
mod.rs

1//! This module provides algebraic abstractions used across Sonobe, including
2//! field and group type enhancements, in-circuit (both canonical and emulated)
3//! variables, and common algebraic operations.
4
5use ark_ff::PrimeField;
6use ark_r1cs_std::{GR1CSVar, alloc::AllocVar};
7
8use crate::traits::SonobeField;
9
10pub mod field;
11pub mod group;
12pub mod ops;
13
14/// [`Val`] associates a type with its in-circuit variables.
15pub trait Val {
16    /// [`Val::PreferredConstraintField`] is the preferred constraint field for
17    /// expressing `Self` in-circuit.
18    type PreferredConstraintField: PrimeField;
19
20    /// [`Val::Var`] is the *canonical* in-circuit variable.
21    ///
22    /// In this case, the circuit is defined over the preferred constraint field
23    /// and can represent `Self` directly (i.e., without emulation).
24    type Var: AllocVar<Self, Self::PreferredConstraintField>
25        + GR1CSVar<Self::PreferredConstraintField, Value = Self>;
26
27    /// [`Val::EmulatedVar`] is the *emulated* in-circuit variable.
28    ///
29    /// In this case, the circuit is defined over an arbitrary field `F` which
30    /// may differ from the preferred constraint field, and `Self` is
31    /// represented in-circuit via emulation.
32    type EmulatedVar<F: SonobeField>: AllocVar<Self, F> + GR1CSVar<F, Value = Self>;
33}