mirror of
https://github.com/d0zingcat/ore.git
synced 2026-06-09 07:36:52 +00:00
keccak
This commit is contained in:
7
Cargo.lock
generated
7
Cargo.lock
generated
@@ -1266,12 +1266,11 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ore-api"
|
name = "ore-api"
|
||||||
version = "3.6.0"
|
version = "3.7.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"array-const-fn-init",
|
"array-const-fn-init",
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
"const-crypto",
|
"const-crypto",
|
||||||
"drillx",
|
|
||||||
"mpl-token-metadata",
|
"mpl-token-metadata",
|
||||||
"num_enum",
|
"num_enum",
|
||||||
"solana-program",
|
"solana-program",
|
||||||
@@ -1304,11 +1303,11 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ore-program"
|
name = "ore-program"
|
||||||
version = "3.6.0"
|
version = "3.7.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"drillx",
|
"drillx",
|
||||||
"mpl-token-metadata",
|
"mpl-token-metadata",
|
||||||
"ore-api 3.6.0",
|
"ore-api 3.7.0",
|
||||||
"ore-boost-api",
|
"ore-boost-api",
|
||||||
"rand 0.8.5",
|
"rand 0.8.5",
|
||||||
"solana-program",
|
"solana-program",
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ resolver = "2"
|
|||||||
members = ["api", "program"]
|
members = ["api", "program"]
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "3.6.0"
|
version = "3.7.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
homepage = "https://ore.supply"
|
homepage = "https://ore.supply"
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ keywords.workspace = true
|
|||||||
array-const-fn-init.workspace = true
|
array-const-fn-init.workspace = true
|
||||||
bytemuck.workspace = true
|
bytemuck.workspace = true
|
||||||
const-crypto.workspace = true
|
const-crypto.workspace = true
|
||||||
drillx.workspace = true
|
|
||||||
mpl-token-metadata.workspace = true
|
mpl-token-metadata.workspace = true
|
||||||
num_enum.workspace = true
|
num_enum.workspace = true
|
||||||
solana-program.workspace = true
|
solana-program.workspace = true
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ pub struct Close {}
|
|||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
|
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
|
||||||
pub struct Mine {
|
pub struct Mine {
|
||||||
pub digest: [u8; 16],
|
// pub digest: [u8; 16],
|
||||||
pub nonce: [u8; 8],
|
pub nonce: [u8; 8],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
use drillx::Solution;
|
|
||||||
use steel::*;
|
use steel::*;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -55,7 +54,7 @@ pub fn mine(
|
|||||||
signer: Pubkey,
|
signer: Pubkey,
|
||||||
authority: Pubkey,
|
authority: Pubkey,
|
||||||
bus: Pubkey,
|
bus: Pubkey,
|
||||||
solution: Solution,
|
nonce: u64,
|
||||||
boost_config: Pubkey,
|
boost_config: Pubkey,
|
||||||
) -> Instruction {
|
) -> Instruction {
|
||||||
let proof = proof_pda(authority).0;
|
let proof = proof_pda(authority).0;
|
||||||
@@ -73,8 +72,8 @@ pub fn mine(
|
|||||||
program_id: crate::ID,
|
program_id: crate::ID,
|
||||||
accounts,
|
accounts,
|
||||||
data: Mine {
|
data: Mine {
|
||||||
digest: solution.d,
|
// digest: solution.d,
|
||||||
nonce: solution.n,
|
nonce: nonce.to_le_bytes(),
|
||||||
}
|
}
|
||||||
.to_bytes(),
|
.to_bytes(),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
use std::mem::size_of;
|
use std::mem::size_of;
|
||||||
|
|
||||||
use drillx::Solution;
|
use drillx::difficulty;
|
||||||
use ore_api::prelude::*;
|
use ore_api::prelude::*;
|
||||||
use ore_boost_api::{consts::DENOMINATOR_BPS, state::Config as BoostConfig};
|
use ore_boost_api::{consts::DENOMINATOR_BPS, state::Config as BoostConfig};
|
||||||
use solana_program::{
|
use solana_program::{
|
||||||
keccak::hashv,
|
keccak::{self, hashv},
|
||||||
sanitize::SanitizeError,
|
sanitize::SanitizeError,
|
||||||
serialize_utils::{read_pubkey, read_u16},
|
serialize_utils::{read_pubkey, read_u16},
|
||||||
slot_hashes::SlotHash,
|
slot_hashes::SlotHash,
|
||||||
@@ -68,21 +68,16 @@ pub fn process_mine(accounts: &[AccountInfo], data: &[u8]) -> ProgramResult {
|
|||||||
return Err(OreError::Spam.into());
|
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.
|
// Here we use simple keccak.
|
||||||
// If invalid, we return an error.
|
let solution = keccak::hashv(&[proof.challenge.as_slice(), args.nonce.as_slice()]);
|
||||||
let solution = Solution::new(args.digest, args.nonce);
|
|
||||||
if !solution.is_valid(&proof.challenge) {
|
|
||||||
return Err(OreError::HashInvalid.into());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate the hash satisfies the minimum difficulty.
|
// 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
|
// 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.
|
// minimum required difficulty, we reject it with an error.
|
||||||
let hash = solution.to_hash();
|
let difficulty = difficulty(solution.0);
|
||||||
let difficulty = hash.difficulty();
|
|
||||||
if difficulty < config.min_difficulty as u32 {
|
if difficulty < config.min_difficulty as u32 {
|
||||||
return Err(OreError::HashTooEasy.into());
|
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,
|
// 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.
|
// 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(&[
|
proof.challenge = hashv(&[
|
||||||
hash.h.as_slice(),
|
solution.0.as_slice(),
|
||||||
&slot_hashes_sysvar.data.borrow()[0..size_of::<SlotHash>()],
|
&slot_hashes_sysvar.data.borrow()[0..size_of::<SlotHash>()],
|
||||||
])
|
])
|
||||||
.0;
|
.0;
|
||||||
|
|||||||
Reference in New Issue
Block a user