Electroneum
Toggle main menu visibility
Loading...
Searching...
No Matches
hash-target.cpp
Go to the documentation of this file.
1
// Copyrights(c) 2017-2021, The Electroneum Project
2
// Copyrights(c) 2014-2019, The Monero Project
3
//
4
// All rights reserved.
5
//
6
// Redistribution and use in source and binary forms, with or without modification, are
7
// permitted provided that the following conditions are met:
8
//
9
// 1. Redistributions of source code must retain the above copyright notice, this list of
10
// conditions and the following disclaimer.
11
//
12
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
13
// of conditions and the following disclaimer in the documentation and/or other
14
// materials provided with the distribution.
15
//
16
// 3. Neither the name of the copyright holder nor the names of its contributors may be
17
// used to endorse or promote products derived from this software without specific
18
// prior written permission.
19
//
20
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
21
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
23
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
28
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
//
30
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
31
32
#include <cstdint>
33
#include <cstdlib>
34
#include <cstring>
35
#include <limits>
36
#include "
misc_log_ex.h
"
37
#include "
crypto/hash.h
"
38
#include "
cryptonote_basic/difficulty.h
"
39
40
using namespace
std
;
41
using
cryptonote::check_hash
;
42
43
int
main
(
int
argc,
char
*argv[]) {
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
}
main
int main()
Definition
archivertest.cpp:283
difficulty.h
check_hash
bool check_hash(const crypto::hash &hash, difficulty_type difficulty)
Definition
difficulty.cpp:203
misc_log_ex.h
CATCH_ENTRY_L0
#define CATCH_ENTRY_L0(lacation, return_val)
Definition
misc_log_ex.h:165
TRY_ENTRY
#define TRY_ENTRY()
Definition
misc_log_ex.h:151
crypto::hash
POD_CLASS hash
Definition
hash.h:50
cryptonote::difficulty_type
boost::multiprecision::uint128_t difficulty_type
Definition
difficulty.h:43
cryptonote::check_hash
bool check_hash(const crypto::hash &hash, difficulty_type difficulty)
Definition
difficulty.cpp:203
std
STL namespace.
hash.h
uint16_t
unsigned short uint16_t
Definition
stdint.h:125
uint64_t
unsigned __int64 uint64_t
Definition
stdint.h:136
tests
hash-target.cpp
Generated on
for Electroneum by
1.17.0