forked from jprjr/turtlecoin
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUGFIX] LWMA-2 Tweaks, move difficulty to separate file, remove type…
…def (#448) * Make chacha8_key trivially copyable * LWMA-2 Tweaks, move difficulty to separate file, remove typedef * [BUGFIX] Scan height typo (#449) * Make chacha8_key trivially copyable * Fix typo in the wallet service configuration * Update version.h.in * We need <algorithm> for min/max in Windows * Remove un-needed difficulty algorithm
- Loading branch information
1 parent
04130f5
commit 3055107
Showing
21 changed files
with
311 additions
and
342 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright (c) 2012-2017, The CryptoNote developers, The Bytecoin developers | ||
// | ||
// This file is part of Bytecoin. | ||
// | ||
// Bytecoin is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Bytecoin is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with Bytecoin. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
#include <algorithm> | ||
#include <cassert> | ||
#include <cstddef> | ||
#include <cstdint> | ||
#include <vector> | ||
|
||
#include "Common/int-util.h" | ||
#include "crypto/hash.h" | ||
#include "CryptoNoteConfig.h" | ||
#include "CheckDifficulty.h" | ||
|
||
namespace CryptoNote { | ||
|
||
using std::uint64_t; | ||
using std::vector; | ||
|
||
#if defined(__SIZEOF_INT128__) | ||
|
||
static inline void mul(uint64_t a, uint64_t b, uint64_t &low, uint64_t &high) { | ||
typedef unsigned __int128 uint128_t; | ||
uint128_t res = (uint128_t) a * (uint128_t) b; | ||
low = (uint64_t) res; | ||
high = (uint64_t) (res >> 64); | ||
} | ||
|
||
#else | ||
|
||
static inline void mul(uint64_t a, uint64_t b, uint64_t &low, uint64_t &high) { | ||
low = mul128(a, b, &high); | ||
} | ||
|
||
#endif | ||
|
||
static inline bool cadd(uint64_t a, uint64_t b) { | ||
return a + b < a; | ||
} | ||
|
||
static inline bool cadc(uint64_t a, uint64_t b, bool c) { | ||
return a + b < a || (c && a + b == (uint64_t) -1); | ||
} | ||
|
||
bool check_hash(const Crypto::Hash &hash, uint64_t difficulty) { | ||
uint64_t low, high, top, cur; | ||
// First check the highest word, this will most likely fail for a random hash. | ||
mul(swap64le(((const uint64_t *) &hash)[3]), difficulty, top, high); | ||
if (high != 0) { | ||
return false; | ||
} | ||
mul(swap64le(((const uint64_t *) &hash)[0]), difficulty, low, cur); | ||
mul(swap64le(((const uint64_t *) &hash)[1]), difficulty, low, high); | ||
bool carry = cadd(cur, low); | ||
cur = high; | ||
mul(swap64le(((const uint64_t *) &hash)[2]), difficulty, low, high); | ||
carry = cadc(cur, low, carry); | ||
carry = cadc(high, top, carry); | ||
return !carry; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (c) 2012-2017, The CryptoNote developers, The Bytecoin developers | ||
// | ||
// This file is part of Bytecoin. | ||
// | ||
// Bytecoin is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Bytecoin is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with Bytecoin. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
#pragma once | ||
|
||
#include <cstdint> | ||
#include <vector> | ||
|
||
#include "crypto/hash.h" | ||
|
||
namespace CryptoNote { | ||
bool check_hash(const Crypto::Hash &hash, uint64_t difficulty); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.