diff --git a/src/kernel.cpp b/src/kernel.cpp index df78f91fc4aa3..8d295898a774f 100644 --- a/src/kernel.cpp +++ b/src/kernel.cpp @@ -412,13 +412,14 @@ bool CheckProofOfStake(const CBlock block, uint256& hashProofOfStake, std::uniqu stake = std::unique_ptr(pivInput); } - CBlockIndex* pindex = stake->GetIndexFrom(); - if (!pindex) - return error("%s: Failed to find the block index", __func__); + //Get the + CBlockIndex* pindexfrom = stake->GetIndexFrom(); + if (!pindexfrom) + return error("%s: Failed to find the block index for stake origin", __func__); // Read block header - CBlock blockprev; - if (!ReadBlockFromDisk(blockprev, pindex->GetBlockPos())) + CBlock blockfrom; + if (!ReadBlockFromDisk(blockfrom, pindexfrom->GetBlockPos())) return error("CheckProofOfStake(): INFO: failed to find block"); uint256 bnTargetPerCoinDay; @@ -428,8 +429,14 @@ bool CheckProofOfStake(const CBlock block, uint256& hashProofOfStake, std::uniqu if (!stake->GetModifier(nStakeModifier)) return error("%s failed to get modifier for stake input\n", __func__); - unsigned int nBlockFromTime = blockprev.nTime; + unsigned int nBlockFromTime = blockfrom.nTime; unsigned int nTxTime = block.nTime; + if (!txin.IsZerocoinSpend()) { //Equivalent for zPIV is checked above in ContextualCheckZerocoinStake() + if (nTxTime < nBlockFromTime) // Transaction timestamp nTxTime + return error("CheckStakeKernelHash() : nTime violation - nBlockFromTime=%d nTimeTx=%d", nBlockFromTime, nTxTime); + if (nBlockFromTime + nStakeMinAge > nTxTime) // Min age requirement + return error("CheckStakeKernelHash() : min age violation - nBlockFromTime=%d nStakeMinAge=%d nTimeTx=%d", nBlockFromTime, nStakeMinAge, nTxTime); + } if (!CheckStake(stake->GetUniqueness(), stake->GetValue(), nStakeModifier, bnTargetPerCoinDay, nBlockFromTime, nTxTime, hashProofOfStake)) { return error("CheckProofOfStake() : INFO: check kernel failed on coinstake %s, hashProof=%s \n", diff --git a/src/kernel.h b/src/kernel.h index 4991955b72368..620ac94fd7ea3 100644 --- a/src/kernel.h +++ b/src/kernel.h @@ -29,7 +29,7 @@ bool Stake(CStakeInput* stakeInput, unsigned int nBits, unsigned int nTimeBlockF // Check kernel hash target and coinstake signature // Sets hashProofOfStake on success return -bool CheckProofOfStake(const CBlock block, uint256& hashProofOfStake, std::unique_ptr& stake); +bool CheckProofOfStake(const CBlock block, uint256& hashProofOfStake, std::unique_ptr& stake, int nPreviousBlockHeight); // Check whether the coinstake timestamp meets protocol bool CheckCoinStakeTimestamp(int64_t nTimeBlock, int64_t nTimeTx);