mirror of https://github.com/poanetwork/hbbft.git
Update crypto, add mock crypto for testing.
This commit is contained in:
parent
3af821dc88
commit
13b0b04943
|
@ -27,8 +27,9 @@ env:
|
|||
- RUSTFLAGS="-D warnings -C target-cpu=native"
|
||||
- MLOCK_SECRETS=false
|
||||
script:
|
||||
- cargo clippy --tests --examples -- --deny clippy
|
||||
- cargo clippy --all-targets -- --deny clippy
|
||||
- cargo clippy --all-features --all-targets -- --deny clippy
|
||||
- cargo fmt -- --check
|
||||
- cargo test --all-features --release -- --test-threads 1
|
||||
- cargo test --features=use-insecure-test-only-mock-crypto --release
|
||||
- cargo doc
|
||||
- cargo deadlinks --dir target/doc/hbbft/
|
||||
|
|
|
@ -25,13 +25,12 @@ failure = "0.1"
|
|||
hex_fmt = "0.1"
|
||||
init_with = "1.1.0"
|
||||
log = "0.4.1"
|
||||
pairing = { version = "0.14.2", features = ["u128-support"] }
|
||||
rand = "0.4.2"
|
||||
rand_derive = "0.3.1"
|
||||
reed-solomon-erasure = "3.1.0"
|
||||
serde = "1.0.55"
|
||||
serde_derive = "1.0.55"
|
||||
threshold_crypto = { git = "https://github.com/poanetwork/threshold_crypto", tag = "0.1.0-rng-fix" }
|
||||
threshold_crypto = { git = "https://github.com/poanetwork/threshold_crypto", tag = "0.2.0-beta" }
|
||||
tiny-keccak = "1.4"
|
||||
|
||||
[dev-dependencies]
|
||||
|
@ -60,3 +59,6 @@ name = "simulation"
|
|||
# `[profile.release]` block in both cases.
|
||||
[profile.bench]
|
||||
overflow-checks = true
|
||||
|
||||
[features]
|
||||
use-insecure-test-only-mock-crypto = ["threshold_crypto/use-insecure-test-only-mock-crypto"]
|
||||
|
|
|
@ -105,11 +105,8 @@ impl<T: Clone + Debug + AsRef<[u8]> + PartialEq + Send + Sync + From<Vec<u8>> +
|
|||
// required by the interface to all algorithms in Honey Badger. Therefore we set placeholder
|
||||
// keys here. A fully-featured application would need to take appropriately initialized keys
|
||||
// from elsewhere.
|
||||
let secret_key_set =
|
||||
SecretKeySet::from(Poly::zero().expect("Failed to create an empty `Poly`"));
|
||||
let sk_share = secret_key_set
|
||||
.secret_key_share(our_id)
|
||||
.expect("Failed to create our node's `SecretKeyShare`");
|
||||
let secret_key_set = SecretKeySet::from(Poly::zero());
|
||||
let sk_share = secret_key_set.secret_key_share(our_id);
|
||||
let pub_key_set = secret_key_set.public_keys();
|
||||
let sk = SecretKey::default();
|
||||
let pub_keys = all_ids
|
||||
|
|
|
@ -99,9 +99,9 @@ where
|
|||
|
||||
/// Creates a new `DynamicHoneyBadger` configured to start a new network as a single validator.
|
||||
pub fn build_first_node(&mut self, our_id: N) -> Result<DynamicHoneyBadger<C, N>> {
|
||||
let sk_set = SecretKeySet::random(0, &mut self.rng)?;
|
||||
let sk_set = SecretKeySet::random(0, &mut self.rng);
|
||||
let pk_set = sk_set.public_keys();
|
||||
let sks = sk_set.secret_key_share(0)?;
|
||||
let sks = sk_set.secret_key_share(0);
|
||||
let sk: SecretKey = self.rng.gen();
|
||||
let pub_keys = once((our_id.clone(), sk.public_key())).collect();
|
||||
let netinfo = NetworkInfo::new(our_id, sks, pk_set, sk, pub_keys);
|
||||
|
|
|
@ -126,7 +126,6 @@ extern crate hex_fmt;
|
|||
extern crate init_with;
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
extern crate pairing;
|
||||
extern crate rand;
|
||||
#[macro_use]
|
||||
extern crate rand_derive;
|
||||
|
@ -153,6 +152,7 @@ mod traits;
|
|||
pub mod transaction_queue;
|
||||
pub mod util;
|
||||
|
||||
pub use crypto::pairing;
|
||||
pub use messaging::{SourcedMessage, Target, TargetedMessage};
|
||||
pub use network_info::NetworkInfo;
|
||||
pub use traits::{Contribution, DistAlgorithm, Message, NodeIdT, Step};
|
||||
|
|
|
@ -158,7 +158,7 @@ impl<N: NodeIdT> NetworkInfo<N> {
|
|||
let num_faulty = (all_ids.len() - 1) / 3;
|
||||
|
||||
// Generate the keys for threshold cryptography.
|
||||
let sk_set = SecretKeySet::random(num_faulty, rng)?;
|
||||
let sk_set = SecretKeySet::random(num_faulty, rng);
|
||||
let pk_set = sk_set.public_keys();
|
||||
|
||||
// Generate keys for individually signing and encrypting messages.
|
||||
|
@ -173,7 +173,7 @@ impl<N: NodeIdT> NetworkInfo<N> {
|
|||
let create_netinfo = |(i, id): (usize, N)| {
|
||||
let netinfo = NetworkInfo::new(
|
||||
id.clone(),
|
||||
sk_set.secret_key_share(i)?,
|
||||
sk_set.secret_key_share(i),
|
||||
pk_set.clone(),
|
||||
sec_keys[&id].clone(),
|
||||
pub_keys.clone(),
|
||||
|
|
|
@ -170,7 +170,7 @@ use crypto::{
|
|||
serde_impl::field_vec::FieldWrap,
|
||||
Ciphertext, PublicKey, PublicKeySet, SecretKey, SecretKeyShare,
|
||||
};
|
||||
use pairing::bls12_381::{Fr, G1Affine};
|
||||
use crypto::{Fr, G1Affine};
|
||||
use pairing::{CurveAffine, Field};
|
||||
use rand;
|
||||
|
||||
|
@ -312,10 +312,10 @@ impl<N: NodeIdT> SyncKeyGen<N> {
|
|||
return Ok((key_gen, None)); // No part: we are an observer.
|
||||
}
|
||||
|
||||
let our_part = BivarPoly::random(threshold, rng).map_err(Error::Creation)?;
|
||||
let our_part = BivarPoly::random(threshold, rng);
|
||||
let commit = our_part.commitment();
|
||||
let encrypt = |(i, pk): (usize, &PublicKey)| {
|
||||
let row = our_part.row(i + 1).map_err(Error::Creation)?;
|
||||
let row = our_part.row(i + 1);
|
||||
let bytes = bincode::serialize(&row).expect("failed to serialize row");
|
||||
Ok(pk.encrypt_with_rng(rng, &bytes))
|
||||
};
|
||||
|
@ -425,19 +425,18 @@ impl<N: NodeIdT> SyncKeyGen<N> {
|
|||
/// All participating nodes must have handled the exact same sequence of `Part` and `Ack`
|
||||
/// messages before calling this method. Otherwise their key shares will not match.
|
||||
pub fn generate(&self) -> Result<(PublicKeySet, Option<SecretKeyShare>), Error> {
|
||||
let mut pk_commit = Poly::zero().map_err(Error::Generation)?.commitment();
|
||||
let mut pk_commit = Poly::zero().commitment();
|
||||
let mut opt_sk_val = self.our_idx.map(|_| Fr::zero());
|
||||
let is_complete = |part: &&ProposalState| part.is_complete(self.threshold);
|
||||
for part in self.parts.values().filter(is_complete) {
|
||||
pk_commit += part.commit.row(0);
|
||||
if let Some(sk_val) = opt_sk_val.as_mut() {
|
||||
let row = Poly::interpolate(part.values.iter().take(self.threshold + 1))
|
||||
.map_err(Error::Generation)?;
|
||||
let row = Poly::interpolate(part.values.iter().take(self.threshold + 1));
|
||||
sk_val.add_assign(&row.evaluate(0));
|
||||
}
|
||||
}
|
||||
let opt_sk = if let Some(mut fr) = opt_sk_val {
|
||||
let sk = SecretKeyShare::from_mut_ptr(&mut fr as *mut Fr).map_err(Error::Generation)?;
|
||||
let sk = SecretKeyShare::from_mut(&mut fr);
|
||||
Some(sk)
|
||||
} else {
|
||||
None
|
||||
|
|
Loading…
Reference in New Issue