diff --git a/pallets/exodus/Cargo.toml b/pallets/exodus/Cargo.toml index bc78305..84549c7 100644 --- a/pallets/exodus/Cargo.toml +++ b/pallets/exodus/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ghost-exodus" -version = "0.0.21" +version = "0.0.22" description = "Threshold signature generation with DKG included" license.workspace = true authors.workspace = true diff --git a/pallets/exodus/src/lib.rs b/pallets/exodus/src/lib.rs index f55a0ba..863f897 100644 --- a/pallets/exodus/src/lib.rs +++ b/pallets/exodus/src/lib.rs @@ -2544,7 +2544,6 @@ impl Pallet { dkg_qualification.intersect_indexes(&participants); - if dkg_qualification.count_ones::() < min_threshold { dkg_qualification.nullify_indexes(); return; @@ -2554,16 +2553,17 @@ impl Pallet { let consensus = VerifyingKeyConsensus::::get(&network_curve, &dkg_index); let verifying_key_slice = consensus.element_bytes.as_slice(); + if verifying_key_slice.len() != network_curve.element_bytes_len() { + dkg_qualification.nullify_indexes(); + return; + } + weight.saturating_accrue(T::DbWeight::get().reads(2)); let mut exodus_session = CurrentExodus::::get(); + for network_type in T::NetworkDataHandler::iter_types_by_curve(&network_curve) { let exodus_request = match network_type { NetworkType::Evm => { - if verifying_key_slice.len() < 33 { - dkg_qualification.nullify_indexes(); - return; - } - let parity_byte = verifying_key_slice[0]; let parity = if parity_byte % 2 == 0 { 0u8 } else { 1u8 }; @@ -2613,20 +2613,22 @@ impl Pallet { let all_rotations_have_signatures = dkg_qualification .iter_rotation_sessions() - .all(|rotation_session| { + .fold(true, |accumulator, rotation_session| { let session = rotation_session.exodus_session; let r#type = rotation_session.network_type; - weight.saturating_accrue(T::DbWeight::get().reads(1)); - if ExodusRequests::::contains_key((&network_curve, &session)) { - return false - }; + weight.saturating_accrue(T::DbWeight::get().writes(1)); + ExodusRequests::::remove((&network_curve, &session)); weight.saturating_accrue(T::DbWeight::get().reads(1)); - ExodusSignedRotations::::contains_key((session, r#type), dkg_index) + let has_signature = ExodusSignedRotations::::contains_key( + (session, r#type), + dkg_index, + ); + + accumulator && has_signature }); - if all_rotations_have_signatures || is_initial_dkg_round { let verifying_key = dkg_qualification.get_verifying_key(); let activated_state: ActivatedState = (&*dkg_qualification).into(); diff --git a/pallets/exodus/src/tests.rs b/pallets/exodus/src/tests.rs index b54870d..25ee7b6 100644 --- a/pallets/exodus/src/tests.rs +++ b/pallets/exodus/src/tests.rs @@ -1136,7 +1136,7 @@ fn test_all_validators_can_execute_dkg() { ExodusRequests::::count() }); - assert_eq!(rotations_count, 3); + assert_eq!(rotations_count, 2); assert_eq!(bridges_count, 2); assert_eq!(governances_count, 15); assert_eq!(pending_exodus_requests, 0);