1use crate::pasta_fp_plonk_index::WasmPastaFpPlonkIndex;
2use ark_ff::PrimeField;
3use kimchi::circuits::{constraints::ConstraintSystem, gate::CircuitGate};
4use mina_curves::pasta::Fp;
5use napi::bindgen_prelude::*;
6use napi_derive::napi;
7use serde::Serialize;
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 Self {
25 public_input_size: cs.public,
26 gates: cs.gates.to_vec(),
27 }
28 }
29}
30
31#[napi(js_name = "prover_to_json")]
32pub fn prover_to_json(prover_index: &External<WasmPastaFpPlonkIndex>) -> String {
33 let circuit: Circuit<Fp> = prover_index.0.cs.as_ref().into();
34 serde_json::to_string(&circuit).expect("couldn't serialize constraints")
35}