franklin_crypto/plonk/circuit/
mod.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
pub mod allocated_num;
pub mod blake2s;
pub mod boolean;
pub mod custom_rescue_gate;
pub mod linear_combination;
pub mod multieq;
pub mod rescue;
pub mod sha256;
pub mod uint32;
//pub mod poseidon;
pub mod bigint;
pub mod bigint_new;
pub mod byte;
pub mod counter;
pub mod curve;
pub mod curve_new;
pub mod custom_5th_degree_gate_optimized;
pub mod edwards;
pub mod goldilocks;
pub mod permutation_network;
pub mod simple_term;
pub mod tables;
pub mod utils;
pub mod verifier_circuit;

pub mod assignment;
pub mod hashes_with_tables;

use num_bigint::BigUint;

use crate::bellman::pairing::Engine;
use crate::bellman::plonk::better_better_cs::cs::PlonkConstraintSystemParams;

pub use crate::bellman::plonk::better_better_cs::cs::PlonkCsWidth4WithNextStepAndCustomGatesParams as Width4WithCustomGates;

use crate::bellman::SynthesisError;

pub use self::assignment::*;
use crate::bellman::pairing::ff::{Field, PrimeField};

pub trait SomeArithmetizable {
    fn add(&self, other: &Self) -> Self;
    fn sub(&self, other: &Self) -> Self;
    fn mul(&self, other: &Self) -> Self;
    fn fma(&self, to_mul: &Self, to_add: &Self) -> Self;
    fn negate(&self) -> Self;
}

impl<F: Field> SomeArithmetizable for Option<F> {
    fn add(&self, other: &Self) -> Self {
        match (self, other) {
            (Some(s), Some(o)) => {
                let mut tmp = *s;
                tmp.add_assign(&o);

                Some(tmp)
            }
            _ => None,
        }
    }
    fn sub(&self, other: &Self) -> Self {
        match (self, other) {
            (Some(s), Some(o)) => {
                let mut tmp = *s;
                tmp.sub_assign(&o);

                Some(tmp)
            }
            _ => None,
        }
    }
    fn mul(&self, other: &Self) -> Self {
        match (self, other) {
            (Some(s), Some(o)) => {
                let mut tmp = *s;
                tmp.mul_assign(&o);

                Some(tmp)
            }
            _ => None,
        }
    }
    fn fma(&self, to_mul: &Self, to_add: &Self) -> Self {
        match (self, to_mul, to_add) {
            (Some(s), Some(m), Some(a)) => {
                let mut tmp = *s;
                tmp.mul_assign(&m);
                tmp.add_assign(&a);

                Some(tmp)
            }
            _ => None,
        }
    }
    fn negate(&self) -> Self {
        match self {
            Some(s) => {
                let mut tmp = *s;
                tmp.negate();

                Some(tmp)
            }
            _ => None,
        }
    }
}