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 ///
18 /// Returns `(proof_result, actual_hashes)` where `actual_hashes` is the
19 /// number of hashes actually computed (may be less than `lanes` when the
20 /// backend exits early after finding a proof).
21 fn find_proof_batch(
22 &mut self,
23 header_without_nonce: &[u8],
24 start_nonce: u64,
25 lanes: usize,
26 difficulty: u32,
27 ) -> Result<(ProofResult, usize)>;
28
29 /// Run benchmark: hash `lanes` nonces starting from `start_nonce`.
30 /// Returns number of hashes computed.
31 fn benchmark_hashes(
32 &mut self,
33 header_without_nonce: &[u8],
34 start_nonce: u64,
35 lanes: usize,
36 ) -> Result<usize>;
37}