diff --git a/pallets/exodus/Cargo.toml b/pallets/exodus/Cargo.toml index 98bc84a..42463e5 100644 --- a/pallets/exodus/Cargo.toml +++ b/pallets/exodus/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ghost-exodus" -version = "0.0.10" +version = "0.0.11" 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 cd7f1f6..3c51a05 100644 --- a/pallets/exodus/src/lib.rs +++ b/pallets/exodus/src/lib.rs @@ -2417,6 +2417,7 @@ impl Pallet { let mut number_of_leaked_keys = 0; let qualified_indexes = dkg_qualification.get_indexes(); + let total_authorities_len = qualified_indexes.count_ones::(); let mut failed_authorities = ParticipantsBitmap::::empty_from( &qualified_indexes, @@ -2426,17 +2427,17 @@ impl Pallet { &qualified_indexes, ); - let mut complaints_matrix: BTreeMap> = - BTreeMap::new(); + let mut complaints_matrix = vec![ + ParticipantsBitmap::::empty_from(&qualified_indexes); + total_authorities_len + ]; complaints_bitmap.iter().for_each(|(&accuser_index, offenders_bitmap)| { - offenders_bitmap.iter().for_each(|offended_index| { - complaints_matrix - .entry(offended_index) - .or_insert_with(|| { - ParticipantsBitmap::::empty_from(&qualified_indexes) - }) - .insert(accuser_index); + offenders_bitmap.iter().for_each(|offended_index: AuthIndex| { + let idx = offended_index as usize; + if idx >= complaints_matrix.len() { return; } + + complaints_matrix[idx].insert(accuser_index); }); }); @@ -2447,13 +2448,17 @@ impl Pallet { number_of_leaked_keys.saturating_inc(); } - if let Some(accusers_bitmap) = complaints_matrix.get(&offended_index) { - let successful_justifications = accusers_bitmap & recipients_bitmap; - let failed_to_justify = successful_justifications != *accusers_bitmap; + let idx = offended_index as usize; + if idx >= complaints_matrix.len() { return; } - if failed_to_justify { - failed_authorities.insert(offended_index); - } + let accusers_bitmap = &complaints_matrix[idx]; + if accusers_bitmap.is_empty() { return; } + + let successful_justifications = accusers_bitmap & recipients_bitmap; + let failed_to_justify = successful_justifications != *accusers_bitmap; + + if failed_to_justify { + failed_authorities.insert(offended_index); } });