src/kernel.cpp
// Check kernel hash target and coinstake signature
Check kernel hash target and coinstake signature
Check kernel hash target and coinstake signature
bool CheckProofOfStake(const CTransaction& tx, unsigned int nBits, uint256& hashProofOfStake, uint256& targetProofOfStake)
{
    if (!tx.IsCoinStake())
        return error("CheckProofOfStake() : called on non-coinstake %s", tx.GetHash().ToString().c_str());
    const CTxIn& txin = tx.vin[0];
    CTxDB txdb("r");
    CTransaction txPrev;
    CTxIndex txindex;
    if (!txPrev.ReadFromDisk(txdb, txin.prevout, txindex))
        return tx.DoS(1, error("CheckProofOfStake() : INFO: read txPrev failed"));  
    if (!VerifySignature(txPrev, tx, 0, MANDATORY_SCRIPT_VERIFY_FLAGS, 0))
        return tx.DoS(100, error("CheckProofOfStake() : VerifySignature failed on coinstake %s", tx.GetHash().ToString().c_str()));
    CBlock block;
    if (!block.ReadFromDisk(txindex.pos.nFile, txindex.pos.nBlockPos, false))
        return fDebug? error("CheckProofOfStake() : read block failed") : false; 
    if (!CheckStakeKernelHash(nBits, block, txindex.pos.nTxPos - txindex.pos.nBlockPos, txPrev, txin.prevout, tx.nTime, hashProofOfStake, targetProofOfStake, fDebug))
        return tx.DoS(1, error("CheckProofOfStake() : INFO: check kernel failed on coinstake %s, hashProof=%s", tx.GetHash().ToString().c_str(), hashProofOfStake.ToString().c_str())); 
    return true;
}
bool CheckProofOfStake ( const CTransaction & tx , unsigned int nBits , uint256 & hashProofOfStake , uint256 & targetProofOfStake ) { if ( ! tx . IsCoinStake ( ) ) return error ( " " , tx . GetHash ( ) . ToString ( ) . c_str ( ) ) ; const CTxIn & txin = tx . vin [ 0 ] ; CTxDB txdb ( " " ) ; CTransaction txPrev ; CTxIndex txindex ; if ( ! txPrev . ReadFromDisk ( txdb , txin . prevout , txindex ) ) return tx . DoS ( 1 , error ( " " ) ) ; if ( ! VerifySignature ( txPrev , tx , 0 , MANDATORY_SCRIPT_VERIFY_FLAGS , 0 ) ) return tx . DoS ( 100 , error ( " " , tx . GetHash ( ) . ToString ( ) . c_str ( ) ) ) ; CBlock block ; if ( ! block . ReadFromDisk ( txindex . pos . nFile , txindex . pos . nBlockPos , false ) ) return fDebug ? error ( " " ) : false ; if ( ! CheckStakeKernelHash ( nBits , block , txindex . pos . nTxPos - txindex . pos . nBlockPos , txPrev , txin . prevout , tx . nTime , hashProofOfStake , targetProofOfStake , fDebug ) ) return tx . DoS ( 1 , error ( " " , tx . GetHash ( ) . ToString ( ) . c_str ( ) , hashProofOfStake . ToString ( ) . c_str ( ) ) ) ; return true ; }
Check kernel hash target and coinstake signature
Check kernel hash target and coinstake signature
// Kernel (input 0) must match the stake hash target per coin age (nBits) // First try finding the previous transaction in database // previous transaction not in main chain, may occur during initial download // Verify signature // Read block header // unable to read block of previous transaction // may occur during initial download or if behind on block chain sync