jf_relation/gates/
logic.rs

1// Copyright (c) 2022 Espresso Systems (espressosys.com)
2// This file is part of the Jellyfish library.
3
4// You should have received a copy of the MIT License
5// along with the Jellyfish library. If not, see <https://mit-license.org/>.
6
7//! Implementation of logic gates
8
9use super::Gate;
10use crate::constants::{GATE_WIDTH, N_MUL_SELECTORS};
11use ark_ff::Field;
12
13/// A gate for logic OR
14#[derive(Clone)]
15pub struct LogicOrGate;
16
17impl<F> Gate<F> for LogicOrGate
18where
19    F: Field,
20{
21    fn name(&self) -> &'static str {
22        "Logic OR Gate"
23    }
24    fn q_lc(&self) -> [F; GATE_WIDTH] {
25        [F::one(), F::one(), F::zero(), F::zero()]
26    }
27    fn q_mul(&self) -> [F; N_MUL_SELECTORS] {
28        [-F::one(), F::zero()]
29    }
30    fn q_c(&self) -> F {
31        -F::one()
32    }
33}
34
35/// A gate for computing the logic OR value of 2 variables
36#[derive(Clone)]
37pub struct LogicOrOutputGate;
38
39impl<F> Gate<F> for LogicOrOutputGate
40where
41    F: Field,
42{
43    fn name(&self) -> &'static str {
44        "Logic OR Value Gate"
45    }
46    fn q_lc(&self) -> [F; GATE_WIDTH] {
47        [F::one(), F::one(), F::zero(), F::zero()]
48    }
49    fn q_mul(&self) -> [F; N_MUL_SELECTORS] {
50        [-F::one(), F::zero()]
51    }
52    fn q_o(&self) -> F {
53        F::one()
54    }
55}