Skip to content

Commit

Permalink
generating proof
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-ramos committed Sep 4, 2022
1 parent cde40ba commit fcabd96
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 29 deletions.
8 changes: 4 additions & 4 deletions poseidon-tornado/Cargo.toml
Expand Up @@ -15,12 +15,12 @@ edition = "2021"
num-bigint = { version = "0.4", default-features = false, features = ["rand"] }

# ZKP Generation
ark-ec = { version = "0.3.0", default-features = false, features = ["parallel"] }
# ark-ff = { version = "0.3.0", default-features = false, features = ["parallel", "asm"] }
ark-std = { version = "0.3.0", default-features = false, features = ["parallel"] }
ark-ec = { version = "0.3.0", default-features = false, features = [] }
# ark-ff = { version = "0.3.0", default-features = false, features = [ "asm"] }
ark-std = { version = "0.3.0", default-features = false, features = [] }
ark-bn254 = { version = "0.3.0" }
ark-groth16 = { git = "https://github.com/arkworks-rs/groth16", rev = "765817f", features = ["parallel"] }
# ark-poly = { version = "^0.3.0", default-features = false, features = ["parallel"] }
# ark-poly = { version = "^0.3.0", default-features = false, features = [] }
#ark-relations = { version = "0.3.0", default-features = false, path = "../../../arkworks-rs/snark/relations", features = [ "std" ] }
ark-relations = { version = "0.3.0", default-features = false, features = [ "std" ] }
ark-serialize = { version = "0.3.0", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion rln/Cargo.toml
Expand Up @@ -17,7 +17,7 @@ ark-bn254 = { version = "0.3.0" }
ark-groth16 = { git = "https://github.com/arkworks-rs/groth16", rev = "765817f", default-features = false }
ark-relations = { version = "0.3.0", default-features = false, features = [ "std" ] }
ark-serialize = { version = "0.3.0", default-features = false }
ark-circom = { git = "https://github.com/vacp2p/ark-circom", branch = "wasm", features = ["circom-2"] }
ark-circom = { git = "https://github.com/vacp2p/ark-circom", branch = "wasm", default-features = false, features = ["circom-2"] }
getrandom = { version = "0.2.7", default-features = false, features = ["js"] }

# WASM
Expand Down
2 changes: 1 addition & 1 deletion rln/src/lib.rs
Expand Up @@ -2,14 +2,14 @@

pub mod circuit;
pub mod ffi;
pub mod wasm;
pub mod merkle_tree;
pub mod poseidon_constants;
pub mod poseidon_hash;
pub mod poseidon_tree;
pub mod protocol;
pub mod public;
pub mod utils;
pub mod wasm;

#[cfg(test)]
mod test {
Expand Down
7 changes: 3 additions & 4 deletions rln/src/protocol.rs
Expand Up @@ -398,8 +398,7 @@ fn calculate_witness_element<E: ark_ec::PairingEngine>(
pub fn generate_proof_with_witness(
witness: Vec<BigInt>,
proving_key: &(ProvingKey<Curve>, ConstraintMatrices<Fr>),
) /*-> Result<ArkProof<Curve>, ProofError>*/
{
) -> Result<ArkProof<Curve>, ProofError> {
// If in debug mode, we measure and later print time take to compute witness
// #[cfg(debug_assertions)]
//let now = Instant::now();
Expand Down Expand Up @@ -435,7 +434,7 @@ pub fn generate_proof_with_witness(
// #[cfg(debug_assertions)]
// println!("proof generation took: {:.2?}", now.elapsed());

// Ok(proof)
Ok(proof)
}

/// Generates a RLN proof
Expand Down Expand Up @@ -554,7 +553,7 @@ pub fn verify_proof(
}

/// Get CIRCOM JSON inputs
///
///
/// Returns a JSON object containing the inputs necessary to calculate
/// the witness with CIRCOM on javascript
pub fn get_json_inputs<'a>(rln_witness: &RLNWitnessInput) -> serde_json::Value {
Expand Down
22 changes: 11 additions & 11 deletions rln/src/public.rs
Expand Up @@ -218,13 +218,16 @@ impl RLN {
}

/// Get JSON inputs for serialized RLN witness
pub fn get_rln_witness_json(&mut self, serialized_witness: &[u8]) -> io::Result<serde_json::Value> {
pub fn get_rln_witness_json(
&mut self,
serialized_witness: &[u8],
) -> io::Result<serde_json::Value> {
let (rln_witness, _) = deserialize_witness(serialized_witness);
Ok(get_json_inputs(&rln_witness))
}

/// Generate RLN Proof using a witness calculated from outside zerokit
///
///
/// output_data is [ proof<128> | share_y<32> | nullifier<32> | root<32> | epoch<32> | share_x<32> | rln_identifier<32> ]
pub fn generate_rln_proof_with_witness<W: Write>(
&mut self,
Expand All @@ -236,16 +239,13 @@ impl RLN {
let proof_values = proof_values_from_witness(&rln_witness);

let proof =
generate_proof_with_witness(calculated_witness, self.proving_key.as_ref().unwrap());
generate_proof_with_witness(calculated_witness, self.proving_key.as_ref().unwrap())
.unwrap();

// TODO: uncomment once the function above is fixed ^
//.unwrap();
/*
// Note: we export a serialization of ark-groth16::Proof not semaphore::Proof
// This proof is compressed, i.e. 128 bytes long
proof.serialize(&mut output_data).unwrap();
output_data.write_all(&serialize_proof_values(&proof_values))?;
*/
// Note: we export a serialization of ark-groth16::Proof not semaphore::Proof
// This proof is compressed, i.e. 128 bytes long
proof.serialize(&mut output_data).unwrap();
output_data.write_all(&serialize_proof_values(&proof_values))?;
Ok(())
}

Expand Down
9 changes: 4 additions & 5 deletions rln/src/wasm.rs
Expand Up @@ -60,10 +60,9 @@ pub fn generate_rln_proof_with_witness(
ctx: *mut RLN,
calculated_witness: Vec<JsBigInt>,
serialized_witness: Uint8Array,
) -> bool {
) -> Result<Uint8Array, String> {
let rln = unsafe { &mut *ctx };

// web_sys::console::log_1(&identitySecret.into());
let witness_vec: Vec<BigInt> = calculated_witness
.iter()
.map(|v| {
Expand All @@ -82,12 +81,12 @@ pub fn generate_rln_proof_with_witness(
.generate_rln_proof_with_witness(witness_vec, serialized_witness.to_vec(), &mut output_data)
.is_ok()
{
//unsafe { *output_buffer = Buffer::from(&output_data[..]) };
let result = Uint8Array::from(&output_data[..]);
std::mem::forget(output_data);
true
Ok(result)
} else {
std::mem::forget(output_data);
false
Err("could not generate proof".into())
}
}

Expand Down
2 changes: 1 addition & 1 deletion rln/www/files.js

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions rln/www/index.js
Expand Up @@ -98,9 +98,12 @@ wc(circomUint8Array).then(async witnessCalculator => {
console.log("Calculated Witness", calculatedWitness)

// generate proof
let proofRes = rln.generate_rln_proof_with_witness(rln, calculatedWitness, rlnWitness);
console.log("Proof", proofRes)
console.log("Generating proof...");
console.time("proof_gen_timer");
let proofRes = rln.generate_rln_proof_with_witness(rlnInstance, calculatedWitness, rlnWitness);
console.timeEnd("proof_gen_timer");

console.log("Proof", proofRes)
// verify the proof
// TODO

Expand Down

0 comments on commit fcabd96

Please sign in to comment.