From c87debb0486349a04088fb91ec0bbc8a2d8c1d1b Mon Sep 17 00:00:00 2001 From: instagibbs Date: Thu, 9 Jun 2016 13:23:11 -0400 Subject: [PATCH] Add parentChainPowLimit, check in CheckBitcoinProof --- src/chainparams.cpp | 7 +++++++ src/consensus/params.h | 1 + src/pow.cpp | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 4bf40a63ff..4552dc0180 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -61,6 +61,12 @@ public: consensus.BIP65Height = 388381; // 000000000000000004c2b624ed5d7756c508d90fd0da2c7c679febfa6c4735f0 consensus.BIP66Height = 363725; // 00000000000000000379eaa19dce8c9b722d46ae6a57c2f1a988119488b50931 consensus.powLimit = uint256S("00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); + // Peg-ins Bitcoin headers must have higher difficulty target than this field + // This value must be sufficiently small to not preclude realistic parent + // chain difficulty during network lifespan yet sufficiently large to + // deny peg-in DoS attacks due to our inability to ban after failed + // IsBitcoinBlock RPC checks. + consensus.parentChainPowLimit = uint256S("00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); consensus.nPowTargetTimespan = 14 * 24 * 60 * 60; // two weeks consensus.nPowTargetSpacing = 10 * 60; consensus.fPowAllowMinDifficultyBlocks = false; @@ -166,6 +172,7 @@ public: consensus.BIP65Height = 1351; // BIP65 activated on regtest (Used in rpc activation tests) consensus.BIP66Height = 1251; // BIP66 activated on regtest (Used in rpc activation tests) consensus.powLimit = uint256S("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); + consensus.parentChainPowLimit = uint256S("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); consensus.nPowTargetTimespan = 14 * 24 * 60 * 60; // two weeks consensus.nPowTargetSpacing = 10 * 60; consensus.fPowAllowMinDifficultyBlocks = true; diff --git a/src/consensus/params.h b/src/consensus/params.h index 6240e82857..a6d00987ce 100644 --- a/src/consensus/params.h +++ b/src/consensus/params.h @@ -56,6 +56,7 @@ struct Params { BIP9Deployment vDeployments[MAX_VERSION_BITS_DEPLOYMENTS]; /** Proof of work parameters */ uint256 powLimit; + uint256 parentChainPowLimit; bool fPowAllowMinDifficultyBlocks; bool fPowNoRetargeting; int64_t nPowTargetSpacing; diff --git a/src/pow.cpp b/src/pow.cpp index 73d5699431..68fe276238 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -46,7 +46,7 @@ bool CheckBitcoinProof(uint256 hash, unsigned int nBits) bnTarget.SetCompact(nBits, &fNegative, &fOverflow); // Check range - if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(Params().GetConsensus().powLimit)) + if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(Params().GetConsensus().parentChainPowLimit)) return false; // Check proof of work matches claimed amount