Commit Graph

75 Commits

Author SHA1 Message Date
Andreas Fackler d52be00d0e Fix CI.
Fix a few new Clippy lints, and some broken dependencies.
2020-03-20 10:37:31 +01:00
Andreas Fackler d15467eb09 Remove NetworkInfo from Broadcast. 2019-08-27 20:51:24 +02:00
Andreas Fackler 15f7313706 Extract test framework into hbbft_testing crate. (#404)
* Extract test framework into hbbft_testing crate.

Also update Rust and some dependencies.

* Rename DHB tests.

They are only called `net_dynamic_hb` because we used to have two test
frameworks and two DHB test modules.
2019-04-26 15:54:11 +01:00
David Forstenlechner c1e634ecf2 Ported more integration tests to the new net simulator (#387)
* Ported threshold_sign test to the new framework

* Ported the first three broadcast tests to the new framework

* Extracted messages storting and random swapping to reusable functions

Used to compose ProposeAdversary's behavior without having to duplicate code

* Implemented ProposeAdversary for the new integration testing framework

Added "id()" function to the "NodeMutHandle", required for sending messages to all nodes

ProposeAdversary needs access to all faulty node's netinfo. We follow the example of the binary_agreement_mitm integration test of using an reference counted Mutex to make netinfo available on both Consensus Protocol construction and in the Adversary implementation.
Unlike binary_agreement_mitm every faulty node needs to use its own netinfo for the broadcast algorithm, so we store all nodeinfo structures in a Map instead of just the nodeinfo of the first node.
Ideallly the new network simulation library should provide netinfo similar to the old library to avoid these hideous workarounds.

* Migrated test_broadcast_random_delivery_adv_propose to the new network simulator

Refactored the implementation of ProposeAdversary to closely resemble the behavior in the old network simulator library.
Implemented a pick_random_node function to sort messages for a random node id. Switched from using "inject_message" to joining messages generated by adversaries' temporary Broadcast Consensus Protocols with the Step generated by regular operation.

* Ported RandomAdversary to the new network simulator library

Ported all broadcast integration tests and replaced the old tests with the new.

* Eliminated the old broadcast integration test, replaced with the new

* Ported subset test to the new framework

Adjusted message queue size as suggested by Andreas

* Ported the first three honey_badger tests to the new framework

* Re-implemented FaultyShareAdversary for the new framework

Eliminated the old honey_badger integration tests, replaced with implementations using the new net simulator framework

* Fixed issues reported by clippy

* Fixed issues reported on code review

* Fixed issues reported by clippy

* Implemented a broadcast test dropping messages similar to the tests written in the old framework

* Picking the proposer id at random, verifying all possible output cases

If the proposer is faulty the message queue may starve, but the outputs of all correct nodes need to be empty, if the broadcast protocol produces output nonetheless all correct nodes need to have the same output.
If the proposer was correct all correct nodes need to output its proposed value.

* Eliminated duplicated semicolon

* Consistently using TestRng and proptest in all newly ported tests

* Increased the drop_and_re_add test message limit to 20k per node

* Removed unnecessary closure

* Increased the tolerance for deviations from the expected value range to eliminate random test failures
2019-03-14 13:41:23 +00:00
Andreas Fackler 87b1d45d97 Rename DistAlgorithm to ConsensusProtocol. 2019-01-08 14:14:34 +01:00
Marc Brinkmann eafa77d5fc OsRng / external RNG Refactoring (#357)
* Use `OsRng` in place of `thread_rng`.

This changes the defaults of any builder by instantiating an `OsRng` instead of
a `thread_rng`, the former being much more secure than the latter.

Additionally, all the unit tests that still instantiate RNGs manually used `OsRng`s
as well; while there is no actual need for this level of security in tests, the performance overhead is very small and random number generation complexity has such a small impact on these tests that the convenience of being able to ban `thread_rng` from the codebase altogether, setting a good example and avoid issues when refactoring later greatly outweigh the negatives.

* Instead of storing random number generators in the various consensus algorithm instances, pass them in from the outside whenever they are needed.

This changes a large amount of interfaces (and in this commit is only partially done, since `DistAlgorithm` needs to be fundamentally altered as well.

It also obsoletes parts of the `util` module.

* Added an `R: Rng` type parameter to both methods of `DistAlgorithm`, forcing callers to pass in their own Rngs.

* Fixed documentation grammar and spelling in some of the altered interfaces due to RNG refactoring.

* Move `rng` argument to the end of the argument for most functions.

Also includes a reformatting due to Rust 1.30.

* Updated tests, accomodate `rng`-API changes.

* Fixed remaining compilation issues with new RNG code.

* Fix illegal `self` import outside curly braces.

* Cleaned up comments and fixed broken definition of `broadcast_input`.

* Updated existing test cases to properly work with static dispatch randomness.

* Do not use boxed `Rng`s for key generation in test networks.

* Use the passed-in `Rng` in `ReorderingAdversary`, instead of storing a boxed one.

* Fixed clippy lints after refactoring.

* Removed some no-longer necessary manual `fmt::Debug` implementations in test framework.

* Use `OsRng` even in tests in `binary_agreement_mitm`.

* Use a proper deterministic RNG in tests `binary_agreement_mitm`.

* Refactor `examples/simulation.rs` by not using `ThreadRng`, passing generic `Rng` parameters throughout and using a type alias instead of a newtype as the `Transaction`.

* Remove `thread_rng` use from `examples/node.rs`.

* Explicitly construct `InternalContrib` in `DynamicHoneyBadger::propose`.

* Fixed typo in description of `DistAlgorithm` trait.
2018-12-14 12:51:09 +00:00
Demi Marie Obenour 7fb172cda2 Switch to 2018 edition idioms (#359)
* Switch to 2018 edition idioms

* Fix build with Rust 2018.

* Remove unnecessary cloning, make `max_faulty` const.

* Remove unneeded `extern crate` statements.
2018-12-11 14:44:36 +01:00
Andreas Fackler da3d50d1b0 Fix some TODOs, make key share in net info optional. 2018-11-29 12:45:39 +01:00
Andreas Fackler df36258715 Instead of macro_use, use use. 2018-10-30 08:11:03 +01:00
Andreas Fackler d9bac58bc8 Use the correct NetworkInfos in the broadcast ProposeAdversary. 2018-10-29 15:42:20 +01:00
Andreas Fackler 8d1361e6ae Split up messaging module. 2018-10-10 17:29:59 +02:00
Andreas Fackler 7002dad54c Remove unused pairing import.
Also use the new `Iterator::flatten`.
2018-10-09 11:53:20 +02:00
Marc Brinkmann d2627272fe
Better proptest persistence through deterministic randomness. (#248)
* Add support for RNG instantiation in proptests.

* Use `proptest` module strategy to create the rng for `net_dynamic_honey_badger`.

* Use seed generation instead of RNG instantiation in tests.

* Remove fixed RNG in `generate_map`.

* `VirtualNet` now supports setting the random generator through the builder.

* Add missing `time_limit` field to `::std::fmt::Debug` trait implementation on `NetBuilder`.

* Pass an instantiated random number generator through `NewNodeInfo` as a convenience.

* Make the random number generator of `DynamicHoneyBadgerBuilder` configurable, at the cost of now requiring mutability to call `build_first_node()`.

* Ensure RNGs are derive from passed in seed in `net_dynamic_hb` tests.

* Correct inappropriate use of `random::Random` instead of `Rng::gen` to generate dependent values in `binary_agreement`.

The original implementation used `rand::random()`, which will always use the `thread_rng`, ignoring the fact that an RNG has actually been passed in.

* Do not use `OsRng` but passed in RNG instead.

* Use reference/non-reference passing of rngs more in line with the `rand` crates conventions.

* Document `rng` field on `DynamicHoneyBadger`.

* Make `SyncKeyGen` work with the extend (`encrypt_with_rng`) API of `threshold_crypto`.

* Use passed-in random number generator in `HoneyBadger`.

* Create `SubRng` crate in new `util` module to replace `create_rng()`.

* Use an RNG seeded from the configure RNG when reinitializing `DynamicHoneyBadger`.

* Use the correct branch of `threshold_crypto` with support for passing RNGs.
2018-10-02 16:24:51 +02:00
Andreas Fackler 7276621397 Rename uid to id. 2018-08-29 19:35:52 +02:00
Andreas Fackler f27eed4eef Rename input to handle_input.
Also update `.gitignore` to avoid checking in test logs.
2018-08-29 19:35:52 +02:00
DrPeterVanNostrand 8ab58d35d4 Added error handling for mlock errors in threshold_crypto crate. 2018-08-09 15:44:36 -04:00
Andreas Fackler 5cc7b54c06 Split up the broadcast module.
Also, rename broadcast and agreement messages to just `Message`.
2018-08-08 15:46:43 +02:00
Vladimir Komendantskiy 77ed1d50d4 separated crypto module into its own crate 2018-07-31 12:15:05 +01:00
Vladimir Komendantskiy 65b3097238 message queue refactoring WIP 2018-07-20 12:43:15 +01:00
Andreas Fackler 15cc6ffddd Separate keys and key shares. 2018-07-18 14:44:35 +02:00
Vladimir Komendantskiy 9979e790aa added must_use to tests and removed Clone from FaultLog 2018-07-16 14:31:21 +01:00
Vladimir Komendantskiy c6a0090859 removed cloning of FaultLog 2018-07-16 12:33:00 +01:00
Marc Brinkmann 5336fbe707 Added `RandomAdversary` and the necessary auxiliary functions.
Random adversaries are created for `broadcast` and `honey_badger`.  Random value generation was added for all type-dependencies of these algorithms, causing the `Rand` trait to be implement for a large portion of the codebase.

Additionally, `MessageWithSender` turned into an actual struct, making it much easier to handle. Tuple-like construction is still available through `MessageWithSender::new()`.
2018-07-13 13:27:49 +02:00
Marc Brinkmann 510c4478d4 Ensure the adversary is playing fair and give a more helpful error message if they are not. 2018-07-13 13:27:49 +02:00
c0gent f0ed2e6e12 Make `*HoneyBadger` types thread safe.
Replaces `Rc` with `Arc`. This allows usage from different threads
which will be necessary for use with Parity.
2018-07-11 16:28:41 -07:00
Andreas Fackler 2a5f9f1bfe Allow observer nodes in all algorithms.
This allows nodes to join the network without sending any messages
themselves. They can't give any input and just observe the outcome.

Closes #81
2018-06-26 09:17:12 +02:00
Andreas Fackler b3b3994ec1
Merge pull request #82 from poanetwork/vk-test-decryption-shares
An adversary sending faulty decryption shares
2018-06-26 09:06:33 +02:00
Vladimir Komendantskiy 11ec39879b created an adversary to test against faulty decryption shares 2018-06-25 19:22:08 +01:00
Andreas Fackler 062b35ab3a Make SyncKeyGen NodeUid-aware.
This allows the caller to address nodes by ID instead of by index.

Also contains a few other minor changes that will be needed for
`DynamicHoneyBadger`.
2018-06-25 13:07:31 +02:00
Andreas Fackler e11f183db2 Remove generic E: Engine from crypto. 2018-06-22 10:08:23 +02:00
Vladimir Komendantskiy b82ac64148 note in the broadcast example about the use of keys 2018-06-13 18:24:35 +01:00
Vladimir Komendantskiy 122f1fc6f1 updated the tests with key initialisation 2018-06-13 15:15:41 +01:00
Vladimir Komendantskiy d09f3e26b4 introduced common shared network information 2018-05-29 14:53:01 +01:00
Andreas Fackler 9a0622f3f2 Update Rust, re-enable rustfmt. 2018-05-21 11:26:42 +02:00
Andreas Fackler b8a2463d1c Extend tests and fix CommonSubset.
Verify termination and more outputs.

`CommonSubset` now instantiates `Agreement` with the correct ID.
2018-05-19 15:56:49 +02:00
Andreas Fackler d5f9c4d40d Fix Agreement and re-enable HoneyBadger test. 2018-05-17 17:38:45 +02:00
Andreas Fackler 4164af1702 Generalize TestNetwork and test HoneyBadger. 2018-05-16 16:21:30 +02:00
Andreas Fackler b8c534da2b Rename has_output to decided, add output iterator. 2018-05-15 16:05:55 +02:00
Andreas Fackler 3895949cf6 Fix broadcast for size < 4, and test more network sizes. 2018-05-15 15:53:37 +02:00
Andreas Fackler 5528fc2de8 Define a common DistAlgorithm trait.
This will allow us to deduplicate network simulations in tests for the
different algorithms. More generally, it facilitates writing general
tools and applying them to all distributed algorithms.
2018-05-15 15:48:43 +02:00
Vladimir Komendantskiy a20ee74254 added a test for Binary Agreement with 4 proposers 2018-05-14 12:35:28 +01:00
Andreas Fackler 71fa32c18f Remove interior mutability.
The `RwLock` is not needed anymore, since the broadcast implementation
doesn't handle any threading internally.
2018-05-14 09:35:34 +02:00
Andreas Fackler 38cdd596a2 Start implementing the top-level Honey Badger algorithm.
This also contains a few fixes for the `common_subset` module:
* Rename `common_subset::Output` to `Message` to avoid confusing it
  with the value that the algorithm outputs as a result.
* Implement dispatch of messages to the right instance within
  `CommonSubset`, in a way that is transparent to the user.
2018-05-12 16:09:07 +02:00
Andreas Fackler 36183b1e27 Simplify the message types. 2018-05-10 17:52:12 +02:00
Andreas Fackler b98bbe9dcd Fix broadcast and example, enable more tests.
This fixes several issues with the broadcast algorithm and enables the
previously ignored tests that now pass:
* Don't decide on a root hash based on anyone's `Echo` message.
* Work around the `merkle` crate's inability to produce the proof of the
  `i`-th leaf for a given index `i`.
* Ignore messages from unknown nodes.
* Avoid decoding multiple times.
* Document the full algorithm.
* Don't count multiple `Echo` or `Ready` messages coming from the same
  node.
* Fix index computation for a given proof.
* Move `BroadcastMessage` into `broadcast` to make the module more
  self-contained.

The example now only executes a single broadcast instance, expecting the
first node (the one with the lexicographically lowest address) to
propose a value. A shell script is added that runs for example nodes.

Use env_logger instead of simple_logger, so the log level can be controlled
with an environment variable. You can e.g. log all output from the broadcast
test and the crate itself in debug mode with:
RUST_LOG=hbbft=debug,broadcast=debug

Some debugging messages are more concise now and use hexadecimal
notation instead of printing arrays of decimal values.

An indentation error in the Travis script is also fixed.
2018-05-08 17:04:38 +02:00
Andreas Fackler eec3102cbf Move node to examples, deduplicate code. 2018-05-05 17:54:29 +02:00
Andreas Fackler e2cd4ca1b7 added (ignored) regression tests for some of the broadcast issues 2018-05-04 11:14:19 +02:00
Andreas Fackler 8bced81438 removed some unnecessary cloning
This also adds a few TODOs to the broadcast implementation: Some of
these issues need a regression test. (Oh, and a fix!)
2018-05-04 09:58:21 +02:00
Andreas Fackler babbd2f36a fixed broadcast failure with malicious value proposal 2018-05-03 11:07:37 +03:00
Andreas Fackler 0f3377c8e9 made broadcast handle its own echo and value messages 2018-05-03 08:47:31 +03:00