1use ark_ff::PrimeField;
2use kimchi::circuits::{constraints::ConstraintSystem, gate::CircuitGate};
3use mina_curves::pasta::Fp;
4use serde::Serialize;
5use wasm_bindgen::prelude::wasm_bindgen;
6
7use crate::pasta_fp_plonk_index::WasmPastaFpPlonkIndex;
8
9#[derive(Serialize)]
10struct Circuit<F>
11where
12 F: PrimeField,
13{
14 public_input_size: usize,
15 #[serde(bound = "CircuitGate<F>: Serialize")]
16 gates: Vec<CircuitGate<F>>,
17}
18
19impl<F> From<&ConstraintSystem<F>> for Circuit<F>
20where
21 F: PrimeField,
22{
23 fn from(cs: &ConstraintSystem<F>) -> Self {
24 Circuit {
25 public_input_size: cs.public,
26 gates: cs.gates.clone(),
27 }
28 }
29}
30
31#[wasm_bindgen]
32pub fn prover_to_json(prover_index: &WasmPastaFpPlonkIndex) -> String {
33 let circuit: Circuit<Fp> = (&prover_index.0.cs).into();
34 serde_json::to_string(&circuit).expect("couldn't serialize constraints")
35}