-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathmy_circuit.rs
99 lines (82 loc) · 2.87 KB
/
my_circuit.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
use std::{array, num::NonZeroUsize};
use sirius::{
ivc::{
step_circuit::{trivial, AssignedCell, ConstraintSystem, Layouter},
SynthesisError,
},
sangria_prelude::{
bn256::{new_default_pp, C1Affine, C1Scalar, C2Affine, C2Scalar},
CommitmentKey, PrimeField, SangriaIVC, StepCircuit,
},
};
/// Number of folding steps
const FOLD_STEP_COUNT: usize = 5;
/// Arity : Input/output size per fold-step for primary step-circuit
const A1: usize = 5;
/// Arity : Input/output size per fold-step for secondary step-circuit
/// For tivial case it can be any number
const A2: usize = 1;
/// Table size for Primary Circuit
///
/// Requires at least 17, for service purposes, but if the primary requires more, increase the
/// constant
const SECONDARY_CIRCUIT_TABLE_SIZE: usize = 17;
/// Key size for Primary Circuit
const PRIMARY_COMMITMENT_KEY_SIZE: usize = 21;
/// Table size for Primary Circuit
///
/// Requires at least 17, for service purposes, but if the primary requires more, increase the
/// constant
const PRIMARY_CIRCUIT_TABLE_SIZE: usize = 17;
/// Key size for Primary Circuit
const SECONDARY_COMMITMENT_KEY_SIZE: usize = 21;
#[derive(Debug, Clone)]
struct MyConfig {}
struct MyStepCircuit {}
impl<const A: usize, F: PrimeField> StepCircuit<A, F> for MyStepCircuit {
/// This is a configuration object that stores things like columns.
type Config = MyConfig;
/// Configure the step circuit. This method initializes necessary
/// fixed columns and advice columns
fn configure(_cs: &mut ConstraintSystem<F>) -> Self::Config {
todo!()
}
/// Sythesize the circuit for a computation step and return variable
/// that corresponds to the output of the step z_{i+1}
/// this method will be called when we synthesize the IVC_Circuit
///
/// Return `z_out` result
fn synthesize_step(
&self,
_config: Self::Config,
_layouter: &mut impl Layouter<F>,
_z_i: &[AssignedCell<F, F>; A],
) -> Result<[AssignedCell<F, F>; A], SynthesisError> {
todo!()
}
}
fn main() {
let sc1 = MyStepCircuit {};
let sc2 = trivial::Circuit::<A2, C2Scalar>::default();
let primary_commitment_key =
CommitmentKey::<C1Affine>::setup(PRIMARY_COMMITMENT_KEY_SIZE, b"bn256");
let secondary_commitment_key =
CommitmentKey::<C2Affine>::setup(SECONDARY_COMMITMENT_KEY_SIZE, b"grumpkin");
let pp = new_default_pp::<A1, _, A2, _>(
SECONDARY_CIRCUIT_TABLE_SIZE as u32,
&primary_commitment_key,
&sc1,
PRIMARY_CIRCUIT_TABLE_SIZE as u32,
&secondary_commitment_key,
&sc2,
);
SangriaIVC::fold_with_debug_mode(
&pp,
&sc1,
array::from_fn(|i| C1Scalar::from(i as u64)),
&sc2,
array::from_fn(|i| C2Scalar::from(i as u64)),
NonZeroUsize::new(FOLD_STEP_COUNT).unwrap(),
)
.unwrap();
}