fedimint_hbbft/
lib.rs

1//! # Honey Badger BFT
2//!
3//! An implementation of [The Honey Badger of BFT Protocols](https://eprint.iacr.org/2016/199.pdf),
4//! an asynchronous, Byzantine fault tolerant consensus algorithm.
5//!
6//!
7//! ## Consensus
8//!
9//! A consensus algorithm is a protocol that helps a number of nodes agree on some data value.
10//! Byzantine fault tolerant systems can tolerate a number of faulty nodes _f_ (broken, or even
11//! controlled by an attacker), as long as the total number of nodes _N_ is greater than _3 f_.
12//! Asynchronous protocols do not make assumptions about timing: Even if an adversary controls
13//! network scheduling and can delay message delivery, consensus will still be reached as long as
14//! all messages are _eventually_ delivered.
15//!
16//! The Honey Badger consensus algorithm is both Byzantine fault tolerant and asynchronous. It is
17//! also modular, and the subalgorithms it is composed of are exposed in this crate as well, and
18//! usable separately.
19//!
20//! Consensus algorithms are fundamental to resilient, distributed systems such as decentralized
21//! databases and blockchains.
22//!
23//!
24//! ## Usage
25//!
26//! `hbbft` is meant to solve the consensus problem in a distributed application. Participating
27//! nodes provide input to the algorithm and are guaranteed to eventually produce the same output,
28//! after passing several messages back and forth.
29//!
30//! The crate only implements the abstract protocols, it is the application's responsibility to
31//! serialize, sign and send the messages. The application is required to call `handle_message` for
32//! every correctly signed message from a peer. Methods return a [Step](struct.Step.html) data
33//! structure, which contain messages that need to be sent, fault logs indicating misbehaving
34//! peers, and outputs.
35//!
36//! The network must contain a number of nodes that are known to each other by some unique
37//! identifiers (IDs), which is a generic type argument to the algorithms. Where applicable, the
38//! type of the input and output is also generic.
39//!
40//!
41//! ## Algorithms
42//!
43//! Honey Badger is modular, and composed of several algorithms that can also be used independently.
44//!
45//! [**Honey Badger**](honey_badger/index.html)
46//!
47//! The nodes repeatedly input _contributions_ (any user-defined type) and output a sequence of
48//! _batches_. The batches have sequential numbers (_epochs_) and contain one contribution
49//! from at least _N - f_ nodes. The sequence and contents of the batches will be the same in all
50//! nodes.
51//!
52//! [**Dynamic Honey Badger**](dynamic_honey_badger/index.html)
53//!
54//! A modified Honey Badger where validators can dynamically add and remove others to/from the
55//! network. In addition to the transactions, they can input `Add` and `Remove` requests. The
56//! output batches contain information about validator changes.
57//!
58//! [**Queueing Honey Badger**](queueing_honey_badger/index.html)
59//!
60//! A modified Dynamic Honey Badger that has a built-in transaction queue. The nodes input any
61//! number of _transactions_, and output a sequence of batches. Each batch contains a set of
62//! transactions that were input by the nodes, and usually multiple transactions from each node.
63//!
64//! [**Subset**](subset/index.html)
65//!
66//! Each node inputs one item. The output is a set of at least _N - f_ nodes' IDs, together with
67//! their items, and will be the same in every correct node.
68//!
69//! This is the main building block of Honey Badger: In each epoch, every node proposes a number of
70//! transactions. Using the Subset protocol, they agree on at least _N - f_ of those
71//! proposals. The batch contains the union of these sets of transactions.
72//!
73//! [**Broadcast**](broadcast/index.html)
74//!
75//! One node, the _proposer_, inputs an item, and every node receives that item as an output. Even
76//! if the proposer is faulty it is guaranteed that either none of the correct nodes output
77//! anything, or all of them have the same output.
78//!
79//! This is used in Subset to send each node's proposal to the other nodes.
80//!
81//! [**Binary Agreement**](binary_agreement/index.html)
82//!
83//! Each node inputs a binary value: `true` or `false`. As output, either all correct nodes receive
84//! `true` or all correct nodes receive `false`. The output is guaranteed to be a value that was
85//! input by at least one _correct_ node.
86//!
87//! This is used in Subset to decide whether each node's proposal should be included in the subset
88//! or not.
89//!
90//! [**Threshold Sign**](threshold_sign/index.html)
91//!
92//! Each node inputs `()` to broadcast signature shares. Once _f + 1_ nodes have input, all nodes
93//! receive a valid signature. The outcome cannot be known by the adversary before at least one
94//! correct node has provided input, and can be used as a source of pseudorandomness.
95//!
96//! [**Threshold Decrypt**](threshold_decrypt/index.html)
97//!
98//! Each node inputs the same ciphertext, encrypted to the public master key. Once _f + 1_
99//! validators have received input, all nodes output the decrypted data.
100//!
101//! [**Synchronous Key Generation**](sync_key_gen/index.html)
102//!
103//! The participating nodes collaboratively generate a key set for threshold cryptography, such
104//! that each node learns its own secret key share, as well as everyone's public key share and the
105//! public master key. No single trusted dealer is involved and no node ever learns the secret
106//! master key or another node's secret key share.
107//!
108//! Unlike the other algorithms, this one is _not_ asynchronous: All nodes must handle the same
109//! messages, in the same order.
110//!
111//! ## Serialization
112//!
113//! `hbbft` supports [serde](https://serde.rs/): All message types implement the `Serialize` and
114//! `Deserialize` traits so they can be easily serialized or included as part of other serializable
115//! types.
116
117// We put algorithm structs in `src/algorithm/algorithm.rs`.
118// Some of our constructors return results.
119#![allow(clippy::module_inception, clippy::new_ret_no_self)]
120#![warn(missing_docs)]
121
122pub use threshold_crypto as crypto;
123
124mod fault_log;
125mod messaging;
126mod network_info;
127mod traits;
128
129pub mod binary_agreement;
130pub mod broadcast;
131pub mod dynamic_honey_badger;
132pub mod honey_badger;
133pub mod queueing_honey_badger;
134pub mod sender_queue;
135pub mod subset;
136pub mod sync_key_gen;
137pub mod threshold_decrypt;
138pub mod threshold_sign;
139pub mod transaction_queue;
140pub mod util;
141
142pub use crate::crypto::pairing;
143pub use crate::fault_log::{Fault, FaultLog};
144pub use crate::messaging::{SourcedMessage, Target, TargetedMessage};
145pub use crate::network_info::{NetworkInfo, ValidatorSet};
146pub use crate::sync_key_gen::{to_pub_keys, PubKeyMap};
147pub use crate::traits::{
148    ConsensusProtocol, Contribution, CpStep, Epoched, Message, NodeIdT, SessionIdT, Step,
149};