1use ark_ff::Field;
9use ark_std::boxed::Box;
10use core::fmt;
11use downcast_rs::{impl_downcast, Downcast};
12use dyn_clone::DynClone;
13
14use crate::constants::{GATE_WIDTH, N_MUL_SELECTORS};
15
16mod arithmetic;
17mod ecc;
18mod logic;
19mod lookup;
20
21pub use arithmetic::*;
22pub use ecc::*;
23pub use logic::*;
24pub use lookup::*;
25
26pub trait Gate<F: Field>: Downcast + DynClone {
28 fn name(&self) -> &'static str;
30 fn q_lc(&self) -> [F; GATE_WIDTH] {
32 [F::zero(); GATE_WIDTH]
33 }
34 fn q_hash(&self) -> [F; GATE_WIDTH] {
36 [F::zero(); GATE_WIDTH]
37 }
38 fn q_mul(&self) -> [F; N_MUL_SELECTORS] {
40 [F::zero(); N_MUL_SELECTORS]
41 }
42 fn q_ecc(&self) -> F {
44 F::zero()
45 }
46 fn q_c(&self) -> F {
48 F::zero()
49 }
50 fn q_o(&self) -> F {
52 F::zero()
53 }
54 fn q_lookup(&self) -> F {
56 F::zero()
57 }
58 fn q_dom_sep(&self) -> F {
60 F::zero()
61 }
62 fn table_key(&self) -> F {
64 F::zero()
65 }
66 fn table_dom_sep(&self) -> F {
68 F::zero()
69 }
70}
71impl_downcast!(Gate<F> where F: Field);
72
73impl<F: Field> Clone for Box<dyn Gate<F>> {
74 fn clone(&self) -> Box<dyn Gate<F>> {
75 dyn_clone::clone_box(&**self)
76 }
77}
78
79impl<F: Field> fmt::Debug for (dyn Gate<F> + 'static) {
80 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
81 f.write_str(self.name())
83 }
84}
85
86#[derive(Debug, Clone)]
88pub struct PaddingGate;
89
90impl<F> Gate<F> for PaddingGate
91where
92 F: Field,
93{
94 fn name(&self) -> &'static str {
95 "Padding Gate"
96 }
97}