Skip to content

Commit 105ee5f

Browse files
committed
[Consensus] Readd checks removed in 3b778f5
Two importants checks were removed while refactoring to add zPIV staking. Their equivalents were added to zPIV staking but missing for simple PIV staking. We add them back with this commit.
1 parent 2621b7f commit 105ee5f

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/kernel.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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",

src/kernel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ bool Stake(CStakeInput* stakeInput, unsigned int nBits, unsigned int nTimeBlockF
2929

3030
// Check kernel hash target and coinstake signature
3131
// Sets hashProofOfStake on success return
32-
bool CheckProofOfStake(const CBlock block, uint256& hashProofOfStake, std::unique_ptr<CStakeInput>& stake);
32+
bool CheckProofOfStake(const CBlock block, uint256& hashProofOfStake, std::unique_ptr<CStakeInput>& stake, int nPreviousBlockHeight);
3333

3434
// Check whether the coinstake timestamp meets protocol
3535
bool CheckCoinStakeTimestamp(int64_t nTimeBlock, int64_t nTimeTx);

0 commit comments

Comments
 (0)