Skip to content

Commit

Permalink
Update to Rust beta channel.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbr committed Aug 31, 2018
1 parent 02109b5 commit a7cd6e0
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 45 deletions.
11 changes: 3 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions examples/threshold_enc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
Expand Down
34 changes: 17 additions & 17 deletions examples/threshold_sig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
11 changes: 4 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -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);
}
Expand Down Expand Up @@ -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 {
Expand Down
17 changes: 6 additions & 11 deletions src/poly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -221,8 +221,7 @@ impl<'a, B: Borrow<Poly>> ops::Mul<B> for &'a Poly {
c.add_assign(&s);
}
c
})
.collect();
}).collect();

match Poly::new(coeff) {
Ok(poly) => poly,
Expand Down Expand Up @@ -803,8 +802,7 @@ impl BivarPoly {
result.add_assign(&summand);
}
result
})
.collect();
}).collect();
Poly::new(coeff)
}

Expand Down Expand Up @@ -887,8 +885,7 @@ impl BivarCommitment {
result.add_assign(&summand);
}
result
})
.collect();
}).collect();
Commitment { coeff }
}

Expand All @@ -906,8 +903,7 @@ fn powers<T: IntoFr>(into_x: T, degree: usize) -> Vec<Fr> {
.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
Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit a7cd6e0

Please sign in to comment.