@@ -412,13 +412,14 @@ bool CheckProofOfStake(const CBlock block, uint256& hashProofOfStake, std::uniqu
412412 stake = std::unique_ptr<CStakeInput>(pivInput);
413413 }
414414
415- CBlockIndex* pindex = stake->GetIndexFrom ();
416- if (!pindex)
417- return error (" %s: Failed to find the block index" , __func__);
415+ // Get the
416+ CBlockIndex* pindexfrom = stake->GetIndexFrom ();
417+ if (!pindexfrom)
418+ return error (" %s: Failed to find the block index for stake origin" , __func__);
418419
419420 // Read block header
420- CBlock blockprev ;
421- if (!ReadBlockFromDisk (blockprev, pindex ->GetBlockPos ()))
421+ CBlock blockfrom ;
422+ if (!ReadBlockFromDisk (blockfrom, pindexfrom ->GetBlockPos ()))
422423 return error (" CheckProofOfStake(): INFO: failed to find block" );
423424
424425 uint256 bnTargetPerCoinDay;
@@ -428,8 +429,14 @@ bool CheckProofOfStake(const CBlock block, uint256& hashProofOfStake, std::uniqu
428429 if (!stake->GetModifier (nStakeModifier))
429430 return error (" %s failed to get modifier for stake input\n " , __func__);
430431
431- unsigned int nBlockFromTime = blockprev .nTime ;
432+ unsigned int nBlockFromTime = blockfrom .nTime ;
432433 unsigned int nTxTime = block.nTime ;
434+ if (!txin.IsZerocoinSpend ()) { // Equivalent for zPIV is checked above in ContextualCheckZerocoinStake()
435+ if (nTxTime < nBlockFromTime) // Transaction timestamp nTxTime
436+ return error (" CheckStakeKernelHash() : nTime violation - nBlockFromTime=%d nTimeTx=%d" , nBlockFromTime, nTxTime);
437+ if (nBlockFromTime + nStakeMinAge > nTxTime) // Min age requirement
438+ return error (" CheckStakeKernelHash() : min age violation - nBlockFromTime=%d nStakeMinAge=%d nTimeTx=%d" , nBlockFromTime, nStakeMinAge, nTxTime);
439+ }
433440 if (!CheckStake (stake->GetUniqueness (), stake->GetValue (), nStakeModifier, bnTargetPerCoinDay, nBlockFromTime,
434441 nTxTime, hashProofOfStake)) {
435442 return error (" CheckProofOfStake() : INFO: check kernel failed on coinstake %s, hashProof=%s \n " ,
0 commit comments