Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Build Issues and Address Clippy Warnings #222

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion benches/multi_party_ecdsa/gg18/keygen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ mod bench {
})
});
}

#[allow(clippy::type_complexity)]
pub fn keygen_t_n_parties(
t: u16,
n: u16,
Expand Down Expand Up @@ -89,7 +91,7 @@ mod bench {
&y_vec,
&party_shares[i],
&vss_scheme_vec,
(&index_vec[i] + 1),
&index_vec[i] + 1,
)
.expect("invalid vss");
shared_keys_vec.push(shared_keys);
Expand Down
3 changes: 3 additions & 0 deletions examples/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub type Key = String;
#[allow(dead_code)]
pub const AES_KEY_BYTES_LEN: usize = 32;

#[allow(clippy::upper_case_acronyms)]
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
pub struct AEAD {
pub ciphertext: Vec<u8>,
Expand Down Expand Up @@ -101,6 +102,7 @@ where
None
}

#[allow(clippy::result_unit_err)]
pub fn broadcast(
client: &Client,
party_num: u16,
Expand All @@ -115,6 +117,7 @@ pub fn broadcast(
serde_json::from_str(&res_body).unwrap()
}

#[allow(clippy::result_unit_err)]
pub fn sendp2p(
client: &Client,
party_from: u16,
Expand Down
9 changes: 4 additions & 5 deletions examples/gg18_keygen_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ fn main() {
};

//signup:
let (party_num_int, uuid) = match signup(&client).unwrap() {
PartySignup { number, uuid } => (number, uuid),
};
let PartySignup { number, uuid } = signup(&client).unwrap();
let (party_num_int, uuid) = (number, uuid);
println!("number: {:?}, uuid: {:?}", party_num_int, uuid);

let party_keys = Keys::create(party_num_int);
Expand Down Expand Up @@ -263,9 +262,9 @@ fn main() {
fs::write(env::args().nth(2).unwrap(), keygen_json).expect("Unable to save !");
}

pub fn signup(client: &Client) -> Result<PartySignup, ()> {
pub fn signup(client: &Client) -> Result<PartySignup, Box<dyn std::error::Error>> {
let key = "signup-keygen".to_string();

let res_body = postb(client, "signupkeygen", key).unwrap();
serde_json::from_str(&res_body).unwrap()
Ok(serde_json::from_str(&res_body)?)
}
44 changes: 27 additions & 17 deletions examples/gg18_sign_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@ use common::{
broadcast, check_sig, poll_for_broadcasts, poll_for_p2p, postb, sendp2p, Params, PartySignup,
};

// Add this type alias before the main function
type KeygenOutput = (
Keys,
SharedKeys,
u16,
Vec<VerifiableSS<Secp256k1>>,
Vec<EncryptionKey>,
Point<Secp256k1>,
);

// Add this type alias near the top of the file, after other imports
type Phase5Proof = (
Phase5ADecom1,
HomoELGamalProof<Secp256k1, Sha256>,
DLogProof<Secp256k1, Sha256>,
);

#[allow(clippy::cognitive_complexity)]
fn main() {
if env::args().nth(4).is_some() {
Expand All @@ -45,14 +62,7 @@ fn main() {
// read key file
let data = fs::read_to_string(env::args().nth(2).unwrap())
.expect("Unable to load keys, did you run keygen first? ");
let (party_keys, shared_keys, party_id, vss_scheme_vec, paillier_key_vector, y_sum): (
Keys,
SharedKeys,
u16,
Vec<VerifiableSS<Secp256k1>>,
Vec<EncryptionKey>,
Point<Secp256k1>,
) = serde_json::from_str(&data).unwrap();
let (party_keys, shared_keys, party_id, vss_scheme_vec, paillier_key_vector, y_sum): KeygenOutput = serde_json::from_str(&data).unwrap();

//read parameters:
let data = fs::read_to_string("params.json")
Expand All @@ -61,8 +71,12 @@ fn main() {
let THRESHOLD = params.threshold.parse::<u16>().unwrap();

//signup:
let (party_num_int, uuid) = match signup(&client).unwrap() {
PartySignup { number, uuid } => (number, uuid),
let (party_num_int, uuid) = match signup(&client) {
Ok(PartySignup { number, uuid }) => (number, uuid),
Err(e) => {
eprintln!("Error during signup: {:?}", e);
std::process::exit(1);
}
};
println!("number: {:?}, uuid: {:?}", party_num_int, uuid);

Expand Down Expand Up @@ -365,11 +379,7 @@ fn main() {
uuid.clone(),
);

let mut decommit5a_and_elgamal_and_dlog_vec: Vec<(
Phase5ADecom1,
HomoELGamalProof<Secp256k1, Sha256>,
DLogProof<Secp256k1, Sha256>,
)> = Vec::new();
let mut decommit5a_and_elgamal_and_dlog_vec: Vec<Phase5Proof> = Vec::new();
format_vec_from_reads(
&round6_ans_vec,
party_num_int as usize,
Expand Down Expand Up @@ -523,9 +533,9 @@ fn format_vec_from_reads<'a, T: serde::Deserialize<'a> + Clone>(
}
}

pub fn signup(client: &Client) -> Result<PartySignup, ()> {
pub fn signup(client: &Client) -> Result<PartySignup, Box<dyn std::error::Error>> {
let key = "signup-sign".to_string();

let res_body = postb(client, "signupsign", key).unwrap();
serde_json::from_str(&res_body).unwrap()
Ok(serde_json::from_str(&res_body)?)
}
2 changes: 1 addition & 1 deletion examples/gg20_sm_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ impl<'r> FromRequest<'r> for LastEventId {
match header {
Some(Ok(last_seen_msg)) => Outcome::Success(LastEventId(Some(last_seen_msg))),
Some(Err(_parse_err)) => {
Outcome::Failure((Status::BadRequest, "last seen msg id is not valid"))
Outcome::Error((Status::BadRequest, "last seen msg id is not valid"))
}
None => Outcome::Success(LastEventId(None)),
}
Expand Down
2 changes: 1 addition & 1 deletion src/protocols/multi_party_ecdsa/gg_2018/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ fn keygen_t_n_parties(
&y_vec,
&party_shares[i],
&vss_scheme_vec,
(&index_vec[i] + 1),
&index_vec[i] + 1,
)
.expect("invalid vss");
shared_keys_vec.push(shared_keys);
Expand Down
2 changes: 2 additions & 0 deletions src/protocols/multi_party_ecdsa/gg_2020/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ pub mod state_machine;
#[cfg(test)]
mod test;


#[allow(dead_code)]
#[derive(Clone, Debug)]
pub struct ErrorType {
error_type: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ impl fmt::Debug for super::OfflineStage {
}

#[derive(Debug)]
#[allow(dead_code)]
pub struct OfflineStageProgress {
round: OfflineR,

Expand Down Expand Up @@ -120,6 +121,7 @@ impl fmt::Debug for ReceivedMessages {
}

#[derive(Debug)]
#[allow(dead_code)]
pub struct OutgoingMessages {
len: usize,
}
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,7 @@ impl Round6 {

#[derive(Clone)]
pub struct CompletedOfflineStage {
#[allow(dead_code)]
i: u16,
local_key: LocalKey<Secp256k1>,
sign_keys: SignKeys,
Expand Down Expand Up @@ -728,3 +729,4 @@ trait IteratorExt: Iterator {
}

impl<I> IteratorExt for I where I: Iterator {}

27 changes: 15 additions & 12 deletions src/protocols/multi_party_ecdsa/gg_2020/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,81 +70,81 @@ fn test_sign_n8_t4_ttag6() {
#[test]
fn test_sign_n2_t1_ttag1_corrupt_step5_party1() {
let res = sign(1, 2, 2, vec![0, 1], 5, &[0]);
assert!(&res.err().unwrap().bad_actors[..] == &[0])
assert!(res.err().unwrap().bad_actors[..] == [0])
}

// party 2 is corrupting step 5
#[test]
fn test_sign_n2_t1_ttag1_corrupt_step5_party2() {
let res = sign(1, 2, 2, vec![0, 1], 5, &[1]);
assert!(&res.err().unwrap().bad_actors[..] == &[1])
assert!(res.err().unwrap().bad_actors[..] == [1])
}

// both parties are corrupting step 5
#[test]
fn test_sign_n2_t1_ttag1_corrupt_step5_party12() {
let res = sign(1, 2, 2, vec![0, 1], 5, &[0, 1]);
assert!(&res.err().unwrap().bad_actors[..] == &[0, 1])
assert!(res.err().unwrap().bad_actors[..] == [0, 1])
}
// party 1 is corrupted
#[test]
fn test_sign_n5_t2_ttag4_corrupt_step5_party1() {
let res = sign(2, 5, 4, vec![0, 2, 3, 4], 5, &[0]);
assert!(&res.err().unwrap().bad_actors[..] == &[0])
assert!(res.err().unwrap().bad_actors[..] == [0])
}

// party 1,4 are corrupted
#[test]
fn test_sign_n5_t2_ttag4_corrupt_step5_party14() {
let res = sign(2, 5, 4, vec![0, 2, 3, 4], 5, &[0, 3]);
assert!(&res.err().unwrap().bad_actors[..] == &[0, 3])
assert!(res.err().unwrap().bad_actors[..] == [0, 3])
}

// party 1 is corrupting step 6
#[test]
fn test_sign_n2_t1_ttag1_corrupt_step6_party1() {
let res = sign(1, 2, 2, vec![0, 1], 6, &[0]);
assert!(&res.err().unwrap().bad_actors[..] == &[0])
assert!(res.err().unwrap().bad_actors[..] == [0])
}
// party 2 is corrupting step 6
#[test]
fn test_sign_n2_t1_ttag1_corrupt_step6_party2() {
let res = sign(1, 2, 2, vec![0, 1], 6, &[1]);
assert!(&res.err().unwrap().bad_actors[..] == &[1])
assert!(res.err().unwrap().bad_actors[..] == [1])
}

// both parties are corrupting step 6
#[test]
fn test_sign_n2_t1_ttag1_corrupt_step6_party12() {
let res = sign(1, 2, 2, vec![0, 1], 6, &[0, 1]);
assert!(&res.err().unwrap().bad_actors[..] == &[0, 1])
assert!(res.err().unwrap().bad_actors[..] == [0, 1])
}
// party 1 is corrupted
#[test]
fn test_sign_n5_t2_ttag4_corrupt_step6_party1() {
let res = sign(2, 5, 4, vec![0, 2, 3, 4], 6, &[0]);
assert!(&res.err().unwrap().bad_actors[..] == &[0])
assert!(res.err().unwrap().bad_actors[..] == [0])
}

// party 1,4 are corrupted
#[test]
fn test_sign_n5_t2_ttag4_corrupt_step6_party14() {
let res = sign(2, 5, 4, vec![0, 2, 3, 4], 6, &[0, 3]);
assert!(&res.err().unwrap().bad_actors[..] == &[0, 3])
assert!(res.err().unwrap().bad_actors[..] == [0, 3])
}

// party 1 is corrupting step 5
#[test]
fn test_sign_n2_t1_ttag1_corrupt_step7_party2() {
let res = sign(1, 2, 2, vec![0, 1], 7, &[1]);
assert!(&res.err().unwrap().bad_actors[..] == &[1])
assert!(res.err().unwrap().bad_actors[..] == [1])
}

// party 2,4 are corrupted
#[test]
fn test_sign_n5_t2_ttag4_corrupt_step7_party24() {
let res = sign(2, 5, 4, vec![0, 2, 3, 4], 7, &[1, 3]);
assert!(&res.err().unwrap().bad_actors[..] == &[1, 3])
assert!(res.err().unwrap().bad_actors[..] == [1, 3])
}

fn keygen_t_n_parties(
Expand Down Expand Up @@ -473,6 +473,8 @@ fn sign(
let mut T_vec = Vec::new();
let mut l_vec = Vec::new();
let mut T_proof_vec = Vec::new();

#[allow(clippy::needless_range_loop)]
for i in 0..ttag {
let (T_i, l_i, T_proof_i) = SignKeys::phase3_compute_t_i(&sigma_vec[i]);
T_vec.push(T_i);
Expand Down Expand Up @@ -678,6 +680,7 @@ fn sign(

// test corrupted local s
if corrupt_step == 7 {
#[allow(clippy::needless_range_loop)]
for i in 0..s_vec.len() {
if corrupted_parties.iter().any(|&x| x == i) {
s_vec[i] = &s_vec[i] + &s_vec[i];
Expand Down
5 changes: 5 additions & 0 deletions src/protocols/two_party_ecdsa/lindell_2017/party_two.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,13 @@ pub struct Party2Private {
pub struct PDLchallenge {
pub c_tag: BigInt,
pub c_tag_tag: BigInt,
#[allow(dead_code)]
a: BigInt,
#[allow(dead_code)]
b: BigInt,
#[allow(dead_code)]
blindness: BigInt,
#[allow(dead_code)]
q_tag: Point<Secp256k1>,
}

Expand Down Expand Up @@ -422,3 +426,4 @@ impl PartialSig {
}
}
}

4 changes: 2 additions & 2 deletions src/utilities/mta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ pub struct MessageB {
impl MessageA {
/// Creates a new `messageA` using Alice's Paillier encryption key and `dlog_statements`
/// - other parties' `h1,h2,N_tilde`s for range proofs.
/// If range proofs are not needed (one example is identification of aborts where we
/// only want to reconstruct a ciphertext), `dlog_statements` can be an empty slice.
/// If range proofs are not needed (one example is identification of aborts where we
/// only want to reconstruct a ciphertext), `dlog_statements` can be an empty slice.
pub fn a(
a: &Scalar<Secp256k1>,
alice_ek: &EncryptionKey,
Expand Down