Skip to content

Commit

Permalink
drillx interpretted
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmizz committed Feb 26, 2025
1 parent 46b9e01 commit 978752b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ desktop = [
"env_logger",
"solana-account-decoder",
"solana-client",
"solana-program",
"solana-transaction-status",
"spl-associated-token-account",
"spl-memo",
Expand Down Expand Up @@ -107,6 +108,7 @@ solana-sdk = "2.1"
solana-client = { version = "2.1", optional = true }
solana-account-decoder = { version = "2.1", optional = true }
solana-transaction-status = { version = "2.1", optional = true }
solana-program = { version = "2.1", optional = true }
spl-associated-token-account = { version = "^6", optional = true, features = [
"no-entrypoint",
] }
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/miner/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod use_miner;
mod use_miner_events;
#[cfg(not(feature = "web"))]
// #[cfg(not(feature = "web"))]
mod use_miner_native;
#[cfg(feature = "web")]
mod use_miner_web;
Expand Down
43 changes: 40 additions & 3 deletions src/hooks/miner/use_miner_native.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use dioxus::prelude::*;

use anyhow::Result;
use drillx::Solution;
use drillx::{equix, Solution};
use futures::StreamExt;
use ore_miner_types::{InputMessage, OutputMessage};

Expand Down Expand Up @@ -98,8 +98,7 @@ async fn find_hash_par(
let mut best_difficulty = 0;
loop {
// get hashes
let hxs =
drillx::hashes_with_memory(&mut memory, &challenge, &nonce.to_le_bytes());
let hxs = solve(&mut memory, &challenge, &nonce.to_le_bytes());
// look for best difficulty score in all hashes
for hx in hxs {
let difficulty = hx.difficulty();
Expand Down Expand Up @@ -183,6 +182,44 @@ fn nonce_indices(
Ok(nonce_indices)
}

#[inline(always)]
fn solve(
mem: &mut equix::SolverMemory,
challenge: &[u8; 32],
nonce: &[u8; 8],
) -> Vec<drillx::Hash> {
let mut hashes = Vec::with_capacity(7);
let seed = drillx::seed(challenge, nonce);
let solver = drillx::equix::EquiXBuilder::new()
.runtime(drillx::equix::RuntimeOption::InterpretOnly)
.build(seed.as_slice());
if let Ok(solver) = solver {
let solutions = solver.solve_with_memory(mem);
for solution in solutions {
let digest = solution.to_bytes();
hashes.push(drillx::Hash {
d: digest,
h: hashv(&digest, nonce),
});
}
}
hashes
}

#[inline(always)]
fn hashv(digest: &[u8; 16], nonce: &[u8; 8]) -> [u8; 32] {
solana_program::keccak::hashv(&[sorted(*digest).as_slice(), &nonce.as_slice()]).to_bytes()
}

#[inline(always)]
fn sorted(mut digest: [u8; 16]) -> [u8; 16] {
unsafe {
let u16_slice: &mut [u16; 8] = core::mem::transmute(&mut digest);
u16_slice.sort_unstable();
digest
}
}

fn format_duration(seconds: u32) -> String {
let minutes = seconds / 60;
let remaining_seconds = seconds % 60;
Expand Down

0 comments on commit 978752b

Please sign in to comment.