From 0fcfbbc5cfd5c3c2630857e8775db507d54284b8 Mon Sep 17 00:00:00 2001 From: davidsemakula Date: Tue, 17 Oct 2023 11:24:52 +0300 Subject: [PATCH] refactor challenge bits implementation --- multi-party-ecdsa/src/utilities/zk_composite_dlog.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/multi-party-ecdsa/src/utilities/zk_composite_dlog.rs b/multi-party-ecdsa/src/utilities/zk_composite_dlog.rs index f69f39a..0edcde0 100644 --- a/multi-party-ecdsa/src/utilities/zk_composite_dlog.rs +++ b/multi-party-ecdsa/src/utilities/zk_composite_dlog.rs @@ -96,10 +96,14 @@ fn compute_challenges( for (idx, byte) in challenge_bytes.iter().enumerate() { // We're only looking for non-zero bits (i.e. 1) // since the rest are already set to zero by default. - let bits = format!("{byte:08b}"); - for (i, char) in bits.chars().enumerate() { - if char == '1' { - challenge_bits[idx * 8 + i] = ChallengeBit::ONE; + let start = byte.leading_zeros(); // inclusive. + if start < 8 { + // Skips case of all zeros. + let end = 8 - byte.trailing_zeros(); // exclusive. + for i in start..end { + if (byte >> (7 - i)) & 1 == 1 { + challenge_bits[(idx * 8) + i as usize] = ChallengeBit::ONE + } } } }