diff --git a/pallets/dkg/src/functions.rs b/pallets/dkg/src/functions.rs index d76fea2d3..2f543a005 100644 --- a/pallets/dkg/src/functions.rs +++ b/pallets/dkg/src/functions.rs @@ -171,7 +171,7 @@ impl Pallet { } // Ensure a sufficient number of unique signers are present - ensure!(known_signers.len() > data.threshold.into(), Error::::NotEnoughSigners); + ensure!(known_signers.len() >= data.threshold.into(), Error::::NotEnoughSigners); Ok(()) } @@ -231,7 +231,7 @@ impl Pallet { } // Ensure a sufficient number of unique signers are present - ensure!(known_signers.len() > data.threshold.into(), Error::::NotEnoughSigners); + ensure!(known_signers.len() >= data.threshold.into(), Error::::NotEnoughSigners); Ok(()) } diff --git a/pallets/dkg/src/tests.rs b/pallets/dkg/src/tests.rs index 1f592a659..bc9f84fca 100644 --- a/pallets/dkg/src/tests.rs +++ b/pallets/dkg/src/tests.rs @@ -158,7 +158,32 @@ fn dkg_key_verifcation_works_for_ecdsa() { threshold: 1, }; - // should fail for signing different keys + assert_ok!(DKG::verify(JobResult::DKGPhaseOne(job_to_verify)),); + }); +} + +#[test] +fn dkg_key_verifcation_works_for_ecdsa_when_n_equals_t() { + new_test_ext().execute_with(|| { + let mut participant_one = mock_pub_key_ecdsa(); + let mut participant_two = mock_pub_key_ecdsa(); + let signature_one = mock_signature_ecdsa(participant_one, participant_one); + let signature_two = mock_signature_ecdsa(participant_two, participant_one); + let job_to_verify = DKGTSSKeySubmissionResult { + signature_type: DigitalSignatureType::Ecdsa, + key: participant_one.to_raw_vec().try_into().unwrap(), + participants: vec![ + participant_one.as_mut().to_vec().try_into().unwrap(), + participant_two.as_mut().to_vec().try_into().unwrap(), + ] + .try_into() + .unwrap(), + signatures: vec![signature_two.try_into().unwrap(), signature_one.try_into().unwrap()] + .try_into() + .unwrap(), + threshold: 2, + }; + assert_ok!(DKG::verify(JobResult::DKGPhaseOne(job_to_verify)),); }); } @@ -255,7 +280,32 @@ fn dkg_key_verifcation_works_for_schnorr() { threshold: 1, }; - // should fail for signing different keys + assert_ok!(DKG::verify(JobResult::DKGPhaseOne(job_to_verify)),); + }); +} + +#[test] +fn dkg_key_verifcation_works_for_schnorr_when_n_equals_t() { + new_test_ext().execute_with(|| { + let mut participant_one = mock_pub_key_sr25519(); + let mut participant_two = mock_pub_key_sr25519(); + let signature_one = mock_signature_sr25519(participant_one, participant_one); + let signature_two = mock_signature_sr25519(participant_two, participant_one); + let job_to_verify = DKGTSSKeySubmissionResult { + signature_type: DigitalSignatureType::SchnorrSr25519, + key: participant_one.to_raw_vec().try_into().unwrap(), + participants: vec![ + participant_one.as_mut().to_vec().try_into().unwrap(), + participant_two.as_mut().to_vec().try_into().unwrap(), + ] + .try_into() + .unwrap(), + signatures: vec![signature_two.try_into().unwrap(), signature_one.try_into().unwrap()] + .try_into() + .unwrap(), + threshold: 2, + }; + assert_ok!(DKG::verify(JobResult::DKGPhaseOne(job_to_verify)),); }); } diff --git a/pallets/jobs/src/tests.rs b/pallets/jobs/src/tests.rs index c84991c2d..9a048814e 100644 --- a/pallets/jobs/src/tests.rs +++ b/pallets/jobs/src/tests.rs @@ -119,7 +119,7 @@ fn jobs_submission_e2e_works_for_dkg() { .collect::>() .try_into() .unwrap(), - threshold: 5, + threshold: 6, permitted_caller: None, role_type: threshold_signature_role_type, }), @@ -154,6 +154,7 @@ fn jobs_submission_e2e_works_for_dkg() { ); Balances::make_free_balance_be(&mock_pub_key(TEN), 100); + // should work when n = t let submission = JobSubmission { expiry: 10, ttl: 200, @@ -164,7 +165,7 @@ fn jobs_submission_e2e_works_for_dkg() { .collect::>() .try_into() .unwrap(), - threshold: 3, + threshold: 5, permitted_caller: Some(mock_pub_key(TEN)), role_type: threshold_signature_role_type, }), diff --git a/primitives/src/jobs/mod.rs b/primitives/src/jobs/mod.rs index 70aacd58a..0dc520198 100644 --- a/primitives/src/jobs/mod.rs +++ b/primitives/src/jobs/mod.rs @@ -165,7 +165,7 @@ impl + Clone, MaxSubmissionLen: Get> /// This function is intended for simple checks and may need improvement in the future. pub fn sanity_check(&self) -> bool { match self { - JobType::DKGTSSPhaseOne(info) => info.participants.len() > info.threshold.into(), + JobType::DKGTSSPhaseOne(info) => info.participants.len() >= info.threshold.into(), JobType::ZkSaaSPhaseOne(info) => !info.participants.is_empty(), _ => true, }