Add test showing bug in IsProbablyDuplicate()
This commit is contained in:
parent
eeb4177843
commit
fa19e1b357
|
@ -317,28 +317,6 @@ bool Equihash<N,K>::BasicSolve(const eh_HashState& base_state,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<size_t MAX_INDICES>
|
|
||||||
bool IsProbablyDuplicate(std::shared_ptr<eh_trunc> indices, size_t lenIndices)
|
|
||||||
{
|
|
||||||
assert(lenIndices <= MAX_INDICES);
|
|
||||||
bool checked_index[MAX_INDICES] = {false};
|
|
||||||
bool count_checked = 0;
|
|
||||||
for (int z = 0; z < lenIndices; z++) {
|
|
||||||
// Skip over indices we have already paired
|
|
||||||
if (!checked_index[z]) {
|
|
||||||
for (int y = z+1; y < lenIndices; y++) {
|
|
||||||
if (!checked_index[y] && indices.get()[z] == indices.get()[y]) {
|
|
||||||
// Pair found
|
|
||||||
checked_index[y] = true;
|
|
||||||
count_checked += 2;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return count_checked == lenIndices;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<size_t WIDTH>
|
template<size_t WIDTH>
|
||||||
void CollideBranches(std::vector<FullStepRow<WIDTH>>& X, const size_t hlen, const size_t lenIndices, const unsigned int clen, const unsigned int ilen, const eh_trunc lt, const eh_trunc rt)
|
void CollideBranches(std::vector<FullStepRow<WIDTH>>& X, const size_t hlen, const size_t lenIndices, const unsigned int clen, const unsigned int ilen, const eh_trunc lt, const eh_trunc rt)
|
||||||
{
|
{
|
||||||
|
|
|
@ -22,6 +22,28 @@ bool DistinctIndices(const FullStepRow<WIDTH>& a, const FullStepRow<WIDTH>& b, s
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<size_t MAX_INDICES>
|
||||||
|
bool IsProbablyDuplicate(std::shared_ptr<eh_trunc> indices, size_t lenIndices)
|
||||||
|
{
|
||||||
|
assert(lenIndices <= MAX_INDICES);
|
||||||
|
bool checked_index[MAX_INDICES] = {false};
|
||||||
|
bool count_checked = 0;
|
||||||
|
for (int z = 0; z < lenIndices; z++) {
|
||||||
|
// Skip over indices we have already paired
|
||||||
|
if (!checked_index[z]) {
|
||||||
|
for (int y = z+1; y < lenIndices; y++) {
|
||||||
|
if (!checked_index[y] && indices.get()[z] == indices.get()[y]) {
|
||||||
|
// Pair found
|
||||||
|
checked_index[y] = true;
|
||||||
|
count_checked += 2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count_checked == lenIndices;
|
||||||
|
}
|
||||||
|
|
||||||
template<size_t WIDTH>
|
template<size_t WIDTH>
|
||||||
bool IsValidBranch(const FullStepRow<WIDTH>& a, const size_t len, const unsigned int ilen, const eh_trunc t)
|
bool IsValidBranch(const FullStepRow<WIDTH>& a, const size_t len, const unsigned int ilen, const eh_trunc t)
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,6 +3,16 @@
|
||||||
|
|
||||||
#include "crypto/equihash.h"
|
#include "crypto/equihash.h"
|
||||||
|
|
||||||
|
TEST(equihash_tests, is_probably_duplicate) {
|
||||||
|
std::shared_ptr<eh_trunc> p1 (new eh_trunc[4] {0, 1, 2, 3});
|
||||||
|
std::shared_ptr<eh_trunc> p2 (new eh_trunc[4] {0, 1, 1, 3});
|
||||||
|
std::shared_ptr<eh_trunc> p3 (new eh_trunc[4] {3, 1, 1, 3});
|
||||||
|
|
||||||
|
ASSERT_FALSE(IsProbablyDuplicate<4>(p1, 4));
|
||||||
|
ASSERT_FALSE(IsProbablyDuplicate<4>(p2, 4));
|
||||||
|
ASSERT_TRUE(IsProbablyDuplicate<4>(p3, 4));
|
||||||
|
}
|
||||||
|
|
||||||
TEST(equihash_tests, check_basic_solver_cancelled) {
|
TEST(equihash_tests, check_basic_solver_cancelled) {
|
||||||
Equihash<48,5> Eh48_5;
|
Equihash<48,5> Eh48_5;
|
||||||
crypto_generichash_blake2b_state state;
|
crypto_generichash_blake2b_state state;
|
||||||
|
|
Loading…
Reference in New Issue