diff --git a/.gitignore b/.gitignore index ccf9db4..18f8e7e 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ bin/ pkg/ wasm-pack.log .vscode +!zwaves_setup/src/bin diff --git a/zwaves_setup/src/bin/contribute.rs b/zwaves_setup/src/bin/contribute.rs new file mode 100644 index 0000000..46bd5eb --- /dev/null +++ b/zwaves_setup/src/bin/contribute.rs @@ -0,0 +1,67 @@ +use bellman::{Circuit, ConstraintSystem, SynthesisError}; +use sapling_crypto::jubjub::{JubjubEngine, JubjubParams, JubjubBls12}; +use pairing::bls12_381::{Bls12, Fr}; +use rand::os::OsRng; +use rand::Rng; + +use std::fs::File; +use std::io::{Write, Read}; +use zwaves_circuit::circuit::{UtxoAccumulator, Transfer}; + +use hex::encode; + + +fn main() -> std::io::Result<()> { + let rng = &mut OsRng::new().unwrap(); + let jubjub_params = JubjubBls12::new(); + + let params_file = File::open("mpc_params_accumulator")?; + let mut params = phase2::MPCParameters::read(¶ms_file, true)?; + drop(params_file); + + let contributions = params.verify(UtxoAccumulator:: { + params: &jubjub_params, + note_hashes: [None, None], + index: None, + old_proof: None, + new_proof: None + }).expect("parameters should be valid!"); + + + let hash = params.contribute(rng); + + println!("Contributed with hash {}", encode(hash.as_ref())); + + + let params_file = File::create("mpc_params_accumulator")?; + params.write(params_file)?; + + + let params_file = File::open("mpc_params_transfer")?; + let mut params = phase2::MPCParameters::read(¶ms_file, true)?; + drop(params_file); + + let contributions = params.verify(Transfer:: { + params: &jubjub_params, + receiver: None, + in_note: [None, None], + out_note: [None, None], + in_proof: [None, None], + root_hash: None, + sk: None, + packed_asset:None, + }).expect("parameters should be valid!"); + + + let hash = params.contribute(rng); + + println!("Contributed with hash {}", encode(hash.as_ref())); + + + let params_file = File::create("mpc_params_transfer")?; + params.write(params_file)?; + + + println!("MPC params saved OK"); + Ok(()) +} diff --git a/zwaves_setup/src/bin/list.rs b/zwaves_setup/src/bin/list.rs new file mode 100644 index 0000000..3b27e49 --- /dev/null +++ b/zwaves_setup/src/bin/list.rs @@ -0,0 +1,62 @@ +use bellman::{Circuit, ConstraintSystem, SynthesisError}; +use sapling_crypto::jubjub::{JubjubEngine, JubjubParams, JubjubBls12}; +use pairing::bls12_381::{Bls12, Fr}; + + +use std::fs::File; +use std::io::Read; + +use zwaves_circuit::circuit::{Transfer, UtxoAccumulator}; +use hex::encode; + + +fn main() -> std::io::Result<()> { + let jubjub_params = JubjubBls12::new(); + + + let params_file = File::open("mpc_params_accumulator")?; + let mut params = phase2::MPCParameters::read(¶ms_file, true)?; + drop(params_file); + + let contributions = params.verify(UtxoAccumulator:: { + params: &jubjub_params, + note_hashes: [None, None], + index: None, + old_proof: None, + new_proof: None + }).expect("parameters should be valid!"); + + println!("List of all contributions:"); + + contributions.into_iter().enumerate().for_each(|(i, h)| { + println!("{}. {}", i, encode(h.as_ref())); + }); + + + + let params_file = File::open("mpc_params_transfer")?; + let mut params = phase2::MPCParameters::read(¶ms_file, true)?; + drop(params_file); + + let contributions = params.verify(Transfer:: { + params: &jubjub_params, + receiver: None, + in_note: [None, None], + out_note: [None, None], + in_proof: [None, None], + root_hash: None, + packed_asset: None, + sk: None + }).expect("parameters should be valid!"); + + println!("List of all contributions:"); + + contributions.into_iter().enumerate().for_each(|(i, h)| { + println!("{}. {}", i, encode(h.as_ref())); + }); + + + + + Ok(()) +} diff --git a/zwaves_setup/src/bin/new.rs b/zwaves_setup/src/bin/new.rs new file mode 100644 index 0000000..76476c0 --- /dev/null +++ b/zwaves_setup/src/bin/new.rs @@ -0,0 +1,43 @@ +use sapling_crypto::jubjub::{JubjubEngine, JubjubParams, JubjubBls12}; +use pairing::bls12_381::{Bls12, Fr}; +use std::fs::File; +use std::io::Write; + +use zwaves_circuit::circuit::{UtxoAccumulator, Transfer}; + + + + + +fn main() -> std::io::Result<()> { + let jubjub_params = JubjubBls12::new(); +/* + let params = phase2::MPCParameters::new(UtxoAccumulator:: { + params: &jubjub_params, + note_hashes: [None, None], + index: None, + old_proof: None, + new_proof: None + }).unwrap(); + + let params_file = File::create("mpc_params_accumulator")?; + params.write(params_file)?;*/ + + + let params = phase2::MPCParameters::new(Transfer:: { + params: &jubjub_params, + receiver: None, + in_note: [None, None], + out_note: [None, None], + in_proof: [None, None], + root_hash: None, + packed_asset: None, + sk: None + }).unwrap(); + + let params_file = File::create("mpc_params_transfer")?; + params.write(params_file)?; + + println!("MPC params saved OK"); + Ok(()) +}