hash-of-wisdom/cmd/cpu-burner/main.go

112 lines
3 KiB
Go
Raw Normal View History

2025-08-22 15:50:52 +03:00
package main
import (
"context"
"fmt"
"log"
"runtime"
"time"
"hash-of-wisdom/internal/pow/challenge"
"hash-of-wisdom/internal/pow/solver"
)
func main() {
fmt.Println("🔥 Hash of Wisdom - CPU Burner Challenge 🔥")
fmt.Printf("Available CPU cores: %d\n", runtime.NumCPU())
// Create config with brutal difficulty
config, err := challenge.NewConfig(
challenge.WithDefaultDifficulty(30), // This will require ~1 BILLION hash attempts on average
challenge.WithMinDifficulty(25),
challenge.WithMaxDifficulty(32),
challenge.WithRandomBytes(8),
)
if err != nil {
log.Fatalf("Failed to create config: %v", err)
}
// Generate the brutal challenge
generator := challenge.NewGenerator(config)
ch, err := generator.GenerateChallenge()
if err != nil {
log.Fatalf("Failed to generate challenge: %v", err)
}
fmt.Printf("\n💀 Generated BRUTAL challenge with difficulty %d bits\n", ch.Difficulty)
fmt.Printf("Expected attempts: ~%.0f\n", float64(uint64(1)<<uint(ch.Difficulty)))
fmt.Printf("Random: %x\n", ch.Random)
fmt.Printf("Resource: %s\n", ch.Resource)
// Create solver with all available CPU cores
s := solver.NewSolver(solver.WithWorkers(runtime.NumCPU()))
fmt.Printf("\n🚀 Starting solve with %d workers...\n", runtime.NumCPU())
fmt.Println("Press Ctrl+C to cancel if it takes too long!")
// Start timing
start := time.Now()
// Set a longer timeout for the brutal difficulty (15 minutes max)
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Minute)
defer cancel()
// Track progress with goroutine
done := make(chan bool, 1)
go func() {
ticker := time.NewTicker(5 * time.Second)
defer ticker.Stop()
for {
select {
case <-ticker.C:
elapsed := time.Since(start)
fmt.Printf("⏰ Still working... elapsed: %v\n", elapsed.Truncate(time.Second))
case <-done:
return
case <-ctx.Done():
return
}
}
}()
// SOLVE IT!
solution, err := s.Solve(ctx, ch)
done <- true
elapsed := time.Since(start)
if err != nil {
if err == context.DeadlineExceeded {
fmt.Printf("\n⏰ Timeout after %v - difficulty %d was too brutal!\n", elapsed, ch.Difficulty)
fmt.Println("Try reducing difficulty in the code if you want to see a solution.")
} else {
log.Fatalf("Solve failed: %v", err)
}
return
}
// SUCCESS!
fmt.Printf("\n🎉 SOLVED! Found nonce: %d\n", solution.Nonce)
fmt.Printf("⚡ Time taken: %v\n", elapsed)
fmt.Printf("🔥 Hash rate: %.2f attempts/sec\n", float64(solution.Nonce)/elapsed.Seconds())
// Verify the solution
if solution.Verify() {
fmt.Printf("✅ Solution verified successfully!\n")
} else {
fmt.Printf("❌ Solution verification failed!\n")
}
// Show the winning hash
solutionStr := ch.BuildSolutionString(solution.Nonce)
fmt.Printf("🏆 Winning solution string: %s\n", solutionStr)
// Show CPU usage info
var m runtime.MemStats
runtime.ReadMemStats(&m)
fmt.Printf("💾 Memory used: %d KB\n", m.Alloc/1024)
fmt.Printf("\n🔥 Your CPU should be nice and toasty now! 🔥\n")
}