From a7cd6e0529c7aa1a74244ec4f034c34cbcc90647 Mon Sep 17 00:00:00 2001 From: Marc Brinkmann Date: Fri, 31 Aug 2018 15:35:27 +0200 Subject: [PATCH] Update to Rust `beta` channel. --- .travis.yml | 11 +++-------- examples/threshold_enc.rs | 3 +-- examples/threshold_sig.rs | 34 +++++++++++++++++----------------- src/lib.rs | 11 ++++------- src/poly.rs | 17 ++++++----------- 5 files changed, 31 insertions(+), 45 deletions(-) diff --git a/.travis.yml b/.travis.yml index fb007f8..cddb965 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,14 +20,9 @@ env: - RUST_BACKTRACE=1 # Enables additional cpu-specific optimizations. - RUSTFLAGS="-D warnings -C target-cpu=native" - # Note: Currently (as of 2018-07-13), `clippy-preview` is only in the nightly - # release. A version of `rustfmt` that supports the `--check` option - # is also not in stable yet. - # - # A Clear migration path is swapping out `nightly-2018-07-13` with - # `beta` after the stable release of Rust 1.28; and finally migrating - # everything to `stable` at Rust 1.29. - - RUST_NEXT=nightly-2018-07-13 + # Note: `beta` should be removed along with `RUST_NEXT` after the 1.28 + # stable release on 2018-09-13. + - RUST_NEXT=beta script: - cargo +${RUST_NEXT} clippy -- --deny clippy - cargo +${RUST_NEXT} clippy --tests --examples --benches -- --deny clippy diff --git a/examples/threshold_enc.rs b/examples/threshold_enc.rs index 96f850a..5946672 100644 --- a/examples/threshold_enc.rs +++ b/examples/threshold_enc.rs @@ -35,8 +35,7 @@ impl SecretSociety { let sk_share = sk_set.secret_key_share(id).unwrap(); let pk_share = pk_set.public_key_share(id); Actor::new(id, sk_share, pk_share) - }) - .collect(); + }).collect(); SecretSociety { actors, pk_set } } diff --git a/examples/threshold_sig.rs b/examples/threshold_sig.rs index 314a623..aed25d0 100644 --- a/examples/threshold_sig.rs +++ b/examples/threshold_sig.rs @@ -53,8 +53,7 @@ impl ChatNetwork { let sk_share = sk_set.secret_key_share(id).unwrap(); let pk_share = pk_set.public_key_share(id); Node::new(id, sk_share, pk_share) - }) - .collect(); + }).collect(); ChatNetwork { pk_set, @@ -94,22 +93,23 @@ impl ChatNetwork { // signature shares (i.e. has been signed by `threshold + 1` nodes). fn run_consensus(&self) -> Option<(UserId, Msg, Signature)> { // Create a new `MsgDatabase` of every message that has been signed by a validator node. - let all_pending: MsgDatabase = self.nodes.iter().fold( - BTreeMap::new(), - |mut all_pending, node| { - for (user_id, signed_msgs) in &node.pending { - let mut user_msgs = all_pending.entry(*user_id).or_insert_with(BTreeMap::new); - for (msg, sigs) in signed_msgs.iter() { - let sigs = sigs.iter().cloned(); - user_msgs - .entry(msg.to_string()) - .or_insert_with(Vec::new) - .extend(sigs); + let all_pending: MsgDatabase = + self.nodes + .iter() + .fold(BTreeMap::new(), |mut all_pending, node| { + for (user_id, signed_msgs) in &node.pending { + let mut user_msgs = + all_pending.entry(*user_id).or_insert_with(BTreeMap::new); + for (msg, sigs) in signed_msgs.iter() { + let sigs = sigs.iter().cloned(); + user_msgs + .entry(msg.to_string()) + .or_insert_with(Vec::new) + .extend(sigs); + } } - } - all_pending - }, - ); + all_pending + }); // Iterate over the `MsgDatabase` numerically by user ID, then iterate over each user's // messages alphabetically. Try to combine the validator signatures. The first message that diff --git a/src/lib.rs b/src/lib.rs index 0eda80d..abd3da4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -38,7 +38,7 @@ use byteorder::{BigEndian, ByteOrder}; use errno::errno; use init_with::InitWith; use memsec::{memzero, mlock, munlock}; -use pairing::bls12_381::{Bls12, Fr, G1, G1Affine, G2, G2Affine}; +use pairing::bls12_381::{Bls12, Fr, G1Affine, G2Affine, G1, G2}; use pairing::{CurveAffine, CurveProjective, Engine, Field}; use rand::{ChaChaRng, OsRng, Rand, Rng, SeedableRng}; use tiny_keccak::sha3_256; @@ -795,8 +795,7 @@ mod tests { .unwrap_or_else(|_| panic!("Failed to create `SecretKeyShare` #{}", i)) .sign(msg); (i, sig) - }) - .collect(); + }).collect(); // Each of the shares is a valid signature matching its public key share. for (i, sig) in &sigs { @@ -816,8 +815,7 @@ mod tests { .unwrap_or_else(|_| panic!("Failed to create `SecretKeyShare` #{}", i)) .sign(msg); (i, sig) - }) - .collect(); + }).collect(); let sig2 = pk_set.combine_signatures(&sigs2).expect("signatures match"); assert_eq!(sig, sig2); } @@ -864,8 +862,7 @@ mod tests { .decrypt_share(&ciphertext) .expect("ciphertext is valid"); (i, dec_share) - }) - .collect(); + }).collect(); // Each of the shares is valid matching its public key share. for (i, share) in &shares { diff --git a/src/poly.rs b/src/poly.rs index f986f0c..49d0608 100644 --- a/src/poly.rs +++ b/src/poly.rs @@ -24,7 +24,7 @@ use std::{cmp, iter, ops}; use errno::errno; use memsec::{memzero, mlock, munlock}; -use pairing::bls12_381::{Fr, G1, G1Affine}; +use pairing::bls12_381::{Fr, G1Affine, G1}; use pairing::{CurveAffine, CurveProjective, Field}; use rand::Rng; @@ -221,8 +221,7 @@ impl<'a, B: Borrow> ops::Mul for &'a Poly { c.add_assign(&s); } c - }) - .collect(); + }).collect(); match Poly::new(coeff) { Ok(poly) => poly, @@ -803,8 +802,7 @@ impl BivarPoly { result.add_assign(&summand); } result - }) - .collect(); + }).collect(); Poly::new(coeff) } @@ -887,8 +885,7 @@ impl BivarCommitment { result.add_assign(&summand); } result - }) - .collect(); + }).collect(); Commitment { coeff } } @@ -906,8 +903,7 @@ fn powers(into_x: T, degree: usize) -> Vec { .chain((0..degree).map(|_| { x_pow_i.mul_assign(&x); x_pow_i - })) - .collect() + })).collect() } /// Returns the position of coefficient `(i, j)` in the vector describing a symmetric bivariate @@ -977,8 +973,7 @@ mod tests { .map(|_| { BivarPoly::random(faulty_num, &mut rng) .expect("Failed to create random `BivarPoly`") - }) - .collect(); + }).collect(); let pub_bi_commits: Vec<_> = bi_polys.iter().map(BivarPoly::commitment).collect(); let mut sec_keys = vec![Fr::zero(); node_num];