Skip to content

Commit

Permalink
Update to [email protected] (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmpfs authored Jan 4, 2022
1 parent fc4a0ed commit b1448e2
Show file tree
Hide file tree
Showing 33 changed files with 1,829 additions and 1,593 deletions.
19 changes: 16 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
language: rust
cache: cargo
rust:
- nightly
rust: nightly
virt: lxd

before_install:
- rustup component add rustfmt clippy

script:
- cargo build --verbose
- cargo build --benches --verbose
- cargo test --verbose
- cargo fmt --all -- --check
- cargo clippy -- -D clippy::all

deploy:
provider: cargo
token:
secure: "QChykAD/vntzVNHePGuCHRNyLJwiqRAqIYw1uCqWVaca5IYMuItv2Qs6hShWt8AVQ631ZC5O5mnYTsPyxO3ZLZAPM/UEtmJiR9zf7v9DJyPPyyaT9kw+YrELVwit/xab2uJzJIZ1mBHSx0An/67gfdTITLjQmW2UVPhu3pdUz3rSrYBxp2quD7OgMfHeXXP8yk2xtZIXQ2mcNuNPnEkCk/siGTyS1Py/cpEFBsGfHSMPLyZq9Mn/PFPttPtebZiWUPvfDHFqbTd73SB2DmJrrdJ/rpeiHKNuPJUbc8qA1yDQjLATUNmDXjg+q8gcPIraj+zifeR6M+TIG0tLPU1NKVI1Oxta1CUurV+m5qY9YmFxtNyTNquOI4ehbckXADgZhIOLDD9/rfYETXdkxXwYh0WozNOp+yqZj+wGqFfxB3+DfMRKk/ooYQqCYJ2Pun+SzTSnv2REa0Sa70a67hADMV6h6qfumEq3XxgKouNHd3gg+b1urB6JKfL8RI9SrOwKgkU/mBl+qCzP+UwAUPqnzp/r9GONm86gsUZXuhwDJmru30B9YLOrzwnKdGjZEBWDV6OuT5p9e1R+rot069qeTqMOiu8ZAAulttBAEpFoG99vTW1elE3aSBasVa9/YS0M1kY4n4Yz8GTP8w8p9WXM6hX6MU8iR//hPsNHQiNwJws="
on:
tags: true
condition: '"$TRAVIS_TAG" =~ ^v[0-9].+$'
30 changes: 10 additions & 20 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "multi-party-ecdsa"
version = "0.7.4"
version = "0.8.0"
edition = "2018"
authors = [
"Gary <[email protected]>",
Expand All @@ -26,37 +26,30 @@ categories = ["cryptography"]
crate-type = ["lib"]

[features]
default = ["curv/rust-gmp-kzen"]
default = ["curv-kzen/rust-gmp-kzen"]
cclst = ["class_group"]

[dependencies]
subtle = { version = "2" }
serde = { version = "1.0", features = ["derive"] }
zeroize = "1"
libsecp256k1 = "0.3.2"
curv = { package = "curv-kzen", version = "0.7", default-features = false }
curv-kzen = { version = "0.9", default-features = false }
centipede = { version = "0.3", default-features = false }
zk-paillier = { version = "0.4.2", default-features = false }
round-based = { version = "0.1.4", features = [] }
thiserror = "1.0.23"
derivative = "2"

[dependencies.centipede]
git = "https://github.com/KZen-networks/centipede"
tag = "v0.2.12"
default-features = false
sha2 = "0.9"

[dependencies.paillier]
git = "https://github.com/KZen-networks/rust-paillier"
tag = "v0.3.10"
default-features = false

[dependencies.zk-paillier]
git = "https://github.com/KZen-networks/zk-paillier"
tag = "v0.3.12"
version = "0.4.2"
package = "kzen-paillier"
default-features = false

[dependencies.class_group]
git = "https://github.com/KZen-networks/class"
tag = "v0.5.2"
version = "0.6"
default-features = false
optional = true

[dev-dependencies]
Expand All @@ -73,9 +66,6 @@ rand = "0.7"
thiserror = "1.0.23"
round-based = { version = "0.1.4", features = ["dev"] }

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

[[example]]
name = "sm_manager"

Expand Down
41 changes: 28 additions & 13 deletions benches/multi_party_ecdsa/gg18/keygen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use criterion::criterion_main;
mod bench {
use criterion::{criterion_group, Criterion};
use curv::cryptographic_primitives::secret_sharing::feldman_vss::VerifiableSS;
use curv::elliptic::curves::secp256_k1::{FE, GE};
use curv::elliptic::curves::traits::*;
use curv::elliptic::curves::{secp256_k1::Secp256k1, Point, Scalar};
use multi_party_ecdsa::protocols::multi_party_ecdsa::gg_2018::party_i::*;
pub fn bench_full_keygen_party_one_two(c: &mut Criterion) {
c.bench_function("keygen t=1 n=2", move |b| {
Expand All @@ -23,13 +22,21 @@ mod bench {
pub fn keygen_t_n_parties(
t: u16,
n: u16,
) -> (Vec<Keys>, Vec<SharedKeys>, Vec<GE>, GE, VerifiableSS<GE>) {
) -> (
Vec<Keys>,
Vec<SharedKeys>,
Vec<Point<Secp256k1>>,
Point<Secp256k1>,
VerifiableSS<Secp256k1>,
) {
let parames = Parameters {
threshold: t,
share_count: n,
};
let (t, n) = (t as usize, n as usize);
let party_keys_vec = (0..n).map(Keys::create).collect::<Vec<Keys>>();
let party_keys_vec = (0..n)
.map(|i| Keys::create(i as u16))
.collect::<Vec<Keys>>();

let mut bc1_vec = Vec::new();
let mut decom_vec = Vec::new();
Expand All @@ -40,7 +47,9 @@ mod bench {
decom_vec.push(decom1);
}

let y_vec = (0..n).map(|i| decom_vec[i].y_i).collect::<Vec<GE>>();
let y_vec = (0..n)
.map(|i| decom_vec[i].y_i.clone())
.collect::<Vec<Point<Secp256k1>>>();
let mut y_vec_iter = y_vec.iter();
let head = y_vec_iter.next().unwrap();
let tail = y_vec_iter;
Expand All @@ -56,7 +65,7 @@ mod bench {
.expect("invalid key");
vss_scheme_vec.push(vss_scheme);
secret_shares_vec.push(secret_shares);
index_vec.push(index);
index_vec.push(index as u16);
}
let vss_scheme_for_test = vss_scheme_vec.clone();

Expand All @@ -65,11 +74,11 @@ mod bench {
(0..n)
.map(|j| {
let vec_j = &secret_shares_vec[j];
vec_j[i]
vec_j[i].clone()
})
.collect::<Vec<FE>>()
.collect::<Vec<Scalar<Secp256k1>>>()
})
.collect::<Vec<Vec<FE>>>();
.collect::<Vec<Vec<Scalar<Secp256k1>>>>();

let mut shared_keys_vec = Vec::new();
let mut dlog_proof_vec = Vec::new();
Expand All @@ -80,24 +89,30 @@ mod bench {
&y_vec,
&party_shares[i],
&vss_scheme_vec,
&index_vec[i] + 1,
(&index_vec[i] + 1).into(),
)
.expect("invalid vss");
shared_keys_vec.push(shared_keys);
dlog_proof_vec.push(dlog_proof);
}

let pk_vec = (0..n).map(|i| dlog_proof_vec[i].pk).collect::<Vec<GE>>();
let pk_vec = (0..n)
.map(|i| dlog_proof_vec[i].pk.clone())
.collect::<Vec<Point<Secp256k1>>>();

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

//test
let xi_vec = (0..=t).map(|i| shared_keys_vec[i].x_i).collect::<Vec<FE>>();
let xi_vec = (0..=t)
.map(|i| shared_keys_vec[i].x_i.clone())
.collect::<Vec<Scalar<Secp256k1>>>();
let x = vss_scheme_for_test[0]
.clone()
.reconstruct(&index_vec[0..=t], &xi_vec);
let sum_u_i = party_keys_vec.iter().fold(FE::zero(), |acc, x| acc + x.u_i);
let sum_u_i = party_keys_vec
.iter()
.fold(Scalar::<Secp256k1>::zero(), |acc, x| acc + &x.u_i);
assert_eq!(x, sum_u_i);

(
Expand Down
4 changes: 2 additions & 2 deletions benches/two_party_ecdsa/cclst_2019/keygen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ mod bench {

let (party_one_first_message, comm_witness, ec_key_pair_party1) =
party_one::KeyGenFirstMsg::create_commitments_with_fixed_secret_share(
ECScalar::new_random(),
Scalar::<Secp256k1>::random(),
);
let (party_two_first_message, _ec_key_pair_party2) =
party_two::KeyGenFirstMsg::create_with_fixed_secret_share(ECScalar::from(&BigInt::from(
party_two::KeyGenFirstMsg::create_with_fixed_secret_share(Scalar::<Secp256k1>::from(&BigInt::from(
10,
)));
let party_one_second_message = party_one::KeyGenSecondMsg::verify_and_decommit(
Expand Down
10 changes: 5 additions & 5 deletions benches/two_party_ecdsa/lindell_2017/keygen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use criterion::criterion_main;
mod bench {
use criterion::{criterion_group, Criterion};
use curv::arithmetic::traits::Samplable;
use curv::elliptic::curves::traits::*;
use curv::elliptic::curves::{secp256_k1::Secp256k1, Scalar};
use curv::BigInt;
use multi_party_ecdsa::protocols::two_party_ecdsa::lindell_2017::*;

Expand All @@ -12,12 +12,12 @@ mod bench {
b.iter(|| {
let (party_one_first_message, comm_witness, ec_key_pair_party1) =
party_one::KeyGenFirstMsg::create_commitments_with_fixed_secret_share(
ECScalar::from(&BigInt::sample(253)),
Scalar::<Secp256k1>::from(&BigInt::sample(253)),
);
let (party_two_first_message, _ec_key_pair_party2) =
party_two::KeyGenFirstMsg::create_with_fixed_secret_share(ECScalar::from(
&BigInt::from(10),
));
party_two::KeyGenFirstMsg::create_with_fixed_secret_share(
Scalar::<Secp256k1>::from(&BigInt::from(10)),
);
let party_one_second_message = party_one::KeyGenSecondMsg::verify_and_decommit(
comm_witness,
&party_two_first_message.d_log_proof,
Expand Down
34 changes: 16 additions & 18 deletions examples/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ use crypto::{
};
use curv::{
arithmetic::traits::Converter,
elliptic::curves::secp256_k1::{FE, GE},
elliptic::curves::traits::{ECPoint, ECScalar},
elliptic::curves::{secp256_k1::Secp256k1, Point, Scalar},
BigInt,
};
use reqwest::Client;
Expand Down Expand Up @@ -55,7 +54,7 @@ pub fn aes_encrypt(key: &[u8], plaintext: &[u8]) -> AEAD {
let mut gcm = AesGcm::new(KeySize256, key, &nonce[..], &aad);
let mut out: Vec<u8> = repeat(0).take(plaintext.len()).collect();
let mut out_tag: Vec<u8> = repeat(0).take(16).collect();
gcm.encrypt(&plaintext[..], &mut out[..], &mut out_tag[..]);
gcm.encrypt(plaintext, &mut out[..], &mut out_tag[..]);
AEAD {
ciphertext: out.to_vec(),
tag: out_tag.to_vec(),
Expand Down Expand Up @@ -103,12 +102,9 @@ pub fn broadcast(
sender_uuid: String,
) -> Result<(), ()> {
let key = format!("{}-{}-{}", party_num, round, sender_uuid);
let entry = Entry {
key: key.clone(),
value: data,
};
let entry = Entry { key, value: data };

let res_body = postb(&client, "set", entry).unwrap();
let res_body = postb(client, "set", entry).unwrap();
serde_json::from_str(&res_body).unwrap()
}

Expand All @@ -122,12 +118,9 @@ pub fn sendp2p(
) -> Result<(), ()> {
let key = format!("{}-{}-{}-{}", party_from, party_to, round, sender_uuid);

let entry = Entry {
key: key.clone(),
value: data,
};
let entry = Entry { key, value: data };

let res_body = postb(&client, "set", entry).unwrap();
let res_body = postb(client, "set", entry).unwrap();
serde_json::from_str(&res_body).unwrap()
}

Expand Down Expand Up @@ -190,27 +183,32 @@ pub fn poll_for_p2p(
}

#[allow(dead_code)]
pub fn check_sig(r: &FE, s: &FE, msg: &BigInt, pk: &GE) {
pub fn check_sig(
r: &Scalar<Secp256k1>,
s: &Scalar<Secp256k1>,
msg: &BigInt,
pk: &Point<Secp256k1>,
) {
use secp256k1::{verify, Message, PublicKey, PublicKeyFormat, Signature};

let raw_msg = BigInt::to_bytes(&msg);
let raw_msg = BigInt::to_bytes(msg);
let mut msg: Vec<u8> = Vec::new(); // padding
msg.extend(vec![0u8; 32 - raw_msg.len()]);
msg.extend(raw_msg.iter());

let msg = Message::parse_slice(msg.as_slice()).unwrap();
let mut raw_pk = pk.pk_to_key_slice();
let mut raw_pk = pk.to_bytes(false).to_vec();
if raw_pk.len() == 64 {
raw_pk.insert(0, 4u8);
}
let pk = PublicKey::parse_slice(&raw_pk, Some(PublicKeyFormat::Full)).unwrap();

let mut compact: Vec<u8> = Vec::new();
let bytes_r = &r.get_element()[..];
let bytes_r = &r.to_bytes().to_vec();
compact.extend(vec![0u8; 32 - bytes_r.len()]);
compact.extend(bytes_r.iter());

let bytes_s = &s.get_element()[..];
let bytes_s = &s.to_bytes().to_vec();
compact.extend(vec![0u8; 32 - bytes_s.len()]);
compact.extend(bytes_s.iter());

Expand Down
Loading

0 comments on commit b1448e2

Please sign in to comment.