mdnt_support/circuit.rs
1//! Traits for working at the circuit level.
2
3use crate::circuit::configuration::AutoConfigure;
4
5pub mod configuration;
6pub mod injected;
7
8/// Trait for configuring the arguments of a chip.
9///
10/// If the chip has no arguments the type should be `()`. In that case the type
11/// can implement [`NoChipArgs`] which will automatically implement this trait
12/// with that type.
13pub trait ChipArgs {
14 /// Type of the arguments taken by the chip.
15 type Args: Default;
16
17 /// Returns an instance of the arguments.
18 fn chip_args(&self) -> Self::Args {
19 Default::default()
20 }
21}
22
23/// Trait for configuring [`ChipArgs`] for types that don't have arguments.
24///
25/// Sets the type of the arguments to `()`.
26pub trait NoChipArgs {}
27
28impl<T> ChipArgs for T
29where
30 T: NoChipArgs,
31{
32 type Args = ();
33}
34
35/// Adaptor trait for integrating chips with the extractor.
36pub trait CircuitInitialization<L> {
37 /// Configuration of the circuit.
38 type Config: Clone + std::fmt::Debug;
39 /// Arguments required by the circuit.
40 type Args: Default;
41 /// Configuration columns of the circuit.
42 type ConfigCols: Clone + std::fmt::Debug + AutoConfigure<Self::CS>;
43 /// Constrait system.
44 type CS;
45 /// Error type.
46 type Error;
47
48 /// Creates a new instance of the chip.
49 fn new_chip(config: &Self::Config, args: Self::Args) -> Self;
50
51 /// Creates an instance of the chip's configuration.
52 fn configure_circuit(meta: &mut Self::CS, columns: &Self::ConfigCols) -> Self::Config;
53
54 /// Loads internal information of the chip.
55 fn load_chip(&self, layouter: &mut L, config: &Self::Config) -> Result<(), Self::Error>;
56}