Skip to content

Commit aa31261

Browse files
authored
Merge pull request #616 from input-output-hk/mithril-stm-readme
STM Readme update
2 parents 0cd0451 + 53e52c9 commit aa31261

File tree

4 files changed

+81
-50
lines changed

4 files changed

+81
-50
lines changed

mithril-stm/README.md

Lines changed: 77 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,70 @@
1-
Mithril-stm ![CI workflow](https://github.com/input-output-hk/mithril/actions/workflows/ci.yml/badge.svg) ![crates.io](https://img.shields.io/crates/v/mithril_stm.svg)
2-
=======
3-
This crate is ongoing work, has not been audited, and it's API is by no means final. Do not use in production.
1+
# Mithril-stm ![CI workflow](https://github.com/input-output-hk/mithril/actions/workflows/ci.yml/badge.svg) ![crates.io](https://img.shields.io/crates/v/mithril_stm.svg)
42

5-
### A rust implementation of Stake-based Threshold Multisignatures (STMs)
6-
`mithril-stm` implements Stake-based Threshold Multisignatures as described in the paper
7-
[Mithril: Stake-based Threshold Multisignatures](https://eprint.iacr.org/2021/916.pdf), by
8-
Pyrros Chaidos and Aggelos Kiayias.
93

10-
This library uses zkcrypto's implementation of curve [BLS12-381](https://github.com/zkcrypto/bls12_381)
11-
by default for implementing the multisignature scheme. One can optionally choose the
12-
[blst](https://github.com/supranational/blst) backend (by using the feature `blast`),
13-
but this is not recommended due to some [flaky tests](https://github.com/input-output-hk/mithril/issues/207)
14-
That are still being resolved. We
15-
currently only support the trivial concatenation proof system (Section 4.3) and do not support
16-
other proof systems such as Bulletproofs or Halo2.
4+
**This is a work in progress** :hammer_and_wrench:s
175

18-
This library provides implementations of:
6+
* `mithril-stm` is a Rust implementation of the scheme described in the paper [Mithril: Stake-based Threshold Multisignatures](https://eprint.iacr.org/2021/916.pdf) by Pyrros Chaidos and Aggelos Kiayias.
7+
* The BLS12-381 signature library [blst](https://github.com/supranational/blst) is used as the backend for the implementation of STM.
8+
* This implementation supports the _trivial concatenation proof system_ (Section 4.3). Other proof systems such as _Bulletproofs_ or _Halo2_ are not supported in this version.
9+
* We implemented the concatenation proof system as batch proofs:
10+
* Individual signatures do not contain the Merkle path to prove membership of the avk. Instead, it is the role of the aggregator to generate such proofs. This allows for a more efficient implementation of batched membership proofs (or batched Merkle paths).
11+
* Protocol documentation is given in [Mithril Protocol in depth](https://mithril.network/doc/mithril/mithril-protocol/protocol/).
1912

20-
* Stake-based Threshold Multisignatures
21-
* Key registration procedure for STM signatures
2213

23-
The user-facing documentation for the above modules can be found [here]().
14+
* This library provides:
15+
* The implementation of the Stake-based Threshold Multisignatures
16+
* Key registration procedure for STM signatures
17+
* The tests for the library functions and STM scheme
18+
* Benchmark tests
19+
20+
## Pre-requisites
21+
22+
**Install Rust**
23+
24+
* Install a [correctly configured](https://www.rust-lang.org/learn/get-started) Rust toolchain (latest stable version).
25+
26+
## Download source code
27+
28+
```bash
29+
# Download sources from github
30+
git clone https://github.com/input-output-hk/mithril
31+
32+
# Go to sources directory
33+
cd mithril-stm
34+
```
35+
36+
## Compiling the library
37+
```shell
38+
cargo build --release
39+
```
40+
41+
## Running the tests
42+
For running rust tests, simply run (to run the tests faster, the use of `--release` flag is recommended):
43+
```shell
44+
cargo test --release
45+
```
46+
47+
## Running the benches
48+
```shell
49+
cargo bench
50+
```
51+
52+
53+
## Example
54+
55+
The following is a simple example of the STM implementation:
2456

25-
# Example
2657
```rust
2758
use mithril_stm::key_reg::KeyReg;
2859
use mithril_stm::stm::{StmClerk, StmInitializer, StmParameters, StmSig, StmSigner};
29-
use rayon::prelude::*;
60+
use mithril_stm::AggregationError;
3061

31-
use mithril_stm::error::AggregationFailure;
62+
use blake2::{digest::consts::U32, Blake2b};
63+
use rayon::prelude::*;
3264
use rand_chacha::ChaCha20Rng;
3365
use rand_core::{RngCore, SeedableRng};
3466

35-
type H = blake2::Blake2b;
67+
type H = Blake2b<U32>;
3668

3769
fn main() {
3870
let nparties = 32;
@@ -68,7 +100,7 @@ fn main() {
68100

69101
let ps = ps
70102
.into_par_iter()
71-
.map(|p| p.new_signer(closed_reg.clone()))
103+
.map(|p| p.new_signer(closed_reg.clone()).unwrap())
72104
.collect::<Vec<StmSigner<H>>>();
73105

74106
/////////////////////
@@ -78,7 +110,7 @@ fn main() {
78110
let sigs = ps
79111
.par_iter()
80112
.filter_map(|p| p.sign(&msg))
81-
.collect::<Vec<StmSig<H>>>();
113+
.collect::<Vec<StmSig>>();
82114

83115
let clerk = StmClerk::from_signer(&ps[0]);
84116
let avk = clerk.compute_avk();
@@ -91,50 +123,56 @@ fn main() {
91123
// Aggregate with random parties
92124
let msig = clerk.aggregate(&sigs, &msg);
93125

94-
assert!(msig.is_ok(), "aggregation failed");
95-
assert!(msig.unwrap().verify(&msg, &clerk.compute_avk(), &params).is_ok());
126+
match msig {
127+
Ok(aggr) => {
128+
println!("Aggregate ok");
129+
assert!(aggr.verify(&msg, &clerk.compute_avk(), &params).is_ok());
130+
}
131+
Err(AggregationError::NotEnoughSignatures(n, k)) => {
132+
println!("Not enough signatures");
133+
assert!(n < params.k && k == params.k)
134+
}
135+
Err(AggregationError::UsizeConversionInvalid) => {
136+
println!("Invalid usize conversion");
137+
}
138+
}
96139
}
97140
```
98141

99-
# Test and Benchmarks
100-
You can run tests of the library using `cargo test` (we recommend to use the `--release` flag, otherwise
101-
the tests might take a while) and run benchmarks using `cargo bench`. This crate uses `criterion` to run
102-
benchmarks.
142+
## Benchmarks
103143

104-
We have run the benchmarks on an Apple M1 Pro machine with 16 GB of RAM, on macOS 12.6.
144+
Here we give the benchmark results of STM for size and time. We run the benchmarks on macOS 12.6 on an Apple M1 Pro machine with 16 GB of RAM.
105145

106-
Note that single signatures in batch compat version does not depend on any variable and size of an individual signature is `176` bytes.
146+
Note that the size of an individual signature with one valid index is **176 bytes** and increases linearly in the length of valid indices (where an index is 8 bytes).
107147

108148
```shell
109149
+----------------------+
110150
| Size of benchmarks |
111151
+----------------------+
112-
| Results obtained by using the parameters suggested in paper.
152+
| Results obtained by using the parameters suggested by the paper.
113153
+----------------------+
114154
+----------------------+
115155
| Aggregate signatures |
116156
+----------------------+
117157
+----------------------+
118158
| Hash: Blake2b 512 |
119159
+----------------------+
120-
k = 445 | m = 2728 | nr parties = 3000; 118760 bytes (old version = 356632 bytes)
160+
k = 445 | m = 2728 | nr parties = 3000; 118760 bytes
121161
+----------------------+
122162
| Hash: Blake2b 256 |
123163
+----------------------+
124-
k = 445 | m = 2728 | nr parties = 3000; 99384 bytes (old version = 222536 bytes)
164+
k = 445 | m = 2728 | nr parties = 3000; 99384 bytes
125165
+----------------------+
126166
+----------------------+
127167
| Aggregate signatures |
128168
+----------------------+
129169
| Hash: Blake2b 512 |
130170
+----------------------+
131-
k = 554 | m = 3597 | nr parties = 3000; 133936 bytes (old version = 419808 bytes)
171+
k = 554 | m = 3597 | nr parties = 3000; 133936 bytes
132172
+----------------------+
133173
| Hash: Blake2b 256 |
134174
+----------------------+
135-
k = 554 | m = 3597 | nr parties = 3000; 113728 bytes (old version = 261488 bytes)
136-
make build && ./mithrildemo --nparties 16 -k 5 -m 5 --phi-f 0.9
137-
175+
k = 554 | m = 3597 | nr parties = 3000; 113728 bytes
138176
```
139177

140178
```shell
@@ -155,7 +193,4 @@ STM/Blake2b/Aggregation/k: 250, m: 1523, nr_parties: 2000
155193
time: [190.81 ms 191.15 ms 191.54 ms]
156194
STM/Blake2b/Verification/k: 250, m: 1523, nr_parties: 2000
157195
time: [13.944 ms 14.010 ms 14.077 ms]
158-
159-
160196
```
161-

mithril-stm/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![warn(missing_docs)]
2+
#![doc = include_str!("../README.md")]
23
//! Implementation of Stake-based Threshold Multisignatures
34
45
mod dense_mapping;

mithril-stm/src/multi_sig.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
//! Base multisignature scheme, used as a primitive for STM.
22
//! See Section 2.4 of [the paper](https://eprint.iacr.org/2021/916).
3-
//! This module uses the `blst` library as a backend for pairings
4-
//! and can be activated by using the feature `blast`. This feature
5-
//! is not chosen by default due to some flaky tests, as exposed in the
6-
//! [issue](https://github.com/input-output-hk/mithril/issues/207)
3+
//! This module uses the `blst` library as a backend for pairings.
74
85
use crate::error::{blst_err_to_atms, MultiSignatureError};
96
use crate::stm::Index;

mithril-stm/tests/integration.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
use blake2::{digest::consts::U32, Blake2b};
2-
31
use mithril_stm::key_reg::KeyReg;
42
use mithril_stm::stm::{StmClerk, StmInitializer, StmParameters, StmSig, StmSigner};
53
use mithril_stm::AggregationError;
64

7-
use rayon::prelude::*;
8-
5+
use blake2::{digest::consts::U32, Blake2b};
96
use rand_chacha::ChaCha20Rng;
107
use rand_core::{RngCore, SeedableRng};
8+
use rayon::prelude::*;
119

1210
type H = Blake2b<U32>;
1311

0 commit comments

Comments
 (0)