From 3492feef677604fbd894a6bea6f5bdeffc331507 Mon Sep 17 00:00:00 2001 From: Hardhat Chad Date: Wed, 7 May 2025 17:00:00 -0700 Subject: [PATCH] keccak --- Cargo.lock | 7 +++---- Cargo.toml | 2 +- api/Cargo.toml | 1 - api/src/instruction.rs | 2 +- api/src/sdk.rs | 7 +++---- program/src/mine.rs | 21 ++++++++------------- 6 files changed, 16 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cb43745..932d8e5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1266,12 +1266,11 @@ dependencies = [ [[package]] name = "ore-api" -version = "3.6.0" +version = "3.7.0" dependencies = [ "array-const-fn-init", "bytemuck", "const-crypto", - "drillx", "mpl-token-metadata", "num_enum", "solana-program", @@ -1304,11 +1303,11 @@ dependencies = [ [[package]] name = "ore-program" -version = "3.6.0" +version = "3.7.0" dependencies = [ "drillx", "mpl-token-metadata", - "ore-api 3.6.0", + "ore-api 3.7.0", "ore-boost-api", "rand 0.8.5", "solana-program", diff --git a/Cargo.toml b/Cargo.toml index 6dea0b5..9372964 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ resolver = "2" members = ["api", "program"] [workspace.package] -version = "3.6.0" +version = "3.7.0" edition = "2021" license = "Apache-2.0" homepage = "https://ore.supply" diff --git a/api/Cargo.toml b/api/Cargo.toml index 2faf7c7..09d136d 100644 --- a/api/Cargo.toml +++ b/api/Cargo.toml @@ -13,7 +13,6 @@ keywords.workspace = true array-const-fn-init.workspace = true bytemuck.workspace = true const-crypto.workspace = true -drillx.workspace = true mpl-token-metadata.workspace = true num_enum.workspace = true solana-program.workspace = true diff --git a/api/src/instruction.rs b/api/src/instruction.rs index 785dbb3..2ae122a 100644 --- a/api/src/instruction.rs +++ b/api/src/instruction.rs @@ -28,7 +28,7 @@ pub struct Close {} #[repr(C)] #[derive(Clone, Copy, Debug, Pod, Zeroable)] pub struct Mine { - pub digest: [u8; 16], + // pub digest: [u8; 16], pub nonce: [u8; 8], } diff --git a/api/src/sdk.rs b/api/src/sdk.rs index a00d51d..de99c2c 100644 --- a/api/src/sdk.rs +++ b/api/src/sdk.rs @@ -1,4 +1,3 @@ -use drillx::Solution; use steel::*; use crate::{ @@ -55,7 +54,7 @@ pub fn mine( signer: Pubkey, authority: Pubkey, bus: Pubkey, - solution: Solution, + nonce: u64, boost_config: Pubkey, ) -> Instruction { let proof = proof_pda(authority).0; @@ -73,8 +72,8 @@ pub fn mine( program_id: crate::ID, accounts, data: Mine { - digest: solution.d, - nonce: solution.n, + // digest: solution.d, + nonce: nonce.to_le_bytes(), } .to_bytes(), } diff --git a/program/src/mine.rs b/program/src/mine.rs index 573f93a..aa337c8 100644 --- a/program/src/mine.rs +++ b/program/src/mine.rs @@ -1,10 +1,10 @@ use std::mem::size_of; -use drillx::Solution; +use drillx::difficulty; use ore_api::prelude::*; use ore_boost_api::{consts::DENOMINATOR_BPS, state::Config as BoostConfig}; use solana_program::{ - keccak::hashv, + keccak::{self, hashv}, sanitize::SanitizeError, serialize_utils::{read_pubkey, read_u16}, slot_hashes::SlotHash, @@ -68,21 +68,16 @@ pub fn process_mine(accounts: &[AccountInfo], data: &[u8]) -> ProgramResult { return Err(OreError::Spam.into()); } - // Validate the hash digest. + // Compute the hash. // - // Here we use drillx to validate the provided solution is a valid hash of the challenge. - // If invalid, we return an error. - let solution = Solution::new(args.digest, args.nonce); - if !solution.is_valid(&proof.challenge) { - return Err(OreError::HashInvalid.into()); - } + // Here we use simple keccak. + let solution = keccak::hashv(&[proof.challenge.as_slice(), args.nonce.as_slice()]); // Validate the hash satisfies the minimum difficulty. // // We use drillx to get the difficulty (leading zeros) of the hash. If the hash does not have the // minimum required difficulty, we reject it with an error. - let hash = solution.to_hash(); - let difficulty = hash.difficulty(); + let difficulty = difficulty(solution.0); if difficulty < config.min_difficulty as u32 { return Err(OreError::HashTooEasy.into()); } @@ -158,9 +153,9 @@ pub fn process_mine(accounts: &[AccountInfo], data: &[u8]) -> ProgramResult { // // The slot hashes are unpredictable values. By seeding the next challenge with the most recent slot hash, // miners are forced to submit their current solution before they can begin mining for the next. - proof.last_hash = hash.h; + proof.last_hash = solution.0; proof.challenge = hashv(&[ - hash.h.as_slice(), + solution.0.as_slice(), &slot_hashes_sysvar.data.borrow()[0..size_of::()], ]) .0;