Electroneum
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[])
 

Function Documentation

◆ main()

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

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

43  {
44  TRY_ENTRY();
45  crypto::hash h;
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 }
unsigned short uint16_t
Definition: stdint.h:125
#define TRY_ENTRY()
Definition: misc_log_ex.h:151
bool check_hash(const crypto::hash &hash, difficulty_type difficulty)
Definition: difficulty.cpp:203
unsigned __int64 uint64_t
Definition: stdint.h:136
boost::multiprecision::uint128_t difficulty_type
Definition: difficulty.h:43
POD_CLASS hash
Definition: hash.h:50
#define CATCH_ENTRY_L0(lacation, return_val)
Definition: misc_log_ex.h:165
Here is the call graph for this function: