Skip to content

Commit

Permalink
Validation of coinstake now uses txPrev directly instead of CCoins ob…
Browse files Browse the repository at this point in the history
…ject
  • Loading branch information
alex authored and alex committed Jan 21, 2014
1 parent cdef376 commit 8ed64a6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
9 changes: 5 additions & 4 deletions src/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,6 @@ bool CheckProofOfStake(const CTransaction& tx, unsigned int nBits, uint256& hash

// Kernel (input 0) must match the stake hash target per coin age (nBits)
const CTxIn& txin = tx.vin[0];

unsigned nTxPos;

CTransaction txPrev;
Expand All @@ -380,11 +379,13 @@ bool CheckProofOfStake(const CTransaction& tx, unsigned int nBits, uint256& hash
else
return fDebug? error("CheckProofOfStake() : read block failed") : false; // unable to read block of previous transaction

// Verify signature
if (!VerifySignature(coins, tx, 0, true, false, 0))
const CTxOut& txout = txPrev.vout[txin.prevout.n];

// Verify script
if (!VerifyScript(txin.scriptSig, txout.scriptPubKey, tx, 0, true, false, 0))
{
fFatal = true;
return error("CheckProofOfStake() : VerifySignature failed on coinstake %s", tx.GetHash().ToString().c_str());
return error("CheckProofOfStake() : VerifyScript failed on coinstake %s", tx.GetHash().ToString().c_str());
}

if (!CheckStakeKernelHash(nBits, block, nTxPos, txPrev, txin.prevout, tx.nTime, hashProofOfStake, targetProofOfStake, fFatal, fMiner, fDebug))
Expand Down
6 changes: 3 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2443,16 +2443,16 @@ bool ProcessBlock(CNode* pfrom, CBlock* pblock)
bool fFatal = false;
uint256 hashProofOfStake;

// Verify proof-of-stake hash target and signatures
// Verify proof-of-stake script, hash target and signature
if (!pblock->CheckSignature(fFatal, hashProofOfStake))
{
if (fFatal)
{
// Invalid blockhash/coinstake signature or no generator defined, nothing to do here
// Invalid coinstake script, blockhash signature or no generator defined, nothing to do here
// This also may occur when supplied proof-of-stake doesn't satisfy required target
if (pfrom)
pfrom->Misbehaving(100);
return error("ProcessBlock() : invalid signature in proof-of-stake block %s", hash.ToString().c_str());
return error("ProcessBlock() : invalid signatures found in proof-of-stake block %s", hash.ToString().c_str());
}
else
{
Expand Down
1 change: 1 addition & 0 deletions src/script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1762,6 +1762,7 @@ bool VerifySignature(const CCoins& txFrom, const CTransaction& txTo, unsigned in
const CTxIn& txin = txTo.vin[nIn];
if (txin.prevout.n >= txFrom.vout.size())
return false;

const CTxOut& txout = txFrom.vout[txin.prevout.n];

return VerifyScript(txin.scriptSig, txout.scriptPubKey, txTo, nIn, fValidatePayToScriptHash, fStrictEncodings, nHashType);
Expand Down

0 comments on commit 8ed64a6

Please sign in to comment.