@@ -2915,6 +2915,12 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
29152915 if (pindex->IsProofOfStake ())
29162916 setStakeSeen.insert (make_pair (pindex->prevoutStake , pindex->nStakeTime ));
29172917
2918+
2919+ // Check proof of stake
2920+ if (block.nBits != GetNextTargetRequired (pindex->pprev , block.IsProofOfStake ())){
2921+ return state.DoS (1 ,error (" ContextualCheckBlock() : incorrect %s at height %d (%d)" , !block.IsProofOfStake () ? " proof-of-work" : " proof-of-stake" ,pindex->pprev ->nHeight , block.nBits ), REJECT_INVALID , " bad-diffbits" );
2922+ }
2923+
29182924 arith_uint256 hashProof;
29192925
29202926 // Verify hash target and signature of coinstake tx
@@ -2929,9 +2935,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
29292935 }
29302936
29312937 if (block.IsProofOfWork ())
2932- {
29332938 hashProof = UintToArith256 (block.GetPoWHash ());
2934- }
29352939
29362940 if (!pindex->SetStakeEntropyBit (block.GetStakeEntropyBit ()))
29372941 return state.DoS (1 ,error (" ConnectBlock() : SetStakeEntropyBit() failed" ), REJECT_INVALID , " bad-entropy-bit" );
@@ -4762,11 +4766,6 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIn
47624766 if (VersionBitsState (pindexPrev, consensusParams, Consensus::DEPLOYMENT_CSV , versionbitscache) == THRESHOLD_ACTIVE ) {
47634767 nLockTimeFlags |= LOCKTIME_MEDIAN_TIME_PAST ;
47644768 }
4765-
4766- // Check proof of stake
4767- if (nHeight > 0 && block.nBits != GetNextTargetRequired (pindexPrev, block.IsProofOfStake ())){
4768- return state.DoS (1 ,error (" ContextualCheckBlock() : incorrect %s at height %d (%d)" , !block.IsProofOfStake () ? " proof-of-work" : " proof-of-stake" , nHeight, block.nBits ), REJECT_INVALID , " bad-diffbits" );
4769- }
47704769
47714770 if (block.IsProofOfWork () && nHeight > Params ().GetConsensus ().nLastPOWBlock )
47724771 return state.DoS (10 , false , REJECT_INVALID , " check-pow-height" , " pow-mined blocks not allowed" );
0 commit comments