Skip to content

Commit

Permalink
fix not commited trusted setup utils
Browse files Browse the repository at this point in the history
  • Loading branch information
snjax committed Mar 9, 2020
1 parent e52c1fd commit ab9a8fe
Show file tree
Hide file tree
Showing 4 changed files with 173 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ bin/
pkg/
wasm-pack.log
.vscode
!zwaves_setup/src/bin
67 changes: 67 additions & 0 deletions zwaves_setup/src/bin/contribute.rs
Original file line number Diff line number Diff line change
@@ -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(&params_file, true)?;
drop(params_file);

let contributions = params.verify(UtxoAccumulator::<Bls12> {
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(&params_file, true)?;
drop(params_file);

let contributions = params.verify(Transfer::<Bls12> {
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(())
}
62 changes: 62 additions & 0 deletions zwaves_setup/src/bin/list.rs
Original file line number Diff line number Diff line change
@@ -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(&params_file, true)?;
drop(params_file);

let contributions = params.verify(UtxoAccumulator::<Bls12> {
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(&params_file, true)?;
drop(params_file);

let contributions = params.verify(Transfer::<Bls12> {
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(())
}
43 changes: 43 additions & 0 deletions zwaves_setup/src/bin/new.rs
Original file line number Diff line number Diff line change
@@ -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::<Bls12> {
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::<Bls12> {
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(())
}

0 comments on commit ab9a8fe

Please sign in to comment.