Primecoin: Remove redundant Fermat test in Cunningham chain test

master
Sunny King 2013-07-05 23:23:36 +01:00
parent 23beafa6dc
commit e7711f3c97
2 changed files with 4 additions and 6 deletions

View File

@ -101,7 +101,7 @@ static bool FermatProbablePrimalityTest(const CBigNum& n, unsigned int& nLength)
unsigned int nFractionalLength = (((n-r) << nFractionalBits) / n).getuint();
if (nFractionalLength >= (1 << nFractionalBits))
return error("FermatProbablePrimalityTest() : fractional assert");
nLength = (nLength & 0xfff00000u) | nFractionalLength;
nLength = (nLength & TARGET_LENGTH_MASK) | nFractionalLength;
return false;
}
@ -139,16 +139,13 @@ static bool EulerLagrangeLifchitzPrimalityTest(const CBigNum& n, bool fSophieGer
unsigned int nFractionalLength = (((n-r) << nFractionalBits) / n).getuint();
if (nFractionalLength >= (1 << nFractionalBits))
return error("EulerLagrangeLifchitzPrimalityTest() : fractional assert");
nLength = (nLength & 0xfff00000u) | nFractionalLength;
nLength = (nLength & TARGET_LENGTH_MASK) | nFractionalLength;
return false;
}
// Proof-of-work Target (prime chain target):
// format - 32 bit, 8 length bits, 24 fractional length bits
static const unsigned int TARGET_FRACTIONAL_MASK = (1u<<nFractionalBits) - 1;
static const unsigned int TARGET_LENGTH_MASK = ~TARGET_FRACTIONAL_MASK;
unsigned int nTargetInitialLength = 7; // initial chain length target
unsigned int nTargetMinLength = 6; // minimum chain length target
@ -311,7 +308,6 @@ static bool ProbableCunninghamChainTest(const CBigNum& n, bool fSophieGermain, b
}
}
FermatProbablePrimalityTest(N, nProbableChainLength);
return (TargetGetLength(nProbableChainLength) >= 2);
}

View File

@ -38,6 +38,8 @@ void PrimorialAt(CBigNum& bn, CBigNum& bnPrimorial);
bool ProbablePrimeChainTest(const CBigNum& bnPrimeChainOrigin, unsigned int nBits, bool fFermatTest, unsigned int& nChainLengthCunningham1, unsigned int& nChainLengthCunningham2, unsigned int& nChainLengthBiTwin);
static const unsigned int nFractionalBits = 24;
static const unsigned int TARGET_FRACTIONAL_MASK = (1u<<nFractionalBits) - 1;
static const unsigned int TARGET_LENGTH_MASK = ~TARGET_FRACTIONAL_MASK;
static const uint64 nFractionalDifficultyMax = (1llu << (nFractionalBits + 32));
static const uint64 nFractionalDifficultyMin = (1llu << 32);
static const uint64 nFractionalDifficultyThreshold = (1llu << (8 + 32));