use crate::common::{ REQUEST_DURING_RESHARING_PORT_SEED, damgard_etal_domain, generate_ckd_app_public_key, must_get_domain, must_setup_cluster, sign_all_domains, }; use near_mpc_contract_interface::types::{Protocol, ProtocolContractState}; use rand::{SeedableRng, rngs::StdRng}; /// Tests that signature and CKD requests are processed using the previous /// running state's threshold while resharing is in progress. /// /// Setup: 6 nodes, 5 initial participants (threshold 5). Domains cover /// classic ECDSA (CaitSith), DamgardEtAl, EdDSA (Frost) and /// CKD (ConfidentialKeyDerivation). The DamgardEtAl domain uses a /// reconstruction threshold of `t = 3`, which requires `2t - 1 = 5` signers, /// so we need at least 5 participants. Begin resharing to all 6 with threshold /// 6, then kill node 5 so resharing can't complete. Requests should still /// succeed using the previous running state across all signing schemes. #[tokio::test] async fn test_request_during_resharing() { // given let (mut cluster, contract_state) = must_setup_cluster(REQUEST_DURING_RESHARING_PORT_SEED, |c| { c.num_nodes = 6; c.initial_participant_indices = (0..5).collect(); c.threshold = 5; c.triples_to_buffer = 2; c.presignatures_to_buffer = 2; c.domains .push(damgard_etal_domain(c.domains.len() as u64, 3)); }) .await; // when tracing::info!("beginning resharing to 6 nodes, threshold 6"); cluster .start_resharing(&[0, 1, 2, 3, 4, 5], 6) .await .expect("start_resharing failed"); tracing::info!("killing node 5 to block resharing"); cluster.kill_nodes(&[5]).expect("failed to kill node 5"); // then let ckd_domain = must_get_domain(&contract_state, Protocol::ConfidentialKeyDerivation); let mut rng = StdRng::seed_from_u64(0); for i in 0..3 { tracing::info!(i, "sending sign requests during resharing"); sign_all_domains(&cluster, &contract_state, &mut rng).await; tracing::info!(i, "sending CKD request during resharing"); let outcome = cluster .send_ckd_request( ckd_domain.id, generate_ckd_app_public_key(&mut rng), cluster.default_user_account(), ) .await .expect("ckd request failed"); assert!( outcome.is_success(), "ckd request {i} failed: {:?}", outcome.failure_message() ); } assert!( matches!( cluster .get_contract_state() .await .expect("failed to get state"), ProtocolContractState::Resharing(_) ), "expected Resharing after requests" ); }