diff --git a/Cargo.lock b/Cargo.lock index a0864c570c..b0ec5a5b5d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -660,6 +660,7 @@ dependencies = [ "blake2b_simd", "byteorder", "cc", + "hex", ] [[package]] diff --git a/components/equihash/Cargo.toml b/components/equihash/Cargo.toml index 5998e54cd0..a4d3403134 100644 --- a/components/equihash/Cargo.toml +++ b/components/equihash/Cargo.toml @@ -16,5 +16,8 @@ byteorder = "1" [build-dependencies] cc = "1" +[dev-dependencies] +hex = "0.4" + [lib] bench = false diff --git a/components/equihash/src/tromp.rs b/components/equihash/src/tromp.rs index 22d9f27aa1..b3d9a5af94 100644 --- a/components/equihash/src/tromp.rs +++ b/components/equihash/src/tromp.rs @@ -275,13 +275,14 @@ mod tests { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ]; - let mut nonces = 2400..=u16::MAX; + let mut nonces = 0..=32_u32; + let nonce_count = nonces.clone().count(); let solutions = solve_200_9_compressed(input, || { let variable_nonce = nonces.next()?; println!("Using variable nonce [0..4] of {}", variable_nonce); - let variable_nonce = variable_nonce.to_be_bytes(); + let variable_nonce = variable_nonce.to_le_bytes(); nonce[0] = variable_nonce[0]; nonce[1] = variable_nonce[1]; nonce[2] = variable_nonce[2]; @@ -291,22 +292,23 @@ mod tests { }); if solutions.is_empty() { - println!("Found no solutions"); + // Expected solution rate is documented at: + // https://github.com/tromp/equihash/blob/master/README.md + panic!("Found no solutions after {nonce_count} runs, expected 1.88 solutions per run",); } else { println!("Found {} solutions:", solutions.len()); - for solution in solutions { - println!("- {:?}", solution); - crate::is_valid_solution(200, 9, input, &nonce, &solution).unwrap_or_else( - |error| { - panic!( - "unexpected invalid equihash 200, 9 solution:\n\ + for (sol_num, solution) in solutions.iter().enumerate() { + println!("Validating solution {sol_num}:-\n{}", hex::encode(solution)); + crate::is_valid_solution(200, 9, input, &nonce, solution).unwrap_or_else(|error| { + panic!( + "unexpected invalid equihash 200, 9 solution:\n\ error: {error:?}\n\ input: {input:?}\n\ nonce: {nonce:?}\n\ solution: {solution:?}" - ) - }, - ); + ) + }); + println!("Solution {sol_num} is valid!\n"); } } }