mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
some random adjustments on groth16 proof
This commit is contained in:
57
lisp/lisp.rs
57
lisp/lisp.rs
@@ -3,18 +3,18 @@
|
||||
use crate::types::LispCircuit;
|
||||
use bellman::groth16::PreparedVerifyingKey;
|
||||
|
||||
use simplelog::*;
|
||||
use sapvi::{BlsStringConversion, Decodable, Encodable, ZKContract, ZKProof};
|
||||
use simplelog::*;
|
||||
|
||||
use std::fs;
|
||||
use std::fs::File;
|
||||
use bellman::{groth16};
|
||||
use bellman::groth16;
|
||||
use bls12_381::Bls12;
|
||||
use fnv::FnvHashMap;
|
||||
use itertools::Itertools;
|
||||
use rand::rngs::OsRng;
|
||||
use std::fs;
|
||||
use std::fs::File;
|
||||
use std::rc::Rc;
|
||||
use std::time::Instant;
|
||||
use std::{rc::Rc};
|
||||
use types::EnforceAllocation;
|
||||
|
||||
#[macro_use]
|
||||
@@ -530,8 +530,7 @@ pub fn setup(_ast: MalVal, env: Env) -> Result<PreparedVerifyingKey<Bls12>, MalE
|
||||
params: None,
|
||||
allocs: None,
|
||||
alloc_inputs: None,
|
||||
constraints: None,
|
||||
env: None
|
||||
constraints: None
|
||||
};
|
||||
// TODO move to another fn
|
||||
let random_parameters =
|
||||
@@ -548,48 +547,38 @@ pub fn prove(_ast: MalVal, env: Env) -> MalRet {
|
||||
let enforce_allocs = get_enforce_allocs(&env);
|
||||
let allocs_const = get_allocations(&env, "AllocationsConst");
|
||||
|
||||
let start = Instant::now();
|
||||
let circuit = LispCircuit {
|
||||
params: Some(allocs_const.as_ref().clone()),
|
||||
allocs: Some(allocs.as_ref().clone()),
|
||||
alloc_inputs: Some(allocs_input.as_ref().clone()),
|
||||
constraints: Some(enforce_allocs),
|
||||
};
|
||||
let params = {
|
||||
let c = LispCircuit {
|
||||
params: Some(FnvHashMap::default()),
|
||||
allocs: Some(FnvHashMap::default()),
|
||||
alloc_inputs: Some(FnvHashMap::default()),
|
||||
constraints: Some(vec![]),
|
||||
env: Some(env.clone())
|
||||
};
|
||||
let c = circuit.clone();
|
||||
groth16::generate_random_parameters::<Bls12, _, _>(c, &mut OsRng).unwrap()
|
||||
};
|
||||
let pvk = groth16::prepare_verifying_key(¶ms.vk);
|
||||
|
||||
let circuit = LispCircuit {
|
||||
params: Some(allocs_const.as_ref().clone()),
|
||||
allocs: Some(allocs.as_ref().clone()),
|
||||
alloc_inputs: Some(allocs_input.as_ref().clone()),
|
||||
constraints: Some(enforce_allocs),
|
||||
env: Some(env.clone())
|
||||
};
|
||||
let start = Instant::now();
|
||||
let proof = groth16::create_random_proof(circuit, ¶ms, &mut OsRng);
|
||||
let proof = groth16::create_random_proof(circuit, ¶ms, &mut OsRng).unwrap();
|
||||
/*
|
||||
match proof {
|
||||
_ => {
|
||||
Ok(v) => {
|
||||
println!("Prove: [{:?}]", start.elapsed());
|
||||
let mut file = File::create("prove.out").unwrap();
|
||||
//proof.write(file);
|
||||
|
||||
let mut vec_input = vec![];
|
||||
for (k, val) in allocs_input.iter() {
|
||||
if let MalVal::ZKScalar(v) = val {
|
||||
vec_input.push(*v);
|
||||
vec_input.push(*v);
|
||||
}
|
||||
}
|
||||
// let verify_result = groth16::verify_proof(&pvk, &proof, &vec_input.as_slice()).is_ok();
|
||||
// println!("{:?}", verify_result);
|
||||
// let verify_result = groth16::verify_proof(&pvk, &proof, &vec_input.as_slice()).is_ok();
|
||||
// println!("{:?}", verify_result);
|
||||
}
|
||||
Err(e) => {
|
||||
println!("{:?}", e);
|
||||
println!("Error {:?}", e);
|
||||
}
|
||||
};
|
||||
Ok(MalVal::Nil)
|
||||
|
||||
*/
|
||||
Ok(MalVal::Nil)
|
||||
}
|
||||
|
||||
pub fn verify(_ast: &MalVal) -> MalRet {
|
||||
|
||||
@@ -31,8 +31,7 @@ pub struct LispCircuit {
|
||||
pub params: Option<FnvHashMap<String, MalVal>>,
|
||||
pub allocs: Option<FnvHashMap<String, MalVal>>,
|
||||
pub alloc_inputs: Option<FnvHashMap<String, MalVal>>,
|
||||
pub constraints: Option<Vec<EnforceAllocation>>,
|
||||
pub env: Option<Env>,
|
||||
pub constraints: Option<Vec<EnforceAllocation>>
|
||||
}
|
||||
|
||||
impl Circuit<bls12_381::Scalar> for LispCircuit {
|
||||
@@ -41,7 +40,7 @@ impl Circuit<bls12_381::Scalar> for LispCircuit {
|
||||
cs: &mut CS,
|
||||
) -> Result<(), SynthesisError> {
|
||||
let mut variables: FnvHashMap<String, Variable> = FnvHashMap::default();
|
||||
let mut params_const = self.params.unwrap_or(FnvHashMap::default());
|
||||
let mut params_const = self.params.unwrap_or(FnvHashMap::default());
|
||||
|
||||
println!("Allocations\n");
|
||||
for (k, v) in &self.allocs.unwrap_or(FnvHashMap::default()) {
|
||||
|
||||
Reference in New Issue
Block a user