Validation of coinstake now uses txPrev directly instead of CCoins object
authoralex <alex@alex-VirtualBox.(none)>
Tue, 21 Jan 2014 21:17:29 +0000 (01:17 +0400)
committeralex <alex@alex-VirtualBox.(none)>
Tue, 21 Jan 2014 21:17:29 +0000 (01:17 +0400)
src/kernel.cpp
src/main.cpp
src/script.cpp

index b099b54..85c0e36 100644 (file)
@@ -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;
@@ -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))
index f144a58..8904962 100644 (file)
@@ -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
             {
index 6d581aa..7bf1cc8 100644 (file)
@@ -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);