mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-14 07:26:51 +00:00
127
Cargo.lock
generated
127
Cargo.lock
generated
@@ -481,6 +481,15 @@ dependencies = [
|
||||
"typenum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "blake2"
|
||||
version = "0.10.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "46502ad458c9a52b69d4d4d32775c788b7a1b85e8bc9d482d92250fc0e3f8efe"
|
||||
dependencies = [
|
||||
"digest 0.10.7",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "blake3"
|
||||
version = "1.5.0"
|
||||
@@ -1248,13 +1257,39 @@ checksum = "1435fa1053d8b2fbbe9be7e97eca7f33d37b28409959813daefc1446a14247f1"
|
||||
name = "drillx"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"enum_dispatch",
|
||||
"num-traits",
|
||||
"num_enum 0.5.11",
|
||||
"blake3",
|
||||
"equix",
|
||||
"solana-program",
|
||||
"strum 0.26.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dynasm"
|
||||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "33dc03612f42465a8ed7f5e354bc2b79ba54cedefa81d5bd3a064f1835adaba8"
|
||||
dependencies = [
|
||||
"bitflags 1.3.2",
|
||||
"byteorder",
|
||||
"lazy_static",
|
||||
"proc-macro-error",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dynasmrt"
|
||||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f7dccc31a678058996aef614f6bd418ced384da70f284e83e2b7bf29b27b6a28"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"dynasm",
|
||||
"fnv",
|
||||
"memmap2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "eager"
|
||||
version = "0.1.0"
|
||||
@@ -1362,18 +1397,6 @@ dependencies = [
|
||||
"syn 2.0.48",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "enum_dispatch"
|
||||
version = "0.3.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "aa18ce2bc66555b3218614519ac839ddb759a7d6720732f979ef8d13be147ecd"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.48",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "env_logger"
|
||||
version = "0.9.3"
|
||||
@@ -1393,6 +1416,19 @@ version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
|
||||
|
||||
[[package]]
|
||||
name = "equix"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e25ed202554ac3bf3c8e5fab352947cc9b5c592e219185351d50fedf2b4213a"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"hashx",
|
||||
"num-traits",
|
||||
"thiserror",
|
||||
"visibility",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "errno"
|
||||
version = "0.3.8"
|
||||
@@ -1433,6 +1469,12 @@ dependencies = [
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fixed-capacity-vec"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6b31a14f5ee08ed1a40e1252b35af18bed062e3f39b69aab34decde36bc43e40"
|
||||
|
||||
[[package]]
|
||||
name = "flate2"
|
||||
version = "1.0.28"
|
||||
@@ -1687,6 +1729,21 @@ version = "0.14.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604"
|
||||
|
||||
[[package]]
|
||||
name = "hashx"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "49d1afec2e9689360a16d9790ac9704c038da4fd04f17890a9ff1c56e536e20a"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"blake2",
|
||||
"dynasmrt",
|
||||
"fixed-capacity-vec",
|
||||
"hex",
|
||||
"rand_core 0.6.4",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.4.1"
|
||||
@@ -1708,6 +1765,12 @@ version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7"
|
||||
|
||||
[[package]]
|
||||
name = "hex"
|
||||
version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
|
||||
|
||||
[[package]]
|
||||
name = "histogram"
|
||||
version = "0.6.9"
|
||||
@@ -2423,15 +2486,6 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num_enum"
|
||||
version = "0.5.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1f646caf906c20226733ed5b1374287eb97e3c2a5c227ce668c1f2ce20ae57c9"
|
||||
dependencies = [
|
||||
"num_enum_derive 0.5.11",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num_enum"
|
||||
version = "0.6.1"
|
||||
@@ -2450,18 +2504,6 @@ dependencies = [
|
||||
"num_enum_derive 0.7.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num_enum_derive"
|
||||
version = "0.5.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dcbff9bc912032c62bf65ef1d5aea88983b420f4f839db1e9b0c281a25c9c799"
|
||||
dependencies = [
|
||||
"proc-macro-crate 1.3.1",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num_enum_derive"
|
||||
version = "0.6.1"
|
||||
@@ -2480,7 +2522,7 @@ version = "0.7.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "681030a937600a36906c185595136d26abfebb4aa9c65701cefcaf8578bb982b"
|
||||
dependencies = [
|
||||
"proc-macro-crate 1.3.1",
|
||||
"proc-macro-crate 3.1.0",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.48",
|
||||
@@ -5685,6 +5727,17 @@ version = "0.9.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
||||
|
||||
[[package]]
|
||||
name = "visibility"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b3fd98999db9227cf28e59d83e1f120f42bc233d4b152e8fab9bc87d5bb1e0f8"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.48",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "void"
|
||||
version = "1.0.2"
|
||||
|
||||
@@ -23,7 +23,7 @@ array-const-fn-init = "0.1.1"
|
||||
bs58 = "0.5.0"
|
||||
bytemuck = "1.14.3"
|
||||
const-crypto = "0.1.0"
|
||||
drillx = { path = "../drillx/drillx" }
|
||||
drillx = { path = "../drillx/drillx", features = ["solana"] }
|
||||
mpl-token-metadata = "4.1.2"
|
||||
num_enum = "0.7.2"
|
||||
shank = "0.3.0"
|
||||
|
||||
@@ -9,7 +9,7 @@ pub const INITIAL_BASE_REWARD_RATE: u64 = 10u64.pow(3u32);
|
||||
pub const INITIAL_TOLERANCE: i64 = 5;
|
||||
|
||||
/// The minimum difficulty required of all submitted hashes.
|
||||
pub const MIN_DIFFICULTY: u32 = 12;
|
||||
pub const MIN_DIFFICULTY: u32 = 8; // 12;
|
||||
|
||||
/// The decimal precision of the Ore token.
|
||||
/// There are 100 billion indivisible units per Ore (called "grains").
|
||||
@@ -24,6 +24,9 @@ pub const ONE_MINUTE: i64 = 60;
|
||||
/// The duration of one day, in seconds.
|
||||
pub const ONE_DAY: i64 = 86400;
|
||||
|
||||
/// The duration of one year, in minutes.
|
||||
pub const ONE_YEAR: u64 = 525600;
|
||||
|
||||
/// The number of minutes in an Ore epoch.
|
||||
pub const EPOCH_MINUTES: i64 = 1;
|
||||
|
||||
@@ -55,10 +58,6 @@ static_assertions::const_assert!(
|
||||
(MAX_EPOCH_REWARDS / BUS_COUNT as u64) * BUS_COUNT as u64 == MAX_EPOCH_REWARDS
|
||||
);
|
||||
|
||||
/// The duration of two years, in minutes.
|
||||
/// Used to calculate the staking reward multiplier.
|
||||
pub const ONE_YEAR: u64 = 60 * 24 * 365;
|
||||
|
||||
/// The seed of the bus account PDA.
|
||||
pub const BUS: &[u8] = b"bus";
|
||||
|
||||
|
||||
14
src/error.rs
14
src/error.rs
@@ -9,18 +9,20 @@ pub enum OreError {
|
||||
IsPaused = 0,
|
||||
#[error("The epoch has ended and needs reset")]
|
||||
NeedsReset = 1,
|
||||
#[error("The provided hash is invalid")]
|
||||
HashInvalid = 2,
|
||||
#[error("The provided hash did not satisfy the minimum required difficulty")]
|
||||
HashTooEasy = 2,
|
||||
HashTooEasy = 3,
|
||||
#[error("The claim amount cannot be greater than the claimable rewards")]
|
||||
ClaimTooLarge = 3,
|
||||
ClaimTooLarge = 4,
|
||||
#[error("The clock time is invalid")]
|
||||
ClockInvalid = 4,
|
||||
ClockInvalid = 5,
|
||||
#[error("Only one hash may be validated per transaction")]
|
||||
TransactionInvalid = 5,
|
||||
TransactionInvalid = 6,
|
||||
#[error("The tolerance cannot exceed i64 max value")]
|
||||
ToleranceOverflow = 6,
|
||||
ToleranceOverflow = 7,
|
||||
#[error("The maximum supply has been reached")]
|
||||
MaxSupply = 7,
|
||||
MaxSupply = 8,
|
||||
}
|
||||
|
||||
impl From<OreError> for ProgramError {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use bytemuck::{Pod, Zeroable};
|
||||
use drillx::Solution;
|
||||
use num_enum::TryFromPrimitive;
|
||||
use shank::ShankInstruction;
|
||||
use solana_program::{
|
||||
@@ -151,6 +152,7 @@ pub struct RegisterArgs {
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
|
||||
pub struct MineArgs {
|
||||
pub digest: [u8; 16],
|
||||
pub nonce: [u8; 8],
|
||||
}
|
||||
|
||||
@@ -273,7 +275,7 @@ pub fn deregister(signer: Pubkey) -> Instruction {
|
||||
}
|
||||
|
||||
/// Builds a mine instruction.
|
||||
pub fn mine(signer: Pubkey, bus: Pubkey, nonce: u64) -> Instruction {
|
||||
pub fn mine(signer: Pubkey, bus: Pubkey, solution: Solution) -> Instruction {
|
||||
let proof = Pubkey::find_program_address(&[PROOF, signer.as_ref()], &crate::id()).0;
|
||||
Instruction {
|
||||
program_id: crate::id(),
|
||||
@@ -288,7 +290,8 @@ pub fn mine(signer: Pubkey, bus: Pubkey, nonce: u64) -> Instruction {
|
||||
data: [
|
||||
OreInstruction::Mine.to_vec(),
|
||||
MineArgs {
|
||||
nonce: nonce.to_le_bytes(),
|
||||
digest: solution.d,
|
||||
nonce: solution.n,
|
||||
}
|
||||
.to_bytes()
|
||||
.to_vec(),
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
use std::mem::size_of;
|
||||
|
||||
use drillx::Solution;
|
||||
#[allow(deprecated)]
|
||||
use solana_program::{
|
||||
account_info::AccountInfo,
|
||||
blake3::hashv,
|
||||
clock::Clock,
|
||||
entrypoint::ProgramResult,
|
||||
keccak::hashv,
|
||||
program_error::ProgramError,
|
||||
pubkey::Pubkey,
|
||||
sanitize::SanitizeError,
|
||||
@@ -88,11 +89,15 @@ pub fn process_mine<'a, 'info>(
|
||||
return Err(OreError::NeedsReset.into());
|
||||
}
|
||||
|
||||
// Calculate the hash from the provided nonce
|
||||
let hx = drillx::hash(&proof.challenge, &args.nonce);
|
||||
// Validate the digest
|
||||
let solution = Solution::new(args.digest, args.nonce);
|
||||
if !solution.is_valid(&proof.challenge) {
|
||||
return Err(OreError::HashInvalid.into());
|
||||
}
|
||||
|
||||
// Validate hash satisfies the minimnum difficulty
|
||||
let difficulty = drillx::difficulty(hx);
|
||||
let hash = solution.to_hash();
|
||||
let difficulty = hash.difficulty();
|
||||
sol_log(&format!("Diff {}", difficulty));
|
||||
if difficulty.lt(&MIN_DIFFICULTY) {
|
||||
return Err(OreError::HashTooEasy.into());
|
||||
@@ -165,7 +170,7 @@ pub fn process_mine<'a, 'info>(
|
||||
|
||||
// Hash recent slot hash into the next challenge to prevent pre-mining attacks
|
||||
proof.challenge = hashv(&[
|
||||
hx.as_slice(),
|
||||
hash.h.as_slice(),
|
||||
&slot_hashes_sysvar.data.borrow()[0..size_of::<SlotHash>()],
|
||||
])
|
||||
.0;
|
||||
|
||||
@@ -2,9 +2,9 @@ use std::mem::size_of;
|
||||
|
||||
use solana_program::{
|
||||
account_info::AccountInfo,
|
||||
blake3::hashv,
|
||||
clock::Clock,
|
||||
entrypoint::ProgramResult,
|
||||
keccak::hashv,
|
||||
program_error::ProgramError,
|
||||
pubkey::Pubkey,
|
||||
slot_hashes::SlotHash,
|
||||
|
||||
Reference in New Issue
Block a user