From 5c27bd3d00145b658d4c7d27d20498d5d9ed2184 Mon Sep 17 00:00:00 2001 From: Hardhat Chad Date: Tue, 15 Oct 2024 21:27:06 +0000 Subject: [PATCH] move spam check up in logic --- program/src/mine.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/program/src/mine.rs b/program/src/mine.rs index fa7963b..6eb1ba2 100644 --- a/program/src/mine.rs +++ b/program/src/mine.rs @@ -53,15 +53,6 @@ pub fn process_mine(accounts: &[AccountInfo], data: &[u8]) -> ProgramResult { return Err(OreError::NeedsReset.into()); } - // Validate the hash digest. - // - // 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()); - } - // Reject spam transactions. // // If a miner attempts to submit solutions too frequently, we reject with an error. In general, @@ -73,6 +64,15 @@ pub fn process_mine(accounts: &[AccountInfo], data: &[u8]) -> ProgramResult { return Err(OreError::Spam.into()); } + // Validate the hash digest. + // + // 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()); + } + // 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