Skip to content

Commit

Permalink
Merge branch 'eichhorl/use-new-contexts' into 'master'
Browse files Browse the repository at this point in the history
feat(schnorr): CON-1262 Switch signer to new generalized signature requests contexts

Currently, ECDSA signature requests still generate a `SignWithEcdsaContext`. Once we deploy a Schnorr key, Schnorr requests weill generate a generalized `SignWithThresholdContext` which will eventually also be used for ECDSA. In order to avoid having to handle both types of contexts separately, we create a function in the replicated state, mapping existing `SignWithEcdsaContext`s to `SignWithThresholdContext`s and returning them together with existing `SignWithThresholdContext`s. This allows us to handle both request types using the same interface.

The remaining changes adapt names and types, and prepare for the addition of the tSchnorr implementation which remains unimplemented for now. This includes generation & validation of Schnorr signature shares, and creation & validation of combined Schnorr signatures. 

See merge request dfinity-lab/public/ic!19576
  • Loading branch information
eichhorl committed Jun 7, 2024
2 parents 10397eb + fa60cfe commit e2849a8
Show file tree
Hide file tree
Showing 14 changed files with 472 additions and 416 deletions.
14 changes: 7 additions & 7 deletions rs/consensus/src/consensus/catchup_package_maker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ impl CatchUpPackageMaker {
mod tests {
//! CatchUpPackageMaker unit tests
use crate::ecdsa::test_utils::{
add_available_quadruple_to_payload, empty_ecdsa_payload, fake_ecdsa_key_id,
fake_sign_with_ecdsa_context_with_quadruple, fake_state_with_ecdsa_contexts,
add_available_quadruple_to_payload, empty_ecdsa_payload, fake_ecdsa_master_public_key_id,
fake_signature_request_context_with_pre_sig, fake_state_with_signature_requests,
};

use super::*;
Expand Down Expand Up @@ -394,23 +394,23 @@ mod tests {
.expect_get_state_hash_at()
.return_const(Ok(CryptoHashOfState::from(CryptoHash(vec![1, 2, 3]))));

let key_id = fake_ecdsa_key_id();
let key_id = fake_ecdsa_master_public_key_id();

// Create three quadruple Ids and contexts, quadruple "2" will remain unmatched.
let pre_sig_id1 = PreSigId(1);
let pre_sig_id2 = PreSigId(2);
let pre_sig_id3 = PreSigId(3);

let contexts = vec![
fake_sign_with_ecdsa_context_with_quadruple(1, key_id.clone(), Some(pre_sig_id1)),
fake_sign_with_ecdsa_context_with_quadruple(2, key_id.clone(), None),
fake_sign_with_ecdsa_context_with_quadruple(3, key_id.clone(), Some(pre_sig_id3)),
fake_signature_request_context_with_pre_sig(1, key_id.clone(), Some(pre_sig_id1)),
fake_signature_request_context_with_pre_sig(2, key_id.clone(), None),
fake_signature_request_context_with_pre_sig(3, key_id.clone(), Some(pre_sig_id3)),
];

state_manager
.get_mut()
.expect_get_state_at()
.return_const(Ok(fake_state_with_ecdsa_contexts(
.return_const(Ok(fake_state_with_signature_requests(
Height::from(0),
contexts.clone(),
)
Expand Down
14 changes: 7 additions & 7 deletions rs/consensus/src/consensus/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1654,8 +1654,8 @@ impl Validator {
#[cfg(test)]
pub mod test {
use crate::ecdsa::test_utils::{
add_available_quadruple_to_payload, empty_ecdsa_payload, fake_ecdsa_key_id,
fake_sign_with_ecdsa_context_with_quadruple, fake_state_with_ecdsa_contexts,
add_available_quadruple_to_payload, empty_ecdsa_payload, fake_ecdsa_master_public_key_id,
fake_signature_request_context_with_pre_sig, fake_state_with_signature_requests,
};

use super::*;
Expand Down Expand Up @@ -1900,22 +1900,22 @@ pub mod test {
.expect_get_state_hash_at()
.return_const(Ok(state_hash.clone()));

let key_id = fake_ecdsa_key_id();
let key_id = fake_ecdsa_master_public_key_id();
// Create three quadruple Ids and contexts, quadruple "2" will remain unmatched.
let pre_sig_id1 = PreSigId(1);
let pre_sig_id2 = PreSigId(2);
let pre_sig_id3 = PreSigId(3);

let contexts = vec![
fake_sign_with_ecdsa_context_with_quadruple(1, key_id.clone(), Some(pre_sig_id1)),
fake_sign_with_ecdsa_context_with_quadruple(2, key_id.clone(), None),
fake_sign_with_ecdsa_context_with_quadruple(3, key_id.clone(), Some(pre_sig_id3)),
fake_signature_request_context_with_pre_sig(1, key_id.clone(), Some(pre_sig_id1)),
fake_signature_request_context_with_pre_sig(2, key_id.clone(), None),
fake_signature_request_context_with_pre_sig(3, key_id.clone(), Some(pre_sig_id3)),
];

state_manager
.get_mut()
.expect_get_state_at()
.return_const(Ok(fake_state_with_ecdsa_contexts(
.return_const(Ok(fake_state_with_signature_requests(
Height::from(0),
contexts.clone(),
)
Expand Down
23 changes: 10 additions & 13 deletions rs/consensus/src/ecdsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ impl EcdsaPriorityFnArgs {
.map_or(Default::default(), |snapshot| {
let request_contexts = snapshot
.get_state()
.sign_with_ecdsa_contexts()
.signature_request_contexts()
.values()
.flat_map(get_context_request_id)
.collect::<BTreeSet<_>>();
Expand Down Expand Up @@ -594,30 +594,30 @@ fn compute_priority(
#[cfg(test)]
mod tests {
use self::test_utils::{
fake_completed_sign_with_ecdsa_context, fake_sign_with_ecdsa_context_with_quadruple,
fake_state_with_ecdsa_contexts, TestEcdsaBlockReader,
fake_completed_signature_request_context, fake_signature_request_context_with_pre_sig,
fake_state_with_signature_requests, TestEcdsaBlockReader,
};

use super::test_utils::fake_ecdsa_key_id;
use super::*;
use ic_management_canister_types::MasterPublicKeyId;
use ic_test_utilities::state_manager::RefMockStateManager;
use ic_types::consensus::idkg::{EcdsaUIDGenerator, PreSigId};
use ic_types::crypto::canister_threshold_sig::idkg::IDkgTranscriptId;
use ic_types::{consensus::idkg::RequestId, PrincipalId, SubnetId};
use test_utils::fake_ecdsa_master_public_key_id;
use tests::test_utils::create_sig_inputs;

#[test]
fn test_ecdsa_priority_fn_args() {
let state_manager = Arc::new(RefMockStateManager::default());
let height = Height::from(100);
let key_id = fake_ecdsa_key_id();
let key_id = fake_ecdsa_master_public_key_id();
// Add two contexts to state, one with, and one without quadruple
let pre_sig_id = PreSigId(0);
let context_with_quadruple = fake_completed_sign_with_ecdsa_context(0, pre_sig_id);
let context_with_quadruple =
fake_completed_signature_request_context(0, key_id.clone(), pre_sig_id);
let context_without_quadruple =
fake_sign_with_ecdsa_context_with_quadruple(1, key_id.clone(), None);
let snapshot = fake_state_with_ecdsa_contexts(
fake_signature_request_context_with_pre_sig(1, key_id.clone(), None);
let snapshot = fake_state_with_signature_requests(
height,
[
context_with_quadruple.clone(),
Expand All @@ -635,10 +635,7 @@ mod tests {

let block_reader = TestEcdsaBlockReader::for_signer_test(
height,
vec![(
expected_request_id.clone(),
create_sig_inputs(0, &MasterPublicKeyId::Ecdsa(key_id.clone())),
)],
vec![(expected_request_id.clone(), create_sig_inputs(0, &key_id))],
);

// Only the context with matched quadruple should be in "requested"
Expand Down
Loading

0 comments on commit e2849a8

Please sign in to comment.