-
Notifications
You must be signed in to change notification settings - Fork 141
Expand file tree
/
Copy pathcircuit.rs
More file actions
37 lines (33 loc) · 1002 Bytes
/
circuit.rs
File metadata and controls
37 lines (33 loc) · 1002 Bytes
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
use crate::{build_info::report_native_call, pasta_fp_plonk_index::NapiPastaFpPlonkIndex};
use ark_ff::PrimeField;
use kimchi::circuits::{constraints::ConstraintSystem, gate::CircuitGate};
use mina_curves::pasta::Fp;
use napi::bindgen_prelude::*;
use napi_derive::napi;
use serde::Serialize;
#[derive(Serialize)]
struct Circuit<F>
where
F: PrimeField,
{
public_input_size: usize,
#[serde(bound = "CircuitGate<F>: Serialize")]
gates: Vec<CircuitGate<F>>,
}
impl<F> From<&ConstraintSystem<F>> for Circuit<F>
where
F: PrimeField,
{
fn from(cs: &ConstraintSystem<F>) -> Self {
Self {
public_input_size: cs.public,
gates: cs.gates.to_vec(),
}
}
}
#[napi(js_name = "prover_to_json")]
pub fn prover_to_json(prover_index: &External<NapiPastaFpPlonkIndex>) -> String {
report_native_call();
let circuit: Circuit<Fp> = prover_index.0.cs.as_ref().into();
serde_json::to_string(&circuit).expect("couldn't serialize constraints")
}