no-std keccak

This commit is contained in:
Hardhat Chad
2025-06-06 13:42:29 -07:00
parent 77bccc3e2c
commit 09ff016280
4 changed files with 19 additions and 4 deletions

10
Cargo.lock generated
View File

@@ -1338,6 +1338,7 @@ dependencies = [
"ore-api 3.7.0",
"ore-boost-api",
"rand 0.8.5",
"solana-nostd-keccak",
"solana-program",
"spl-associated-token-account",
"spl-token 4.0.2",
@@ -1973,6 +1974,15 @@ version = "2.1.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49f626d3d461a623d7f8131fc4eedaed186e0f63c6f388b5ca782cdfcc8326e0"
[[package]]
name = "solana-nostd-keccak"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8ced70920435b1baa58f76e6f84bbc1110ddd1d6161ec76b6d731ae8431e9c4"
dependencies = [
"sha3",
]
[[package]]
name = "solana-packet"
version = "2.1.15"

View File

@@ -25,6 +25,7 @@ ore-api = { path = "./ore/api" }
ore-delegate-api = { path = "./ore-delegate/api" }
ore-boost-api = "4.0.0-alpha"
solana-account-decoder = "^2.1"
solana-nostd-keccak = "0.1.3"
solana-program = "^2.1"
solana-client = "^2.1"
solana-sdk = "^2.1"

View File

@@ -22,6 +22,7 @@ bincode.workspace = true
mpl-token-metadata.workspace = true
ore-api.workspace = true
ore-boost-api.workspace = true
solana-nostd-keccak.workspace = true
solana-program.workspace = true
spl-token.workspace = true
spl-token-2022.workspace = true

View File

@@ -1,5 +1,6 @@
use ore_api::prelude::*;
use solana_program::{keccak, slot_hashes::SlotHashes};
use solana_nostd_keccak::hash;
use solana_program::slot_hashes::SlotHashes;
use steel::*;
/// Mine a block.
@@ -75,13 +76,15 @@ pub fn process_mine(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
// Reset miner hash if mining new block.
if miner.block_id != block.id {
miner.block_id = block.id;
miner.hash =
keccak::hashv(&[block.slot_hash.as_ref(), miner.authority.as_ref()]).to_bytes();
let mut args = [0u8; 64];
args[..32].copy_from_slice(&block.slot_hash);
args[32..].copy_from_slice(&miner.authority.to_bytes());
miner.hash = hash(&args);
}
// Mine.
for _ in 0..amount {
miner.hash = keccak::hashv(&[miner.hash.as_ref()]).to_bytes();
miner.hash = hash(miner.hash.as_ref());
if miner.hash < block.best_hash {
block.best_hash = miner.hash;
block.best_miner = miner.authority;