Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
there has been an attempt...
  • Loading branch information
ursisterbtw committed Nov 17, 2024
1 parent 1ce22f0 commit 9eb08fb
Show file tree
Hide file tree
Showing 6 changed files with 278 additions and 20 deletions.
19 changes: 11 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
[package]
name = "hash_hunter"
version = "0.1.0"
version = "0.2.0"
edition = "2021"

[dependencies]
clap = { version = "4.5.20", features = ["derive"] }
rand = "0.8"
clap = { version = "4.5.21", features = ["derive"] }
rand = "0.8.5"
secp256k1 = { version = "0.30.0", features = ["rand"] }
sha3 = "0.10"
sha3 = "0.10.8"
hex = "0.4.3"
dashmap = "6.1.0"
rayon = "1.10.0"
num_cpus = "1.16.0"
colored = "2.0.0"
indicatif = "0.17.8"
serde_json = "1.0.128"
regex = "1.11.0"
colored = "2.1.0"
indicatif = "0.17.9"
serde_json = "1.0.133"
regex = "1.11.1"
chrono = "0.4.38"
config = "0.14"
serde = { version = "1.0.215", features = ["derive"] }
serde_yaml = "0.9.33"
23 changes: 23 additions & 0 deletions cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
steps:
# create buildx instance
- name: "gcr.io/cloud-builders/docker"
args: ["buildx", "create", "--name", "builder", "--use"]

# build and push the container image for multiple platforms
- name: "gcr.io/cloud-builders/docker"
args:
- "buildx"
- "build"
- "--platform"
- "linux/amd64,linux/arm64"
- "-t"
- "gcr.io/$PROJECT_ID/hash_hunter:latest"
- "--push"
- "."

images:
- "gcr.io/$PROJECT_ID/hash_hunter:latest"

timeout: "1800s"
options:
machineType: "E2_HIGHCPU_8"
108 changes: 108 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
use serde::Deserialize;

#[derive(Debug, Deserialize)]
pub struct Config {
pub version: String,
pub app: App,
pub search: Search,
pub performance: Performance,
pub output: Output,
pub docker: Docker,
pub security: Security,
}

#[derive(Debug, Deserialize)]
pub struct App {
pub name: String,
pub version: String,
pub description: String,
pub warning: String,
}

#[derive(Debug, Deserialize)]
pub struct Search {
pub patterns: Patterns,
pub validation: Validation,
}

#[derive(Debug, Deserialize)]
pub struct Patterns {
pub start: String,
pub end: String,
pub regex: String,
}

#[derive(Debug, Deserialize)]
pub struct Validation {
pub use_checksum: bool,
pub min_zeros: usize, // Changed from u32 to usize
pub verify_addresses: bool,
}

#[derive(Debug, Deserialize)]
pub struct Performance {
pub step_size: u64,
pub max_tries: u64,
pub log_interval_ms: u64,
pub threads: String,
pub resources: Resources,
}

#[derive(Debug, Deserialize)]
pub struct Resources {
pub cpu_limit: f32,
pub memory_limit: String,
}

#[derive(Debug, Deserialize)]
pub struct Output {
pub directory: String,
pub files: Files,
pub progress_bar: ProgressBar,
}

#[derive(Debug, Deserialize)]
pub struct Files {
pub log: String,
pub success_marker: String,
}

#[derive(Debug, Deserialize)]
pub struct ProgressBar {
pub template: String,
pub chars: String,
}

#[derive(Debug, Deserialize)]
pub struct Docker {
pub base_image: String,
pub builder_image: String, // Corrected field name from build_image to builder_image
pub platforms: Vec<String>,
pub healthcheck: Healthcheck,
pub volumes: Vec<Volume>,
}

#[derive(Debug, Deserialize)]
pub struct Healthcheck {
pub interval: String,
pub timeout: String,
pub retries: u32,
}

#[derive(Debug, Deserialize)]
pub struct Volume {
pub source: String,
pub target: String,
}

#[derive(Debug, Deserialize)]
pub struct Security {
pub skip_confirmation: bool,
pub entropy: Entropy,
}

#[derive(Debug, Deserialize)]
pub struct Entropy {
pub guesses_per_second: f64,
pub min_bits: u32,
}
62 changes: 62 additions & 0 deletions src/configuration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# configuration
version: "1.0"

# app settings
app:
name: "hash_hunter"
version: "0.1.0"
description: "Ethereum vanity address generator"
warning: "THIS IS A PROOF OF CONCEPT - DO NOT USE IN PRODUCTION"

# search params
search:
patterns:
start: "69"
end: "69696969"
regex: ""
validation:
use_checksum: true
min_zeros: 0
verify_addresses: true

# performance settings
performance:
step_size: 50000
max_tries: 10000000000
log_interval_ms: 15000
threads: "auto" # uses num_cpus::get()
resources:
cpu_limit: 7.5
memory_limit: "8G"

# output settings
output:
directory: "gen"
files:
log: "hunter.log"
success_marker: "SUCCESS"
progress_bar:
template: "{spinner:.green} [{elapsed_precise}] [{wide_bar:.cyan/blue}] {pos}/{len} ({eta})"
chars: "#>-"

# docker settings
docker:
base_image: "ubuntu:22.04"
builder_image: "rust:1.82"
platforms:
- "linux/amd64"
- "linux/arm64"
healthcheck:
interval: "30s"
timeout: "10s"
retries: 3
volumes:
- source: "./gen"
target: "/usr/src/app/gen"

# security settings
security:
skip_confirmation: false
entropy:
guesses_per_second: 1e12
min_bits: 160
73 changes: 61 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
mod config;
use crate::configuration::*;

Check failure

Code scanning / clippy

unresolved import crate::configuration Error

unresolved import crate::configuration

use crate::config::Config;
use chrono::Utc;
use clap::Parser;
use colored::*;
Expand All @@ -7,6 +11,7 @@ use rand::rngs::OsRng;
use regex::Regex;
use secp256k1::{PublicKey, Secp256k1, SecretKey};
use sha3::{Digest, Keccak256};
use std::fs;
use std::fs::OpenOptions;
use std::io::{self, Write};
use std::sync::atomic::{AtomicBool, Ordering};
Expand Down Expand Up @@ -63,33 +68,62 @@ struct VanityResult {
fn main() {
print_startup_screen();

let args = Args::parse();
// Load config first
let config = load_config();

let start_pattern = args.start_pattern.to_lowercase();
let end_pattern = args.end_pattern.to_lowercase();
let use_checksum = args.checksum;
let step = args.step;
let max_tries = args.max_tries;
let log_interval = args.log_interval;
let min_zeros = args.min_zeros;
// Use config values as defaults for Args
let args = Args::parse();

// Override args with config if provided
let start_pattern = if args.start_pattern == "69" {
config.search.patterns.start.clone()
} else {
args.start_pattern.clone()
};
let end_pattern = if args.end_pattern == "69696969" {
config.search.patterns.end.clone()
} else {
args.end_pattern.clone()
};
let use_checksum = args.checksum || config.search.validation.use_checksum;
let step = args.step.max(config.performance.step_size);
let max_tries = args.max_tries.max(config.performance.max_tries);
let log_interval = args.log_interval.max(config.performance.log_interval_ms);
let min_zeros = args
.min_zeros
.max(config.search.validation.min_zeros as usize);
let regex_pattern = if !args.regex_pattern.is_empty() {
Some(Arc::new(
Regex::new(&args.regex_pattern).expect("Invalid regex pattern"),
))
} else if !config.search.patterns.regex.is_empty() {
Some(Arc::new(
Regex::new(&config.search.patterns.regex).expect("Invalid regex pattern in config"),
))
} else {
None
};
let skip_confirmation = args.skip_confirmation || config.security.skip_confirmation;

// add a confirmation prompt
if !confirm_start(&args) {
if !confirm_start(&Args {
start_pattern: start_pattern.clone(),
end_pattern: end_pattern.clone(),
checksum: use_checksum,
step,
max_tries,
log_interval,
min_zeros,
regex_pattern: args.regex_pattern.clone(), // or use config pattern
skip_confirmation,
}) {
println!("Operation cancelled by user.");
return;
}

println!("Starting Vanity Address Generator 🧪");
println!("Prefix: {}", args.start_pattern.bright_green());
println!("Suffix: {}", args.end_pattern.bright_green());
println!("Prefix: {}", start_pattern.bright_green());
println!("Suffix: {}", end_pattern.bright_green());
println!(
"Checksum: {}",
if use_checksum {
Expand Down Expand Up @@ -260,13 +294,23 @@ fn main() {
"totalAttempts": result.attempts
});

// write to file
// write to file with restricted permissions
std::fs::write(
&filename,
serde_json::to_string_pretty(&json_output).unwrap(),
)
.expect("Unable to write to file");

// Set file permissions to read/write for the owner only
#[cfg(unix)]
{
use std::fs::Permissions;
use std::os::unix::fs::PermissionsExt;

fs::set_permissions(&filename, Permissions::from_mode(0o600))
.expect("Failed to set file permissions");
}

println!(
"{}",
format!(
Expand Down Expand Up @@ -436,3 +480,8 @@ fn calculate_years_to_crack(entropy_bits: usize) -> f64 {
let seconds_to_crack = 2f64.powi(entropy_bits as i32) / guesses_per_second;
seconds_to_crack / (365.25 * 24.0 * 60.0 * 60.0)
}

fn load_config() -> Config {
let config_content = fs::read_to_string("src/config.yml").expect("Failed to read config file");
serde_yaml::from_str(&config_content).expect("Failed to parse config")
}
13 changes: 13 additions & 0 deletions supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[supervisord]
nodaemon=true
user=root

[program:hash_hunter]
command=hash_hunter %(ENV_HASH_HUNTER_ARGS)s
directory=/usr/src/app
autostart=true
autorestart=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0

0 comments on commit 9eb08fb

Please sign in to comment.