frontend/components.rs
1//! Module for components that can be used to build a circuit.
2
3use shared_types::Field;
4
5use crate::layouter::builder::{CircuitBuilder, NodeRef};
6/// Components relating to digital range checking, decomposition and recomposition
7pub mod digits;
8
9// Defines components for use in building binary circuits.
10pub mod binary_operations;
11
12pub mod sha2_gkr;
13
14#[cfg(test)]
15mod tests;
16
17/// Components for building circuits
18pub struct Components;
19
20impl Components {
21 /// Check if the values of two ClaimableNodes are equal, by adding self.sector
22 /// to the circuit as an output layer.
23 pub fn equality_check<F: Field>(
24 builder_ref: &mut CircuitBuilder<F>,
25 lhs: &NodeRef<F>,
26 rhs: &NodeRef<F>,
27 ) -> NodeRef<F> {
28 builder_ref.add_sector(lhs - rhs)
29 }
30}
31
32/// Use this component to check if the values of two ClaimableNodes are equal, by adding self.sector
33/// to the circuit as an output layer.
34pub struct EqualityChecker<F: Field> {
35 /// To be added to the circuit as an output layer by the caller.
36 pub sector: NodeRef<F>,
37}
38
39impl<F: Field> EqualityChecker<F> {
40 /// Create a new EqualityChecker.
41 pub fn new(builder_ref: &mut CircuitBuilder<F>, lhs: &NodeRef<F>, rhs: &NodeRef<F>) -> Self {
42 let sector = builder_ref.add_sector(lhs.expr() - rhs.expr());
43 Self { sector }
44 }
45
46 /// Returns a weak pointer to the output sector of this component.
47 pub fn get_output(&self) -> NodeRef<F> {
48 self.sector.clone()
49 }
50}