From 8ed64a6b5b64b097478098245539613db24494f7 Mon Sep 17 00:00:00 2001 From: alex Date: Wed, 22 Jan 2014 01:17:29 +0400 Subject: [PATCH] Validation of coinstake now uses txPrev directly instead of CCoins object --- src/kernel.cpp | 9 +++++---- src/main.cpp | 6 +++--- src/script.cpp | 1 + 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/kernel.cpp b/src/kernel.cpp index b099b54..85c0e36 100644 --- a/src/kernel.cpp +++ b/src/kernel.cpp @@ -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)) diff --git a/src/main.cpp b/src/main.cpp index f144a58..8904962 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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 { diff --git a/src/script.cpp b/src/script.cpp index 6d581aa..7bf1cc8 100644 --- a/src/script.cpp +++ b/src/script.cpp @@ -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); -- 1.7.1