Skip to content

Commit

Permalink
Fix inconsistent checks in CheckProofOfStake()
Browse files Browse the repository at this point in the history
  • Loading branch information
presstab committed Aug 10, 2016
1 parent 922f368 commit db34f50
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
12 changes: 8 additions & 4 deletions src/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,9 @@ bool CheckStakeKernelHash(unsigned int nBits, const CBlock blockFrom, const CTra
}

// Check kernel hash target and coinstake signature
bool CheckProofOfStake(const CTransaction& tx, unsigned int nTxTime, unsigned int nBits, uint256& hashProofOfStake)
bool CheckProofOfStake(const CBlock block, uint256& hashProofOfStake)
{
const CTransaction tx = block.vtx[1];
if (!tx.IsCoinStake())
return error("CheckProofOfStake() : called on non-coinstake %s", tx.GetHash().ToString().c_str());

Expand All @@ -394,11 +395,14 @@ bool CheckProofOfStake(const CTransaction& tx, unsigned int nTxTime, unsigned in
return error("CheckProofOfStake() : read block failed");

// Read block header
CBlockHeader block = pindex->GetBlockHeader();
CBlock blockprev;
if (!ReadBlockFromDisk(blockprev, pindex->GetBlockPos()))
return error("CheckProofOfStake(): INFO: failed to find block");

unsigned int nInterval = 0;
if (!CheckStakeKernelHash(nBits, block, txPrev, txin.prevout, nTxTime, nInterval, true, hashProofOfStake, fDebug))
return error("CheckProofOfStake() : INFO: check kernel failed on coinstake %s, hashProof=%s", tx.GetHash().ToString().c_str(), hashProofOfStake.ToString().c_str()); // may occur during initial download or if behind on block chain sync
unsigned int nTime = block.nTime;
if (!CheckStakeKernelHash(blockprev.nBits, blockprev, txPrev, txin.prevout, nTime, nInterval, true, hashProofOfStake, fDebug))
return error("CheckProofOfStake() : INFO: check kernel failed on coinstake %s, hashProof=%s \n", tx.GetHash().ToString().c_str(), hashProofOfStake.ToString().c_str()); // may occur during initial download or if behind on block chain sync

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

// Check kernel hash target and coinstake signature
// Sets hashProofOfStake on success return
bool CheckProofOfStake(const CTransaction& tx, unsigned int nTxTime, unsigned int nBits, uint256& hashProofOfStake);
bool CheckProofOfStake(const CBlock block, uint256& hashProofOfStake);

// Check whether the coinstake timestamp meets protocol
bool CheckCoinStakeTimestamp(int64_t nTimeBlock, int64_t nTimeTx);
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3252,7 +3252,7 @@ bool CheckWork(const CBlock block, CBlockIndex * const pindexPrev)
{
uint256 hashProofOfStake;
uint256 hash = block.GetHash();
if (!CheckProofOfStake(block.vtx[1], block.nTime, block.nBits, hashProofOfStake))
if(!CheckProofOfStake(block, hashProofOfStake))
{
LogPrintf("WARNING: ProcessBlock(): check proof-of-stake failed for block %s\n", hash.ToString().c_str());
return false;
Expand Down

0 comments on commit db34f50

Please sign in to comment.