Auto merge of #1048 - str4d:collect-all-valid-equihash-solns, r=ebfull

Collect all permutations of final solutions

This fixes a small bug where if there was a three-way (or more) collision in the final step, one or more valid solutions would be left out.
This commit is contained in:
zkbot 2016-07-20 03:54:30 +00:00
commit e117ff7651
2 changed files with 40 additions and 8 deletions

View File

@ -268,11 +268,24 @@ std::set<std::vector<eh_index>> Equihash<N,K>::BasicSolve(const eh_HashState& ba
LogPrint("pow", "- Sorting list\n");
std::sort(X.begin(), X.end(), CompareSR(hashLen));
LogPrint("pow", "- Finding collisions\n");
for (int i = 0; i < X.size() - 1; i++) {
FullStepRow<FinalFullWidth> res(X[i], X[i+1], hashLen, lenIndices, 0);
if (res.IsZero(hashLen) && DistinctIndices(X[i], X[i+1], hashLen, lenIndices)) {
solns.insert(res.GetIndices(hashLen, 2*lenIndices));
int i = 0;
while (i < X.size() - 1) {
int j = 1;
while (i+j < X.size() &&
HasCollision(X[i], X[i+j], hashLen)) {
j++;
}
for (int l = 0; l < j - 1; l++) {
for (int m = l + 1; m < j; m++) {
FullStepRow<FinalFullWidth> res(X[i+l], X[i+m], hashLen, lenIndices, 0);
if (DistinctIndices(X[i+l], X[i+m], hashLen, lenIndices)) {
solns.insert(res.GetIndices(hashLen, 2*lenIndices));
}
}
}
i += j;
}
} else
LogPrint("pow", "- List is empty\n");
@ -416,11 +429,22 @@ std::set<std::vector<eh_index>> Equihash<N,K>::OptimisedSolve(const eh_HashState
LogPrint("pow", "- Sorting list\n");
std::sort(Xt.begin(), Xt.end(), CompareSR(hashLen));
LogPrint("pow", "- Finding collisions\n");
for (int i = 0; i < Xt.size() - 1; i++) {
TruncatedStepRow<FinalTruncatedWidth> res(Xt[i], Xt[i+1], hashLen, lenIndices, 0);
if (res.IsZero(hashLen)) {
partialSolns.push_back(res.GetTruncatedIndices(hashLen, 2*lenIndices));
int i = 0;
while (i < Xt.size() - 1) {
int j = 1;
while (i+j < Xt.size() &&
HasCollision(Xt[i], Xt[i+j], hashLen)) {
j++;
}
for (int l = 0; l < j - 1; l++) {
for (int m = l + 1; m < j; m++) {
TruncatedStepRow<FinalTruncatedWidth> res(Xt[i+l], Xt[i+m], hashLen, lenIndices, 0);
partialSolns.push_back(res.GetTruncatedIndices(hashLen, 2*lenIndices));
}
}
i += j;
}
} else
LogPrint("pow", "- List is empty\n");

View File

@ -119,6 +119,14 @@ BOOST_AUTO_TEST_CASE(solver_testvectors) {
{637, 78032, 97478, 118268, 16058, 44395, 19029, 39150, 1566, 66582, 4084, 107252, 59619, 116281, 67957, 128728, 30916, 69051, 90422, 102716, 51905, 66753, 60509, 78066, 38568, 119630, 75839, 113134, 54356, 70996, 63085, 83048},
{4130, 71826, 46248, 50447, 4281, 129092, 23122, 103196, 9305, 34797, 111094, 127775, 82662, 120386, 109738, 124765, 24770, 125174, 83477, 102473, 45209, 79062, 84764, 125929, 31689, 95554, 66614, 127658, 31756, 55684, 53670, 53776}
});
TestEquihashSolvers(96, 5, "Test case with 3+-way collision in the final round.", 0x2af3, {
{1093, 45982, 37399, 89200, 29813, 113936, 40951, 64027, 4370, 122807, 82736, 119086, 21530, 60168, 65163, 68120, 2310, 94346, 22675, 61162, 19193, 54507, 38352, 94322, 5341, 65047, 48071, 120787, 32561, 129305, 62593, 93497},
{6411, 91796, 58827, 93129, 6705, 74430, 91891, 124391, 32765, 128544, 51395, 74269, 55980, 89012, 58573, 75543, 7902, 22572, 27944, 66370, 61755, 76417, 68687, 90417, 31576, 105479, 117582, 130960, 52751, 53260, 71636, 118134},
{6411, 91796, 58827, 93129, 6705, 74430, 91891, 124391, 32765, 128544, 51395, 74269, 55980, 89012, 58573, 75543, 7902, 22572, 61755, 76417, 27944, 66370, 68687, 90417, 31576, 105479, 117582, 130960, 52751, 53260, 71636, 118134},
{6411, 91796, 58827, 93129, 6705, 74430, 91891, 124391, 32765, 128544, 51395, 74269, 55980, 89012, 58573, 75543, 7902, 22572, 68687, 90417, 27944, 66370, 61755, 76417, 31576, 105479, 117582, 130960, 52751, 53260, 71636, 118134},
{11541, 106147, 29075, 118360, 53060, 62499, 109856, 118745, 14581, 56663, 114595, 121986, 35542, 72577, 88428, 116033, 11996, 55170, 16966, 94150, 16116, 81559, 34889, 112430, 37304, 104803, 92442, 119354, 46613, 72741, 50259, 89047}
});
}
BOOST_AUTO_TEST_CASE(validator_testvectors) {