Skip to content

Commit 019ed6a

Browse files
kigawasomershlo
authored andcommitted
Fix clippy warnings and format README (#71)
* Fix key_gen.rs clippy warnings and format README * Fix more clippy warnings and add .rustfmt.toml * Fix more clippy warnings * Improve test * Improve test * Shebang for demo/run.sh * Improve demo/run.sh * Fix readme table * Improve sm_manager.rs * Move demo to examples folder * Finish fix clippy warnings * Minor fix on keygen client * improve keygen client * usize t, n => u16 t, n * Switch to Rust 2018 * aes encrypt/decrypt wrapper * Update Readme * Refactor examples * Minor fix on keygen client * Move rust-crypto and hex to dev-dep * unify message traits in gg_2018 * 2018 bench * fix curv & paillier dep * temporarily disable travis cache * fix tests * disable travis cache due to getting stuck * test multi sig against secp256k1 * backup examples * update readme * fix cclst * default features false of rocket * fix bench * fix pk slice
1 parent fd92128 commit 019ed6a

File tree

29 files changed

+1583
-1837
lines changed

29 files changed

+1583
-1837
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ Cargo.lock
1111

1212
.idea
1313
.DS_Store
14+
15+
keys*.store
16+
signature
17+
params.json

.rustfmt.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
edition = "2018"

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
language: rust
2-
cache: cargo
2+
cache: false
33
rust:
44
- nightly
55

Cargo.toml

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[package]
22
name = "multi-party-ecdsa"
33
version = "0.2.4"
4+
edition = "2018"
45
authors = [
56
67
@@ -13,7 +14,8 @@ keywords = [
1314
"secret-shares",
1415
"blockchain",
1516
"cryptography",
16-
"cryptocurrency"]
17+
"cryptocurrency"
18+
]
1719

1820
homepage = "https://github.com/KZen-networks/multi-party-ecdsa"
1921
repository = "https://github.com/KZen-networks/multi-party-ecdsa"
@@ -23,18 +25,16 @@ categories = ["cryptography"]
2325
[lib]
2426
crate-type = ["lib"]
2527

26-
27-
[dependencies]
28-
paillier = { git = "https://github.com/KZen-networks/rust-paillier", tag = "v0.3.3" }
29-
zk-paillier = { git = "https://github.com/KZen-networks/zk-paillier", tag = "v0.2.4" }
30-
subtle = {version = "2", features = ["nightly"]}
31-
serde = "1.0"
32-
serde_derive = "1.0"
33-
zeroize = "0.10"
34-
3528
[features]
3629
cclst = ["class_group"]
3730

31+
[dependencies]
32+
paillier = { git = "https://github.com/KZen-networks/rust-paillier", tag = "v0.3.3"}
33+
zk-paillier = { git = "https://github.com/KZen-networks/zk-paillier", tag = "v0.2.4"}
34+
subtle = { version = "2", features = ["nightly"] }
35+
serde = { version = "1.0", features = ["derive"] }
36+
zeroize = "0.10.1"
37+
3838
[dependencies.curv]
3939
git = "https://github.com/KZen-networks/curv"
4040
tag = "v0.2.2"
@@ -49,36 +49,44 @@ git = "https://github.com/KZen-networks/class-groups"
4949
tag = "v0.1.5"
5050
optional = true
5151

52-
[dependencies.rocket]
53-
version = "0.4.2"
54-
default-features = false
55-
optional = true
56-
57-
52+
[dev-dependencies]
53+
criterion = "0.3"
54+
rust-crypto = "0.2"
55+
hex = "0.4"
56+
rocket = { version = "0.4.2", default-features = false }
57+
rocket_contrib = "0.4.2"
58+
reqwest = { version = "0.9", default-features = false }
59+
uuid = { version = "0.8", features = ["v4"] }
60+
serde_json = "1.0"
61+
libsecp256k1 = "0.3.2"
5862

5963
[patch.crates-io]
6064
rust-gmp = { version = "0.5.0", features = ["serde_support"], git = "https://github.com/KZen-networks/rust-gmp" }
6165

62-
[dev-dependencies]
63-
criterion = "0.2"
64-
hex = "0.3.2"
65-
rocket_contrib = {version = "0.4.2",default-features = false,features = ["json"]}
66-
rocket = {version = "0.4.2", default-features = false}
67-
reqwest = {version = "0.9.5", default-features = false}
68-
uuid = { version = "0.7", features = ["v4"] }
69-
rust-crypto = "^0.2"
70-
serde_json = "1.0"
71-
7266
[[example]]
7367
name = "sm_manager"
7468

69+
[[example]]
70+
name = "gg18_sign_client"
71+
7572
[[example]]
7673
name = "gg18_keygen_client"
7774

7875
[[example]]
79-
name = "gg18_sign_client"
76+
name = "common"
77+
crate-type = ["lib"]
8078

8179
[[bench]]
82-
name = "keygen"
80+
name = "cclst"
8381
path = "benches/two_party_ecdsa/cclst_2019/keygen.rs"
8482
harness = false
83+
84+
[[bench]]
85+
name = "gg18"
86+
path = "benches/multi_party_ecdsa/gg18/keygen.rs"
87+
harness = false
88+
89+
[[bench]]
90+
name = "lindel2017"
91+
path = "benches/two_party_ecdsa/lindell_2017/keygen.rs"
92+
harness = false

README.md

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,72 @@
1+
# Multi-party ECDSA
2+
13
[![Build Status](https://travis-ci.com/KZen-networks/multi-party-ecdsa.svg?branch=master)](https://travis-ci.com/KZen-networks/multi-party-ecdsa)
24
[![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
35

4-
Multi-party ECDSA
5-
=====================================
6-
76
This project is a Rust implementation of {t,n}-threshold ECDSA (elliptic curve digital signature algorithm).
87

98
Threshold ECDSA includes two protocols:
109

11-
* Key Generation for creating secret shares.
12-
* Signing for using the secret shares to generate a signature.
10+
- Key Generation for creating secret shares.
11+
- Signing for using the secret shares to generate a signature.
1312

14-
ECDSA is used extensively for crypto-currencies such as Bitcoin, Ethereum (secp256k1 curve), NEO (NIST P-256 curve) and much more.
13+
ECDSA is used extensively for crypto-currencies such as Bitcoin, Ethereum (secp256k1 curve), NEO (NIST P-256 curve) and much more.
1514
This library can be used to create MultiSig and ThresholdSig crypto wallet.
1615

17-
Project Status
18-
-------
19-
* The library supports **2P-ECDSA** based on Lindell's crypto 2017 paper [1]. Project [Gotham-city](https://github.com/KZen-networks/gotham-city) is a proof of concept for a full two-party Bitcoin wallet that uses this library. See benchmarks and white paper there.
16+
## Project Status
2017

21-
* The library supports Gennaro and Goldfeder CCS 2018 protocol [2] for **{t,n}-threshold ECDSA**.
18+
- The library supports **2P-ECDSA** based on Lindell's crypto 2017 paper [1]. Project [Gotham-city](https://github.com/KZen-networks/gotham-city) is a proof of concept for a full two-party Bitcoin wallet that uses this library. See benchmarks and white paper there.
2219

23-
* The library supports **2P-ECDSA** based on Castagnos et. al. crypto 2019 paper [3]. To Enable build with `--features=cclst`.
20+
- The library supports Gennaro and Goldfeder CCS 2018 protocol [2] for **{t,n}-threshold ECDSA**.
2421

25-
Run Demo
26-
-------
27-
The following steps are for setup, key generation with `n` parties and signing with `t+1` parties.
22+
- The library supports **2P-ECDSA** based on Castagnos et. al. crypto 2019 paper [3]. To Enable build with `--features=cclst`.
2823

29-
**Setup**
30-
1) We use shared state machine architecture (see [white city](https://github.com/KZen-networks/white-city)). The parameters `parties` and `threshold` can be configured by changing the file: `param`. a keygen will run with `parties` parties and signing will run with any subset of `threshold + 1` parties. `param` file should be located in the same path of the client softwares.
31-
2) Install [Rust](https://www.rust-lang.org/en-US/install.html),[Nightly Rust](https://doc.rust-lang.org/1.5.0/book/nightly-rust.html). Run `cargo build --release --examples` ( it will build into `/target/release/examples`)
32-
3) Run the shared state machine: `./sm_manager`. Currently configured to be in `127.0.0.1:8001`, this can be changed in `Rocket.toml` file. The `Rocket.toml` file should be in the same folder you run `sm_manager` from.
24+
## Run Demo
3325

34-
**KeyGen**
26+
The following steps are for setup, key generation with `n` parties and signing with `t+1` parties.
3527

36-
run `gg18_keygen_client` as follows: `./gg18_keygen_client http://127.0.0.1:8001 keys.store`. Replace IP and port with the ones configured in setup. Once `n` parties join the application will run till finish. At the end each party will get a local keys file `keys.store` (change filename in command line). This contain secret and public data of the party after keygen. The file therefore should remain private.
28+
### Setup
3729

38-
**Sign**
30+
1. We use shared state machine architecture (see [white city](https://github.com/KZen-networks/white-city)). The parameters `parties` and `threshold` can be configured by changing the file: `param`. a keygen will run with `parties` parties and signing will run with any subset of `threshold + 1` parties. `param` file should be located in the same path of the client softwares.
3931

40-
Run `./gg18_sign_client`. The application should be in the same folder as the `keys.store` file (or custom filename generated in keygen). the application takes three arguments: `IP:port` as in keygen, `filename` and message to be signed: `./gg18_sign_client http://127.0.0.1:8001 keys.store "KZen Networks"`. The same message should be used by all signers. Once `t+1` parties join the protocol will run and will output to screen signatue (R,s).
32+
2. Install [Rust](https://rustup.rs/). Run `cargo build --release --examples` (it will build into `/target/release/examples/`)
4133

42-
**Full demo**
34+
3. Run the shared state machine: `./sm_manager`. Currently configured to be in `127.0.0.1:8001`, this can be changed in `Rocket.toml` file. The `Rocket.toml` file should be in the same folder you run `sm_manager` from.
4335

44-
Run `./run.sh` (located in `/demo` folder) in the same folder as the excutables (usually `/target/release/examples`). It will spawn a shared state machine, clients in the number of parties and signing requests for the `threshold + 1` first parties.
36+
### KeyGen
37+
38+
run `gg18_keygen_client` as follows: `./gg18_keygen_client http://127.0.0.1:8001 keys.store`. Replace IP and port with the ones configured in setup. Once `n` parties join the application will run till finish. At the end each party will get a local keys file `keys.store` (change filename in command line). This contain secret and public data of the party after keygen. The file therefore should remain private.
39+
40+
### Sign
4541

42+
Run `./gg18_sign_client`. The application should be in the same folder as the `keys.store` file (or custom filename generated in keygen). the application takes three arguments: `IP:port` as in keygen, `filename` and message to be signed: `./gg18_sign_client http://127.0.0.1:8001 keys.store "KZen Networks"`. The same message should be used by all signers. Once `t+1` parties join the protocol will run and will output to screen signatue (R,s).
4643

44+
### Full demo
4745

48-
|![Demo](https://raw.githubusercontent.com/KZen-networks/multi-party-ecdsa/master/demo/MP-ECDSA%20demo.gif "Multiparty ECDSA Demo")|
49-
|:--:|
50-
| *A 5 parties setup with 3 signers (threshold = 2)* |
46+
Run `./run.sh` (located in `/demo` folder) in the same folder as the excutables (usually `/target/release/examples`). It will spawn a shared state machine, clients in the number of parties and signing requests for the `threshold + 1` first parties.
47+
48+
| !["Multiparty ECDSA Demo"][demo] |
49+
| :------------------------------------------------: |
50+
| _A 5 parties setup with 3 signers (threshold = 2)_ |
51+
52+
[demo]: https://raw.githubusercontent.com/KZen-networks/multi-party-ecdsa/master/demo/MP-ECDSA%20demo.gif
5153

54+
## Contributions & Development Process
5255

53-
Contributions & Development Process
54-
-------------------
5556
The contribution workflow is described in [CONTRIBUTING.md](CONTRIBUTING.md), in addition **the [Rust utilities wiki](https://github.com/KZen-networks/rust-utils/wiki) contains information on workflow and environment set-up**.
5657

57-
License
58-
-------
58+
## License
59+
5960
Multi-party ECDSA is released under the terms of the GPL-3.0 license. See [LICENSE](LICENSE) for more information.
6061

61-
Contact
62-
-------------------
63-
Feel free to [reach out](mailto:[email protected]) or join the KZen Research [Telegram]( https://t.me/kzen_research) for discussions on code and research.
62+
## Contact
63+
64+
Feel free to [reach out](mailto:[email protected]) or join the KZen Research [Telegram](https://t.me/kzen_research) for discussions on code and research.
6465

65-
References
66-
-------------------
66+
## References
6767

68-
[1] https://eprint.iacr.org/2017/552.pdf
68+
[1] <https://eprint.iacr.org/2017/552.pdf>
6969

70-
[2] https://eprint.iacr.org/2019/114.pdf
70+
[2] <https://eprint.iacr.org/2019/114.pdf>
7171

72-
[3] https://eprint.iacr.org/2019/503.pdf
72+
[3] <https://eprint.iacr.org/2019/503.pdf>

benches/multi_party_ecdsa/gg18/keygen.rs

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
#[macro_use]
2-
extern crate criterion;
3-
extern crate curv;
4-
extern crate multi_party_ecdsa;
1+
use criterion::criterion_main;
52

63
mod bench {
7-
use criterion::Criterion;
4+
use criterion::{criterion_group, Criterion};
85
use curv::cryptographic_primitives::secret_sharing::feldman_vss::VerifiableSS;
96
use curv::elliptic::curves::traits::*;
107
use curv::{FE, GE};
@@ -24,37 +21,35 @@ mod bench {
2421
});
2522
}
2623
pub fn keygen_t_n_parties(
27-
t: usize,
28-
n: usize,
24+
t: u16,
25+
n: u16,
2926
) -> (Vec<Keys>, Vec<SharedKeys>, Vec<GE>, GE, VerifiableSS) {
3027
let parames = Parameters {
3128
threshold: t,
32-
share_count: n.clone(),
29+
share_count: n,
3330
};
34-
let party_keys_vec = (0..n.clone())
35-
.map(|i| Keys::create(i))
36-
.collect::<Vec<Keys>>();
31+
let (t, n) = (t as usize, n as usize);
32+
let party_keys_vec = (0..n).map(Keys::create).collect::<Vec<Keys>>();
3733

3834
let mut bc1_vec = Vec::new();
3935
let mut decom_vec = Vec::new();
40-
for i in 0..n.clone() {
41-
let (bc1, decom1) = party_keys_vec[i].phase1_broadcast_phase3_proof_of_correct_key();
36+
37+
for key in &party_keys_vec {
38+
let (bc1, decom1) = key.phase1_broadcast_phase3_proof_of_correct_key();
4239
bc1_vec.push(bc1);
4340
decom_vec.push(decom1);
4441
}
4542

46-
let y_vec = (0..n.clone())
47-
.map(|i| decom_vec[i].y_i.clone())
48-
.collect::<Vec<GE>>();
43+
let y_vec = (0..n).map(|i| decom_vec[i].y_i).collect::<Vec<GE>>();
4944
let mut y_vec_iter = y_vec.iter();
5045
let head = y_vec_iter.next().unwrap();
5146
let tail = y_vec_iter;
5247
let y_sum = tail.fold(head.clone(), |acc, x| acc + x);
5348
let mut vss_scheme_vec = Vec::new();
5449
let mut secret_shares_vec = Vec::new();
5550
let mut index_vec = Vec::new();
56-
for i in 0..n.clone() {
57-
let (vss_scheme, secret_shares, index) = party_keys_vec[i]
51+
for key in &party_keys_vec {
52+
let (vss_scheme, secret_shares, index) = key
5853
.phase1_verify_com_phase3_verify_correct_key_phase2_distribute(
5954
&parames, &decom_vec, &bc1_vec,
6055
)
@@ -65,50 +60,44 @@ mod bench {
6560
}
6661
let vss_scheme_for_test = vss_scheme_vec.clone();
6762

68-
let party_shares = (0..n.clone())
63+
let party_shares = (0..n)
6964
.map(|i| {
70-
(0..n.clone())
65+
(0..n)
7166
.map(|j| {
7267
let vec_j = &secret_shares_vec[j];
73-
vec_j[i].clone()
68+
vec_j[i]
7469
})
7570
.collect::<Vec<FE>>()
7671
})
7772
.collect::<Vec<Vec<FE>>>();
7873

7974
let mut shared_keys_vec = Vec::new();
8075
let mut dlog_proof_vec = Vec::new();
81-
for i in 0..n.clone() {
76+
for i in 0..n {
8277
let (shared_keys, dlog_proof) = party_keys_vec[i]
8378
.phase2_verify_vss_construct_keypair_phase3_pok_dlog(
8479
&parames,
8580
&y_vec,
8681
&party_shares[i],
8782
&vss_scheme_vec,
88-
&(&index_vec[i] + 1),
83+
&index_vec[i] + 1,
8984
)
9085
.expect("invalid vss");
9186
shared_keys_vec.push(shared_keys);
9287
dlog_proof_vec.push(dlog_proof);
9388
}
9489

95-
let pk_vec = (0..n.clone())
96-
.map(|i| dlog_proof_vec[i].pk.clone())
97-
.collect::<Vec<GE>>();
90+
let pk_vec = (0..n).map(|i| dlog_proof_vec[i].pk).collect::<Vec<GE>>();
9891

9992
//both parties run:
10093
Keys::verify_dlog_proofs(&parames, &dlog_proof_vec, &y_vec).expect("bad dlog proof");
10194

10295
//test
103-
let xi_vec = (0..t.clone() + 1)
104-
.map(|i| shared_keys_vec[i].x_i.clone())
105-
.collect::<Vec<FE>>();
96+
let xi_vec = (0..=t).map(|i| shared_keys_vec[i].x_i).collect::<Vec<FE>>();
10697
let x = vss_scheme_for_test[0]
10798
.clone()
108-
.reconstruct(&index_vec[0..t.clone() + 1], &xi_vec);
109-
let sum_u_i = party_keys_vec
110-
.iter()
111-
.fold(FE::zero(), |acc, x| acc + &x.u_i);
99+
.reconstruct(&index_vec[0..=t], &xi_vec);
100+
let sum_u_i = party_keys_vec.iter().fold(FE::zero(), |acc, x| acc + x.u_i);
112101
assert_eq!(x, sum_u_i);
113102

114103
(

benches/two_party_ecdsa/cclst_2019/keygen.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
#[macro_use]
2-
extern crate criterion;
3-
extern crate curv;
4-
extern crate multi_party_ecdsa;
1+
use criterion::criterion_main;
52

63
mod bench {
7-
use criterion::Criterion;
4+
use criterion::{criterion_group, Criterion};
85
use curv::arithmetic::traits::Samplable;
96
use curv::elliptic::curves::traits::*;
107
use curv::BigInt;
11-
use multi_party_ecdsa::protocols::two_party_ecdsa::cclst_2019::*;
8+
use multi_party_ecdsa::protocols::two_party_ecdsa::cclst_2019::{party_one, party_two};
129

1310
pub fn bench_full_keygen_party_one_two(c: &mut Criterion) {
1411
c.bench_function("keygen", move |b| {

0 commit comments

Comments
 (0)