From 26372deadbe13152667213b19a581131ede95ea9 Mon Sep 17 00:00:00 2001 From: Uncle Stinky Date: Thu, 19 Nov 2026 16:05:27 +0300 Subject: [PATCH] compute round 6 merkle proof depth from highest authority index and preserve proof on retry Signed-off-by: Uncle Stinky --- pallets/exodus/Cargo.toml | 2 +- pallets/exodus/src/lib.rs | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/pallets/exodus/Cargo.toml b/pallets/exodus/Cargo.toml index 2fc2198..67e63d4 100644 --- a/pallets/exodus/Cargo.toml +++ b/pallets/exodus/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ghost-exodus" -version = "0.1.9" +version = "0.1.10" 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 3a6cb9e..0e21cc8 100644 --- a/pallets/exodus/src/lib.rs +++ b/pallets/exodus/src/lib.rs @@ -3206,8 +3206,12 @@ impl Pallet { return Err(InvalidTransaction::BadProof); } - let estimated_proof_count = state - .count_ones::() + let leaf_capacity = state + .highest_bit::() + .map(|bit| bit.saturating_add(1)) + .unwrap_or(0); + + let estimated_proof_count = leaf_capacity .next_power_of_two() .trailing_zeros(); @@ -3802,17 +3806,14 @@ impl Pallet { .get_release_block() .saturating_sub(current_block); - if blocks_remaining <= 2u32.into() { - return false; - } + if blocks_remaining <= 2u32.into() { return false; } let elapsed_blocks = dkg_round_period .saturating_sub(blocks_remaining) .saturating_add(One::one()); let total_authorities = if dkg_phase == DkgPhase::Round0 { - let indexes = qualification_authorities.get_indexes(); - indexes.active_bits_count() as usize + QualificationAuthorities::::decode_len(&network_curve).unwrap_or_default() } else { qualification_authorities.count_ones::() }; @@ -4835,7 +4836,7 @@ impl Pallet { } let Some(DkgStorageEnum::Round5 { secret_share, merkle_proof }) = - round_metadata.into_inner_mut() else { + round_metadata.into_inner() else { return Ok(ExodusOk::DkgRoundNothingStored( ROUND_NUMBER_6, authority_index, @@ -4846,7 +4847,7 @@ impl Pallet { let verifying_share = network_curve .dkg_derive_verifying_share(secret_share)?; - let owned_merkle_proof = core::mem::take(merkle_proof); + let owned_merkle_proof = merkle_proof.clone(); let current_dkg_index = qualification_state.get_dkg_index(); dkg_storage.prepare_signed_call_with_context(