From 3c4c119c99bc374d976e5189b057fb54dd278526 Mon Sep 17 00:00:00 2001 From: deleterium Date: Sun, 12 Dec 2021 22:35:29 -0300 Subject: [PATCH 1/2] Estimated percentage following statistic logaritmic curve. Printing estimated tries for 90% chance to find a match. --- src/main.rs | 9 +++++---- src/pubkey_matcher.rs | 7 +++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index b9e8250..b66feb7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,7 +25,7 @@ extern crate num_bigint; use num_bigint::BigInt; extern crate num_traits; -use num_traits::{ToPrimitive, Zero}; +use num_traits::{Zero}; #[cfg(feature = "gpu")] extern crate ocl; @@ -292,7 +292,7 @@ fn main() { .collect(); } let matcher_base = PubkeyMatcher::new(ext_pubkey_req, ext_pubkey_mask); - let estimated_attempts = matcher_base.estimated_attempts(); + let finding_chance = matcher_base.finding_chance(); let matcher_base = Arc::new(matcher_base); let limit = args .value_of("limit") @@ -333,7 +333,7 @@ fn main() { .map(|s| s.parse().expect("Failed to parse thread count option")) .unwrap_or_else(|| num_cpus::get() - 1); let mut thread_handles = Vec::with_capacity(threads); - eprintln!("Estimated attempts needed: {}", estimated_attempts); + eprintln!("Estimated attempts for 90% chance to find a match: {:.0}", -1.0_f64 / (1.0_f64 - finding_chance).log10()); for _ in 0..threads { let mut key_or_seed = [0u8; 32]; OsRng.fill_bytes(&mut key_or_seed); @@ -423,6 +423,7 @@ fn main() { hex::encode_upper(&found_private_key), ); } + params.attempts.store(0, atomic::Ordering::Relaxed); for byte in &mut found_private_key { *byte = 0; } @@ -435,7 +436,7 @@ fn main() { thread::spawn(move || loop { let attempts = attempts.load(atomic::Ordering::Relaxed); let estimated_percent = - 100. * (attempts as f64) / estimated_attempts.to_f64().unwrap_or(f64::INFINITY); + 100. * (1.0 - (1.0 - finding_chance).powf(attempts as f64)); let runtime = start_time.elapsed(); let keys_per_second = (attempts as f64) // simplify to .as_millis() when available diff --git a/src/pubkey_matcher.rs b/src/pubkey_matcher.rs index 4e66033..c4b35c4 100644 --- a/src/pubkey_matcher.rs +++ b/src/pubkey_matcher.rs @@ -2,7 +2,6 @@ use std::cmp; use blake2::VarBlake2b; use digest::{Update, VariableOutput}; -use num_bigint::BigInt; #[derive(Clone)] pub struct PubkeyMatcher { @@ -68,11 +67,11 @@ impl PubkeyMatcher { true } - pub fn estimated_attempts(&self) -> BigInt { + pub fn finding_chance(&self) -> f64 { let mut bits_in_mask = 0; for byte in &self.mask { - bits_in_mask += byte.count_ones() as usize; + bits_in_mask += byte.count_ones() as i32; } - BigInt::from(1) << bits_in_mask + 2.0_f64.powi(-bits_in_mask) } } From d64f25eb76ef41ec4ed156113aa3f27f9392063c Mon Sep 17 00:00:00 2001 From: deleterium Date: Sun, 12 Dec 2021 22:56:19 -0300 Subject: [PATCH 2/2] Restarting counter for tries for both cpu and gpu calculations (when limit is used) --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index b66feb7..963bded 100644 --- a/src/main.rs +++ b/src/main.rs @@ -115,6 +115,7 @@ fn check_solution(params: &ThreadParams, key_material: [u8; 32]) -> bool { public_key, params.simple_output, ); + params.attempts.store(0, atomic::Ordering::Relaxed); if params.limit != 0 && params.found_n.fetch_add(1, atomic::Ordering::Relaxed) + 1 >= params.limit { @@ -423,7 +424,6 @@ fn main() { hex::encode_upper(&found_private_key), ); } - params.attempts.store(0, atomic::Ordering::Relaxed); for byte in &mut found_private_key { *byte = 0; }