Fix integration tests

Some test were failing because they were not using the new identifiers, but were
trying to identify the participants by simple indices such as 1, 2, 3.
This commit is contained in:
Marek 2021-08-01 20:21:15 +01:00
parent 8eb3937f24
commit 46f8e2cb29
2 changed files with 38 additions and 45 deletions

View File

@ -467,11 +467,7 @@ impl SignatureShare {
/// perform the first round. Batching entails generating more than one
/// nonce/commitment pair at a time. Nonces should be stored in secret storage
/// for later use, whereas the commitments are published.
<<<<<<< HEAD
=======
///
>>>>>>> 316082b (Change the type of the identifiers from u8 to u64)
/// The number of nonces is limited to 255. This limit can be increased if it
/// turns out to be too conservative.
// TODO: Make sure the above is a correct statement, fix if needed in:

View File

@ -8,7 +8,7 @@ use crate::{
};
use rand::thread_rng;
use serde_json;
use std::convert::TryFrom;
use std::{collections::HashMap, convert::TryFrom};
#[test]
fn validate_version() {
@ -421,25 +421,8 @@ fn serialize_signingpackage() {
fn validate_signatureshare() {
let mut setup = basic_setup();
// signers and aggregator should have this data from `SharePackage`
let (shares, _pubkeys) =
frost::keygen_with_dealer(setup.num_signers, setup.threshold, setup.rng.clone()).unwrap();
// create a signing package, this is done in the aggregator side.
// the signrs should have this data from `SigningPackage`
let (nonce1, commitment1) = frost::preprocess(1, u64::from(setup.signer1), &mut setup.rng);
let (_nonce2, commitment2) = frost::preprocess(1, u64::from(setup.signer2), &mut setup.rng);
let commitments = vec![commitment1[0], commitment2[0]];
let participants = vec![setup.signer1, setup.signer2];
let signing_commitments = create_signing_commitments(commitments, participants);
let signing_package = frost::SigningPackage::from(SigningPackage {
signing_commitments: signing_commitments.clone(),
message: "hola".as_bytes().to_vec(),
});
// here we get started with the `SignatureShare` message.
let signature_share = frost::sign(&signing_package, nonce1[0], &shares[0]).unwrap();
let signature_share = generate_signature_share(&mut setup);
// this header is invalid
let header = create_valid_header(setup.aggregator, setup.signer1);
@ -479,25 +462,8 @@ fn validate_signatureshare() {
fn serialize_signatureshare() {
let mut setup = basic_setup();
// signers and aggregator should have this data from `SharePackage`
let (shares, _pubkeys) =
frost::keygen_with_dealer(setup.num_signers, setup.threshold, setup.rng.clone()).unwrap();
// create a signing package, this is done in the aggregator side.
// the signers should have this data from `SigningPackage`
let (nonce1, commitment1) = frost::preprocess(1, u64::from(setup.signer1), &mut setup.rng);
let (_nonce2, commitment2) = frost::preprocess(1, u64::from(setup.signer2), &mut setup.rng);
let commitments = vec![commitment1[0], commitment2[0]];
let participants = vec![setup.signer1, setup.signer2];
let signing_commitments = create_signing_commitments(commitments, participants);
let signing_package = frost::SigningPackage::from(SigningPackage {
signing_commitments: signing_commitments.clone(),
message: "hola".as_bytes().to_vec(),
});
// here we get started with the `SignatureShare` message.
let signature_share = frost::sign(&signing_package, nonce1[0], &shares[0]).unwrap();
let signature_share = generate_signature_share(&mut setup);
// valid header
let header = create_valid_header(setup.signer1, setup.aggregator);
@ -736,10 +702,12 @@ fn full_setup() -> (Setup, signature::Signature<SpendAuth>) {
let mut commitments: Vec<frost::SigningCommitments> =
Vec::with_capacity(setup.threshold as usize);
// aggregator generates nonces and signing commitments for each participant.
for participant_index in 1..(setup.threshold + 1) {
let (nonce, commitment) = frost::preprocess(1, participant_index as u64, &mut setup.rng);
nonces.insert(participant_index as u64, nonce);
// Shares represent participants.
// The aggregator generates nonces and signing commitments for each participant.
for share in &shares {
// Generate one nonce and one SigningCommitments instance for each participant.
let (nonce, commitment) = frost::preprocess(1, share.index, &mut setup.rng);
nonces.insert(share.index, nonce);
commitments.push(commitment[0]);
}
@ -803,3 +771,32 @@ fn create_signing_commitments(
})
.collect()
}
fn generate_signature_share(setup: &mut Setup) -> frost::SignatureShare {
// signers and aggregator should have this data from `SharePackage`
let (shares, _pubkeys) =
frost::keygen_with_dealer(setup.num_signers, setup.threshold, setup.rng.clone()).unwrap();
let mut nonces: HashMap<u64, Vec<frost::SigningNonces>> =
HashMap::with_capacity(setup.threshold as usize);
let mut commitments: Vec<frost::SigningCommitments> =
Vec::with_capacity(setup.threshold as usize);
// Shares represent participants.
for share in &shares {
// Generate one nonce and one SigningCommitments instance for each participant.
let (nonce, commitment) = frost::preprocess(1, share.index, &mut setup.rng);
nonces.insert(share.index, nonce);
commitments.push(commitment[0]);
}
let signing_package = frost::SigningPackage {
message: "message to sign".as_bytes().to_vec(),
signing_commitments: commitments,
};
let signing_share = &shares[0];
let signing_nonce = nonces[&signing_share.index][0];
frost::sign(&signing_package, signing_nonce, &signing_share).unwrap()
}