Electroneum
Loading...
Searching...
No Matches
hash-target.cpp File Reference
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <limits>
#include "misc_log_ex.h"
#include "crypto/hash.h"
#include "cryptonote_basic/difficulty.h"
Include dependency graph for hash-target.cpp:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
bool check_hash (const crypto::hash &hash, difficulty_type difficulty)

Function Documentation

◆ check_hash()

bool cryptonote::check_hash ( const crypto::hash & hash,
difficulty_type difficulty )

Definition at line 203 of file difficulty.cpp.

203 {
204 if (difficulty <= max64bit) // if can convert to small difficulty - do it
205 return check_hash_64(hash, difficulty.convert_to<std::uint64_t>());
206 else
207 return check_hash_128(hash, difficulty);
208 }
bool check_hash_64(const crypto::hash &hash, uint64_t difficulty)
checks if a hash fits the given difficulty
bool check_hash_128(const crypto::hash &hash, difficulty_type difficulty)
Here is the caller graph for this function:

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 43 of file hash-target.cpp.

43 {
44 TRY_ENTRY();
46 for (cryptonote::difficulty_type diff = 1;; diff += 1 + (diff >> 8)) {
47 for (uint16_t b = 0; b < 256; b++) {
48 memset(&h, b, sizeof(crypto::hash));
49 if (check_hash(h, diff) != (b == 0 || diff <= 255 / b)) {
50 return 1;
51 }
52 if (b > 0) {
53 memset(&h, 0, sizeof(crypto::hash));
54 ((char *) &h)[31] = b;
55 if (check_hash(h, diff) != (diff <= 255 / b)) {
56 return 2;
57 }
58 }
59 }
60 if (diff < numeric_limits<uint64_t>::max() / 256) {
61 uint64_t val = 0;
62 for (int i = 31; i >= 0; i--) {
63 val = val * 256 + 255;
64 ((char *) &h)[i] = static_cast<char>(static_cast<uint64_t>(val / diff));
65 val %= (diff & 0xffffffffffffffff).convert_to<uint64_t>();
66 }
67 if (check_hash(h, diff) != true) {
68 return 3;
69 }
70 if (diff > 1) {
71 for (int i = 0;; i++) {
72 if (i >= 32) {
73 abort();
74 }
75 if (++((char *) &h)[i] != 0) {
76 break;
77 }
78 }
79 if (check_hash(h, diff) != false) {
80 return 4;
81 }
82 }
83 }
84 if (diff + 1 + (diff >> 8) < diff) {
85 break;
86 }
87 }
88 return 0;
89 CATCH_ENTRY_L0("main", 1);
90}
bool check_hash(const crypto::hash &hash, difficulty_type difficulty)
#define CATCH_ENTRY_L0(lacation, return_val)
#define TRY_ENTRY()
POD_CLASS hash
Definition hash.h:50
boost::multiprecision::uint128_t difficulty_type
Definition difficulty.h:43
unsigned short uint16_t
Definition stdint.h:125
unsigned __int64 uint64_t
Definition stdint.h:136
Here is the call graph for this function: