core_utils/circuit/
constants.rs

1use enum_try_as_inner::EnumTryAsInner;
2use primitives::algebra::{
3    elliptic_curve::{BaseFieldElement, Point, Scalar},
4    field::Bit,
5};
6use serde::{Deserialize, Serialize};
7
8/// Enum representing a plaintext value. Can either be a fixed value provided with a circuit, or a
9/// public input provided at runtime. The usize is the size of the batch.
10#[derive(Debug, Copy, Clone, EnumTryAsInner, PartialEq, Eq, Serialize, Deserialize)]
11pub enum Plaintext<T> {
12    Fixed(T),
13    Input(usize),
14}
15
16pub type ScalarPlaintext<C> = Plaintext<Scalar<C>>;
17pub type BaseFieldPlaintext<C> = Plaintext<BaseFieldElement<C>>;
18pub type PointPlaintext<C> = Plaintext<Point<C>>;
19pub type BitPlaintext = Plaintext<Bit>;
20
21pub type ScalarPlaintextBatch<C> = Plaintext<Vec<Scalar<C>>>;
22pub type BaseFieldPlaintextBatch<C> = Plaintext<Vec<BaseFieldElement<C>>>;
23pub type PointPlaintextBatch<C> = Plaintext<Vec<Point<C>>>;
24pub type BitPlaintextBatch = Plaintext<Vec<Bit>>;
25
26impl<T> Plaintext<Vec<T>> {
27    /// Returns the size of the batch.
28    pub fn len(&self) -> usize {
29        match self {
30            Plaintext::Fixed(v) => v.len(),
31            Plaintext::Input(size) => *size,
32        }
33    }
34
35    pub fn is_empty(&self) -> bool {
36        self.len() == 0
37    }
38}