use ark_ec::PairingEngine; use ark_ff::fields::PrimeField; use ark_std::test_rng; use voproof::cs::{hpr::*, ConstraintSystem}; use voproof::error::Error; use voproof::kzg::UniversalParams; use voproof::snarks::{voproof_hpr::*, SNARK}; use voproof::tools::{to_field, to_int, try_to_int}; use voproof::*; fn run_hpr_example(scale: usize) -> Result<(), Error> { let rng = &mut test_rng(); let (hpr, instance, witness) = generate_random_hpr_instance(scale as u64, scale as u64, scale as u64 / 5, rng); if hpr.satisfy(&instance, &witness) { println!("HPR satisfied!"); } else { println!("HPR unsatisfied!"); } let max_degree = VOProofHPR::get_max_degree(hpr.get_size()); // Let the universal parameters take a larger size than expected let universal_params: UniversalParams = VOProofHPR::setup(max_degree + 10).unwrap(); println!( "Universal parameter size: {}", universal_params.powers_of_g.len() ); let (pk, vk) = VOProofHPR::index(&universal_params, &hpr).unwrap(); println!("Degree bound: {}", vk.degree_bound); println!("Max degree: {}", pk.max_degree); println!("Prover key matrix size: {}", pk.cap_m_mat.0.len()); println!("Prover key u size: {}", pk.u_vec.len()); println!("Prover key v size: {}", pk.v_vec.len()); println!("Prover key w size: {}", pk.w_vec.len()); println!("M A row indices: {:?}", pk.cap_m_mat.0); println!("M A col indices: {:?}", pk.cap_m_mat.1); println!("M A vals: {}", fmt_ff_vector!(pk.cap_m_mat.2)); let vksize = vk.size.clone(); println!("H: {}", vksize.nrows); println!("K: {}", vksize.ncols); let proof = VOProofHPR::prove(&pk, &instance, &witness)?; VOProofHPR::verify(&vk, &instance, &proof) } #[test] fn test_simple_hpr_small_scales() { assert!(run_hpr_example::(5).is_ok()); assert!(run_hpr_example::(10).is_ok()); assert!(run_hpr_example::(15).is_ok()); assert!(run_hpr_example::(20).is_ok()); }