Created
June 27, 2024 07:29
-
-
Save utsavjnn/fad24d5e3f5dcbaeef79dff9eea29226 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::path::PathBuf; | |
use snark_verifier_sdk::{ | |
evm::gen_evm_proof_shplonk, | |
snark_verifier::{ | |
halo2_base::halo2_proofs::{ | |
halo2curves::bn256::{Bn256, Fr, G1Affine}, | |
plonk::ProvingKey, | |
poly::kzg::commitment::ParamsKZG, | |
}, | |
system::halo2::{compile, Config}, | |
}, | |
CircuitExt, | |
}; | |
pub fn generate_quantum_files<'params, C: CircuitExt<Fr>>( | |
params: &'params ParamsKZG<Bn256>, | |
pk: &'params ProvingKey<G1Affine>, | |
circuit: C, | |
instances: Vec<Vec<Fr>>, | |
storage_path: PathBuf, | |
) { | |
let vk = pk.get_vk(); | |
let protocol = compile( | |
params, | |
vk, | |
Config::kzg() | |
.with_num_instance(circuit.num_instance()) | |
.with_accumulator_indices(C::accumulator_indices()), | |
); | |
let protocol_json = serde_json::to_string(&protocol).unwrap(); | |
// dump protocol.json file | |
std::fs::write(storage_path.join("protocol.json"), protocol_json).unwrap(); | |
let sg2_json = serde_json::to_string(¶ms.s_g2()).unwrap(); | |
// dump sg2.json file | |
std::fs::write(storage_path.join("sg2.json"), sg2_json).unwrap(); | |
let instances_json = serde_json::to_string(&instances).unwrap(); | |
let proof = gen_evm_proof_shplonk(params, pk, circuit, instances); | |
// dump instances.json file | |
std::fs::write(storage_path.join("instances.json"), instances_json).unwrap(); | |
// dump proof.bin file | |
std::fs::write(storage_path.join("proof.bin"), proof.as_slice()).unwrap(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment