cargo fmt

This commit is contained in:
Jack Grigg 2019-02-11 00:02:33 +00:00
parent 7934d34502
commit 0535fae568
No known key found for this signature in database
GPG Key ID: 1B8D649257DB0829
6 changed files with 181 additions and 128 deletions

View File

@ -1,22 +1,22 @@
extern crate phase2;
extern crate pairing;
extern crate rand;
extern crate blake2_rfc; extern crate blake2_rfc;
extern crate byteorder; extern crate byteorder;
extern crate pairing;
extern crate phase2;
extern crate rand;
#[macro_use] #[macro_use]
extern crate hex_literal; extern crate hex_literal;
use std::fs::File;
use std::io::{BufWriter, BufReader};
use blake2_rfc::blake2b::Blake2b; use blake2_rfc::blake2b::Blake2b;
use std::fs::File;
use std::io::{BufReader, BufWriter};
fn main() { fn main() {
let current_params = File::open("params").expect("couldn't open `./params`"); let current_params = File::open("params").expect("couldn't open `./params`");
let mut current_params = BufReader::with_capacity(1024*1024, current_params); let mut current_params = BufReader::with_capacity(1024 * 1024, current_params);
let new_params = File::create("new_params").expect("couldn't create `./new_params`"); let new_params = File::create("new_params").expect("couldn't create `./new_params`");
let mut new_params = BufWriter::with_capacity(1024*1024, new_params); let mut new_params = BufWriter::with_capacity(1024 * 1024, new_params);
let mut sapling_spend = phase2::MPCParameters::read(&mut current_params, false) let mut sapling_spend = phase2::MPCParameters::read(&mut current_params, false)
.expect("couldn't deserialize Sapling Spend params"); .expect("couldn't deserialize Sapling Spend params");
@ -29,12 +29,13 @@ fn main() {
// Create an RNG based on the outcome of the random beacon // Create an RNG based on the outcome of the random beacon
let rng = &mut { let rng = &mut {
use byteorder::{ReadBytesExt, BigEndian}; use byteorder::{BigEndian, ReadBytesExt};
use rand::{SeedableRng};
use rand::chacha::ChaChaRng; use rand::chacha::ChaChaRng;
use rand::SeedableRng;
// Place beacon value here (2^42 SHA256 hash of Bitcoin block hash #534861) // Place beacon value here (2^42 SHA256 hash of Bitcoin block hash #534861)
let beacon_value: [u8; 32] = hex!("2bf41a959668e5b9b688e58d613b3dcc99ee159a880cf764ec67e6488d8b8af3"); let beacon_value: [u8; 32] =
hex!("2bf41a959668e5b9b688e58d613b3dcc99ee159a880cf764ec67e6488d8b8af3");
print!("Final result of beacon: "); print!("Final result of beacon: ");
for b in beacon_value.iter() { for b in beacon_value.iter() {
@ -46,7 +47,9 @@ fn main() {
let mut seed = [0u32; 8]; let mut seed = [0u32; 8];
for i in 0..8 { for i in 0..8 {
seed[i] = digest.read_u32::<BigEndian>().expect("digest is large enough for this to work"); seed[i] = digest
.read_u32::<BigEndian>()
.expect("digest is large enough for this to work");
} }
ChaChaRng::from_seed(&seed) ChaChaRng::from_seed(&seed)
@ -56,9 +59,15 @@ fn main() {
let h2 = sapling_output.contribute(rng); let h2 = sapling_output.contribute(rng);
let h3 = sprout_joinsplit.contribute(rng); let h3 = sprout_joinsplit.contribute(rng);
sapling_spend.write(&mut new_params).expect("couldn't write new Sapling Spend params"); sapling_spend
sapling_output.write(&mut new_params).expect("couldn't write new Sapling Spend params"); .write(&mut new_params)
sprout_joinsplit.write(&mut new_params).expect("couldn't write new Sapling Spend params"); .expect("couldn't write new Sapling Spend params");
sapling_output
.write(&mut new_params)
.expect("couldn't write new Sapling Spend params");
sprout_joinsplit
.write(&mut new_params)
.expect("couldn't write new Sapling Spend params");
let mut h = Blake2b::new(64); let mut h = Blake2b::new(64);
h.update(&h1); h.update(&h1);
@ -66,9 +75,11 @@ fn main() {
h.update(&h3); h.update(&h3);
let h = h.finalize(); let h = h.finalize();
print!("Done!\n\n\ print!(
Your contribution has been written to `./new_params`\n\n\ "Done!\n\n\
The contribution you made is bound to the following hash:\n"); Your contribution has been written to `./new_params`\n\n\
The contribution you made is bound to the following hash:\n"
);
for line in h.as_ref().chunks(16) { for line in h.as_ref().chunks(16) {
print!("\t"); print!("\t");

View File

@ -1,18 +1,18 @@
extern crate phase2;
extern crate pairing;
extern crate rand;
extern crate blake2_rfc; extern crate blake2_rfc;
extern crate pairing;
extern crate phase2;
extern crate rand;
use std::fs::File;
use std::io::{BufWriter, BufReader};
use blake2_rfc::blake2b::Blake2b; use blake2_rfc::blake2b::Blake2b;
use std::fs::File;
use std::io::{BufReader, BufWriter};
fn main() { fn main() {
let current_params = File::open("params").expect("couldn't open `./params`"); let current_params = File::open("params").expect("couldn't open `./params`");
let mut current_params = BufReader::with_capacity(1024*1024, current_params); let mut current_params = BufReader::with_capacity(1024 * 1024, current_params);
let new_params = File::create("new_params").expect("couldn't create `./new_params`"); let new_params = File::create("new_params").expect("couldn't create `./new_params`");
let mut new_params = BufWriter::with_capacity(1024*1024, new_params); let mut new_params = BufWriter::with_capacity(1024 * 1024, new_params);
let mut sapling_spend = phase2::MPCParameters::read(&mut current_params, false) let mut sapling_spend = phase2::MPCParameters::read(&mut current_params, false)
.expect("couldn't deserialize Sapling Spend params"); .expect("couldn't deserialize Sapling Spend params");
@ -29,9 +29,15 @@ fn main() {
let h2 = sapling_output.contribute(rng); let h2 = sapling_output.contribute(rng);
let h3 = sprout_joinsplit.contribute(rng); let h3 = sprout_joinsplit.contribute(rng);
sapling_spend.write(&mut new_params).expect("couldn't write new Sapling Spend params"); sapling_spend
sapling_output.write(&mut new_params).expect("couldn't write new Sapling Spend params"); .write(&mut new_params)
sprout_joinsplit.write(&mut new_params).expect("couldn't write new Sapling Spend params"); .expect("couldn't write new Sapling Spend params");
sapling_output
.write(&mut new_params)
.expect("couldn't write new Sapling Spend params");
sprout_joinsplit
.write(&mut new_params)
.expect("couldn't write new Sapling Spend params");
let mut h = Blake2b::new(64); let mut h = Blake2b::new(64);
h.update(&h1); h.update(&h1);
@ -39,9 +45,11 @@ fn main() {
h.update(&h3); h.update(&h3);
let h = h.finalize(); let h = h.finalize();
print!("Done!\n\n\ print!(
Your contribution has been written to `./new_params`\n\n\ "Done!\n\n\
The contribution you made is bound to the following hash:\n"); Your contribution has been written to `./new_params`\n\n\
The contribution you made is bound to the following hash:\n"
);
for line in h.as_ref().chunks(16) { for line in h.as_ref().chunks(16) {
print!("\t"); print!("\t");

View File

@ -1,6 +1,6 @@
extern crate pairing;
extern crate phase2; extern crate phase2;
extern crate sapling_crypto; extern crate sapling_crypto;
extern crate pairing;
use std::fs::File; use std::fs::File;
use std::io::BufWriter; use std::io::BufWriter;
@ -20,8 +20,11 @@ fn main() {
commitment_randomness: None, commitment_randomness: None,
ar: None, ar: None,
auth_path: vec![None; 32], // Tree depth is 32 for sapling auth_path: vec![None; 32], // Tree depth is 32 for sapling
anchor: None anchor: None,
}).unwrap().write(&mut params).unwrap(); })
.unwrap()
.write(&mut params)
.unwrap();
// Sapling output circuit // Sapling output circuit
phase2::MPCParameters::new(sapling_crypto::circuit::sapling::Output { phase2::MPCParameters::new(sapling_crypto::circuit::sapling::Output {
@ -29,8 +32,11 @@ fn main() {
value_commitment: None, value_commitment: None,
payment_address: None, payment_address: None,
commitment_randomness: None, commitment_randomness: None,
esk: None esk: None,
}).unwrap().write(&mut params).unwrap(); })
.unwrap()
.write(&mut params)
.unwrap();
// Sprout joinsplit circuit // Sprout joinsplit circuit
phase2::MPCParameters::new(sapling_crypto::circuit::sprout::JoinSplit { phase2::MPCParameters::new(sapling_crypto::circuit::sprout::JoinSplit {
@ -38,28 +44,37 @@ fn main() {
vpub_new: None, vpub_new: None,
h_sig: None, h_sig: None,
phi: None, phi: None,
inputs: vec![sapling_crypto::circuit::sprout::JSInput { inputs: vec![
value: None, sapling_crypto::circuit::sprout::JSInput {
a_sk: None, value: None,
rho: None, a_sk: None,
r: None, rho: None,
auth_path: [None; 29] // Depth is 29 for Sprout r: None,
}, sapling_crypto::circuit::sprout::JSInput { auth_path: [None; 29], // Depth is 29 for Sprout
value: None, },
a_sk: None, sapling_crypto::circuit::sprout::JSInput {
rho: None, value: None,
r: None, a_sk: None,
auth_path: [None; 29] // Depth is 29 for Sprout rho: None,
}], r: None,
outputs: vec![sapling_crypto::circuit::sprout::JSOutput { auth_path: [None; 29], // Depth is 29 for Sprout
value: None, },
a_pk: None, ],
r: None outputs: vec![
}, sapling_crypto::circuit::sprout::JSOutput { sapling_crypto::circuit::sprout::JSOutput {
value: None, value: None,
a_pk: None, a_pk: None,
r: None r: None,
}], },
sapling_crypto::circuit::sprout::JSOutput {
value: None,
a_pk: None,
r: None,
},
],
rt: None, rt: None,
}).unwrap().write(&mut params).unwrap(); })
.unwrap()
.write(&mut params)
.unwrap();
} }

View File

@ -1,16 +1,16 @@
//! This binary just splits the parameters up into separate files. //! This binary just splits the parameters up into separate files.
extern crate phase2;
extern crate pairing;
extern crate rand;
extern crate blake2_rfc; extern crate blake2_rfc;
extern crate pairing;
extern crate phase2;
extern crate rand;
use std::fs::File; use std::fs::File;
use std::io::{BufWriter, BufReader}; use std::io::{BufReader, BufWriter};
fn main() { fn main() {
let current_params = File::open("params").expect("couldn't open `./params`"); let current_params = File::open("params").expect("couldn't open `./params`");
let mut current_params = BufReader::with_capacity(1024*1024, current_params); let mut current_params = BufReader::with_capacity(1024 * 1024, current_params);
let sapling_spend = phase2::MPCParameters::read(&mut current_params, false) let sapling_spend = phase2::MPCParameters::read(&mut current_params, false)
.expect("couldn't deserialize Sapling Spend params"); .expect("couldn't deserialize Sapling Spend params");
@ -22,23 +22,29 @@ fn main() {
.expect("couldn't deserialize Sprout JoinSplit params"); .expect("couldn't deserialize Sprout JoinSplit params");
{ {
let f = File::create("sapling-spend.params").expect("couldn't create `./sapling-spend.params`"); let f =
let mut f = BufWriter::with_capacity(1024*1024, f); File::create("sapling-spend.params").expect("couldn't create `./sapling-spend.params`");
sapling_spend.write(&mut f) let mut f = BufWriter::with_capacity(1024 * 1024, f);
sapling_spend
.write(&mut f)
.expect("couldn't write new Sapling Spend params"); .expect("couldn't write new Sapling Spend params");
} }
{ {
let f = File::create("sapling-output.params").expect("couldn't create `./sapling-output.params`"); let f = File::create("sapling-output.params")
let mut f = BufWriter::with_capacity(1024*1024, f); .expect("couldn't create `./sapling-output.params`");
sapling_output.write(&mut f) let mut f = BufWriter::with_capacity(1024 * 1024, f);
sapling_output
.write(&mut f)
.expect("couldn't write new Sapling Output params"); .expect("couldn't write new Sapling Output params");
} }
{ {
let f = File::create("sprout-groth16.params").expect("couldn't create `./sapling-groth16.params`"); let f = File::create("sprout-groth16.params")
let mut f = BufWriter::with_capacity(1024*1024, f); .expect("couldn't create `./sapling-groth16.params`");
sprout_joinsplit.write(&mut f) let mut f = BufWriter::with_capacity(1024 * 1024, f);
sprout_joinsplit
.write(&mut f)
.expect("couldn't write new Sprout JoinSplit params"); .expect("couldn't write new Sprout JoinSplit params");
} }
} }

View File

@ -1,11 +1,11 @@
extern crate blake2_rfc;
extern crate pairing;
extern crate phase2; extern crate phase2;
extern crate sapling_crypto; extern crate sapling_crypto;
extern crate pairing;
extern crate blake2_rfc;
use blake2_rfc::blake2b::Blake2b;
use std::fs::File; use std::fs::File;
use std::io::BufReader; use std::io::BufReader;
use blake2_rfc::blake2b::Blake2b;
fn main() { fn main() {
let jubjub_params = sapling_crypto::jubjub::JubjubBls12::new(); let jubjub_params = sapling_crypto::jubjub::JubjubBls12::new();
@ -22,56 +22,69 @@ fn main() {
let sprout_joinsplit = phase2::MPCParameters::read(&mut params, true) let sprout_joinsplit = phase2::MPCParameters::read(&mut params, true)
.expect("couldn't deserialize Sprout JoinSplit params"); .expect("couldn't deserialize Sprout JoinSplit params");
let sapling_spend_contributions = sapling_spend.verify(sapling_crypto::circuit::sapling::Spend { let sapling_spend_contributions = sapling_spend
params: &jubjub_params, .verify(sapling_crypto::circuit::sapling::Spend {
value_commitment: None, params: &jubjub_params,
proof_generation_key: None, value_commitment: None,
payment_address: None, proof_generation_key: None,
commitment_randomness: None, payment_address: None,
ar: None, commitment_randomness: None,
auth_path: vec![None; 32], // Tree depth is 32 for sapling ar: None,
anchor: None auth_path: vec![None; 32], // Tree depth is 32 for sapling
}).expect("parameters are invalid"); anchor: None,
})
.expect("parameters are invalid");
let sapling_output_contributions = sapling_output.verify(sapling_crypto::circuit::sapling::Output { let sapling_output_contributions = sapling_output
params: &jubjub_params, .verify(sapling_crypto::circuit::sapling::Output {
value_commitment: None, params: &jubjub_params,
payment_address: None, value_commitment: None,
commitment_randomness: None, payment_address: None,
esk: None commitment_randomness: None,
}).expect("parameters are invalid"); esk: None,
})
.expect("parameters are invalid");
let sprout_joinsplit_contributions = sprout_joinsplit.verify(sapling_crypto::circuit::sprout::JoinSplit { let sprout_joinsplit_contributions = sprout_joinsplit
vpub_old: None, .verify(sapling_crypto::circuit::sprout::JoinSplit {
vpub_new: None, vpub_old: None,
h_sig: None, vpub_new: None,
phi: None, h_sig: None,
inputs: vec![sapling_crypto::circuit::sprout::JSInput { phi: None,
value: None, inputs: vec![
a_sk: None, sapling_crypto::circuit::sprout::JSInput {
rho: None, value: None,
r: None, a_sk: None,
auth_path: [None; 29] // Depth is 29 for Sprout rho: None,
}, sapling_crypto::circuit::sprout::JSInput { r: None,
value: None, auth_path: [None; 29], // Depth is 29 for Sprout
a_sk: None, },
rho: None, sapling_crypto::circuit::sprout::JSInput {
r: None, value: None,
auth_path: [None; 29] // Depth is 29 for Sprout a_sk: None,
}], rho: None,
outputs: vec![sapling_crypto::circuit::sprout::JSOutput { r: None,
value: None, auth_path: [None; 29], // Depth is 29 for Sprout
a_pk: None, },
r: None ],
}, sapling_crypto::circuit::sprout::JSOutput { outputs: vec![
value: None, sapling_crypto::circuit::sprout::JSOutput {
a_pk: None, value: None,
r: None a_pk: None,
}], r: None,
rt: None, },
}).expect("parameters are invalid"); sapling_crypto::circuit::sprout::JSOutput {
value: None,
a_pk: None,
r: None,
},
],
rt: None,
})
.expect("parameters are invalid");
for ((a, b), c) in sapling_spend_contributions.into_iter() for ((a, b), c) in sapling_spend_contributions
.into_iter()
.zip(sapling_output_contributions.into_iter()) .zip(sapling_output_contributions.into_iter())
.zip(sprout_joinsplit_contributions) .zip(sprout_joinsplit_contributions)
{ {

View File

@ -1,10 +1,10 @@
extern crate phase2;
extern crate pairing;
extern crate blake2_rfc; extern crate blake2_rfc;
extern crate pairing;
extern crate phase2;
use blake2_rfc::blake2b::Blake2b;
use std::fs::File; use std::fs::File;
use std::io::BufReader; use std::io::BufReader;
use blake2_rfc::blake2b::Blake2b;
fn main() { fn main() {
let params = File::open("params").unwrap(); let params = File::open("params").unwrap();
@ -33,17 +33,17 @@ fn main() {
let h1 = match phase2::verify_contribution(&sapling_spend, &new_sapling_spend) { let h1 = match phase2::verify_contribution(&sapling_spend, &new_sapling_spend) {
Ok(hash) => hash, Ok(hash) => hash,
Err(_) => panic!("invalid transformation!") Err(_) => panic!("invalid transformation!"),
}; };
let h2 = match phase2::verify_contribution(&sapling_output, &new_sapling_output) { let h2 = match phase2::verify_contribution(&sapling_output, &new_sapling_output) {
Ok(hash) => hash, Ok(hash) => hash,
Err(_) => panic!("invalid transformation!") Err(_) => panic!("invalid transformation!"),
}; };
let h3 = match phase2::verify_contribution(&sprout_joinsplit, &new_sprout_joinsplit) { let h3 = match phase2::verify_contribution(&sprout_joinsplit, &new_sprout_joinsplit) {
Ok(hash) => hash, Ok(hash) => hash,
Err(_) => panic!("invalid transformation!") Err(_) => panic!("invalid transformation!"),
}; };
let mut h = Blake2b::new(64); let mut h = Blake2b::new(64);