moved BitIterator to threshold_crypto; updated tests

This commit is contained in:
Vladimir Komendantskiy 2018-11-16 19:17:09 +00:00
parent 806580f590
commit 2e5a8e429c
5 changed files with 10 additions and 44 deletions

View File

@ -33,7 +33,8 @@ rand_derive = "0.3.1"
reed-solomon-erasure = "3.1.0"
serde = "1.0.55"
serde_derive = "1.0.55"
threshold_crypto = "0.2.1"
# threshold_crypto = "0.2.1"
threshold_crypto = { git = "https://github.com/poanetwork/threshold_crypto", branch = "vk-bit-iterator" }
tiny-keccak = "1.4"
[dev-dependencies]

View File

@ -6,7 +6,6 @@ use crypto::Signature;
use derivative::Derivative;
use hex_fmt::HexFmt;
use log::debug;
use pairing::{bls12_381::G2Compressed, EncodedPoint};
use serde_derive::Serialize;
use super::proposal_state::{ProposalState, Step as ProposalStep};
@ -14,39 +13,6 @@ use super::{Error, Message, MessageContent, Result};
use rand::Rand;
use {util, DistAlgorithm, NetworkInfo, NodeIdT, SessionIdT};
#[derive(Debug, Clone)]
/// An iterator of bits in finite sequential data.
pub struct BitIterator<E> {
/// Data for iterating over.
t: E,
/// The number of remaining bits until the end.
n: usize,
}
impl<E: AsRef<[u8]>> BitIterator<E> {
/// Creates a new iterator for the given data and sets the number of remaining bits.
pub fn new(t: E) -> Self {
let n = t.as_ref().len() * 8;
BitIterator { t, n }
}
}
// FIXME: tests!
impl<E: AsRef<[u8]>> Iterator for BitIterator<E> {
type Item = bool;
fn next(&mut self) -> Option<bool> {
if self.n == 0 {
None
} else {
self.n -= 1;
let part = self.n / 8;
let bit = self.n - (8 * part);
Some(self.t.as_ref()[part] & (1 << bit) > 0)
}
}
}
pub type Step<N> = ::Step<Message<N>, SubsetOutput<N>, N>;
#[derive(Derivative, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
@ -163,11 +129,8 @@ impl<N: NodeIdT + Rand, S: SessionIdT> Subset<N, S> {
///
/// When common coins are derived this way, no session common coins are required, thus saving
/// additional threshold signature message rounds.
pub fn set_random_value(&mut self, _random_value: &Signature) -> Result<Step<N>> {
// FIXME: Use `random_value`. For that there has to be access to the `G2` field of
// `Signature`. Remove the dummy value.
let dummy_fixed_value = G2Compressed::empty();
let bits: BitIterator<G2Compressed> = BitIterator::new(dummy_fixed_value);
pub fn set_random_value(&mut self, random_value: &Signature) -> Result<Step<N>> {
let bits = random_value.bit_iter();
let mut step = Step::default();
for (b, (proposer_id, ps)) in bits.cycle().zip(&mut self.proposal_states) {
step.extend(Self::convert_step(&proposer_id, ps.set_coin(b)?));

View File

@ -83,7 +83,7 @@ where
);
let adversary = |_| new_adversary(num_good_nodes, num_faulty_nodes);
let new_ba = |netinfo: Arc<NetworkInfo<NodeId>>| {
BinaryAgreement::new(netinfo, 0).expect("Binary Agreement instance")
BinaryAgreement::new(netinfo, 0, false).expect("Binary Agreement instance")
};
let network = TestNetwork::new(num_good_nodes, num_faulty_nodes, adversary, new_ba);
test_binary_agreement(network, input);

View File

@ -447,7 +447,8 @@ fn reordering_attack() {
if info.id == 0 {
*adversary_netinfo.lock().unwrap() = Some(netinfo.clone());
}
BinaryAgreement::new(netinfo, 0).expect("failed to create BinaryAgreement instance")
BinaryAgreement::new(netinfo, 0, false)
.expect("failed to create BinaryAgreement instance")
}).num_faulty(1)
.build()
.unwrap();

View File

@ -80,8 +80,9 @@ where
// This returns an error in all but the first test.
let _ = env_logger::try_init();
let new_subset =
|netinfo: Arc<NetworkInfo<NodeId>>| Subset::new(netinfo, 0).expect("new Subset instance");
let new_subset = |netinfo: Arc<NetworkInfo<NodeId>>| {
Subset::new(netinfo, 0, false).expect("new Subset instance")
};
TestNetwork::new(good_num, bad_num, adversary, new_subset)
}