-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathrequest_during_resharing.rs
More file actions
78 lines (70 loc) · 2.75 KB
/
Copy pathrequest_during_resharing.rs
File metadata and controls
78 lines (70 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use crate::common::{
REQUEST_DURING_RESHARING_PORT_SEED, damgard_etal_domain, generate_ckd_app_public_key,
must_get_domain, must_setup_cluster, sign_all_schemes,
};
use near_mpc_contract_interface::types::{Protocol, ProtocolContractState};
use rand::SeedableRng;
/// 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 = rand::rngs::StdRng::seed_from_u64(0);
for i in 0..3 {
tracing::info!(i, "sending sign requests during resharing");
sign_all_schemes(&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"
);
}