uhash_prover/solver.rs
1//! Unified solver trait for all backends (CPU/GPU).
2
3use anyhow::Result;
4
5/// Result of a successful proof search: (nonce, hash).
6pub type ProofResult = Option<(u64, [u8; 32])>;
7
8/// Backend-agnostic solver interface.
9pub trait Solver {
10 /// Human-readable backend name ("cpu", "cuda", "metal", etc.)
11 fn backend_name(&self) -> &'static str;
12
13 /// Recommend optimal lane count for this backend.
14 fn recommended_lanes(&mut self, requested: usize) -> usize;
15
16 /// Search for a valid proof in a batch of nonces starting at `start_nonce`.
17 fn find_proof_batch(
18 &mut self,
19 header_without_nonce: &[u8],
20 start_nonce: u64,
21 lanes: usize,
22 difficulty: u32,
23 ) -> Result<ProofResult>;
24
25 /// Run benchmark: hash `lanes` nonces starting from `start_nonce`.
26 /// Returns number of hashes computed.
27 fn benchmark_hashes(
28 &mut self,
29 header_without_nonce: &[u8],
30 start_nonce: u64,
31 lanes: usize,
32 ) -> Result<usize>;
33}