|
|
@@ -38,7 +38,7 @@ use crate::{
|
|
|
|
|
|
/// Max 32 bytes integer, used in rank calculations.
|
|
|
/// Cached to avoid repeated allocation.
|
|
|
-static MAX_32_BYTES: LazyLock<BigUint> = LazyLock::new(|| BigUint::from_bytes_le(&[0xFF; 32]));
|
|
|
+pub static MAX_32_BYTES: LazyLock<BigUint> = LazyLock::new(|| BigUint::from_bytes_le(&[0xFF; 32]));
|
|
|
|
|
|
/// Deploy DarkFi native wasm contracts to provided blockchain overlay.
|
|
|
///
|
|
|
@@ -159,11 +159,8 @@ pub fn block_rank(block: &BlockInfo, target: &BigUint) -> Result<(BigUint, BigUi
|
|
|
return Ok((0u64.into(), 0u64.into()))
|
|
|
}
|
|
|
|
|
|
- // Grab the max 32 bytes int
|
|
|
- let max = &*MAX_32_BYTES;
|
|
|
-
|
|
|
// Compute the squared mining target distance
|
|
|
- let target_distance = max - target;
|
|
|
+ let target_distance = &*MAX_32_BYTES - target;
|
|
|
let target_distance_sq = &target_distance * &target_distance;
|
|
|
|
|
|
// Setup RandomX verifier
|
|
|
@@ -174,7 +171,7 @@ pub fn block_rank(block: &BlockInfo, target: &BigUint) -> Result<(BigUint, BigUi
|
|
|
// Compute the output hash distance
|
|
|
let out_hash = vm.calculate_hash(block.hash().inner())?;
|
|
|
let out_hash = BigUint::from_bytes_le(&out_hash);
|
|
|
- let hash_distance = max - out_hash;
|
|
|
+ let hash_distance = &*MAX_32_BYTES - out_hash;
|
|
|
let hash_distance_sq = &hash_distance * &hash_distance;
|
|
|
|
|
|
Ok((target_distance_sq, hash_distance_sq))
|