aboutsummaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2014-09-14 04:48:32 +0200
committerPieter Wuille <pieter.wuille@gmail.com>2014-10-02 20:26:58 +0200
commite790c370b5971dd096d1bbfd55960ccf71b7594a (patch)
treede37518b3fa3c9fe6d3c6b70759f05dde90134fb /src/script
parent5c1e798a8e9df15f8fbd120e57fc67e585f13843 (diff)
Replace SCRIPT_VERIFY_NOCACHE by flag directly to checker
Diffstat (limited to 'src/script')
-rw-r--r--src/script/interpreter.cpp10
-rw-r--r--src/script/interpreter.h9
-rw-r--r--src/script/sigcache.cpp6
-rw-r--r--src/script/sigcache.h18
-rw-r--r--src/script/sign.cpp2
5 files changed, 18 insertions, 27 deletions
diff --git a/src/script/interpreter.cpp b/src/script/interpreter.cpp
index f0b4268390..56140f19db 100644
--- a/src/script/interpreter.cpp
+++ b/src/script/interpreter.cpp
@@ -671,7 +671,7 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, un
scriptCode.FindAndDelete(CScript(vchSig));
bool fSuccess = IsCanonicalSignature(vchSig, flags) && IsCanonicalPubKey(vchPubKey, flags) &&
- checker.CheckSig(vchSig, vchPubKey, scriptCode, flags);
+ checker.CheckSig(vchSig, vchPubKey, scriptCode);
popstack(stack);
popstack(stack);
@@ -732,7 +732,7 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, un
// Check signature
bool fOk = IsCanonicalSignature(vchSig, flags) && IsCanonicalPubKey(vchPubKey, flags) &&
- checker.CheckSig(vchSig, vchPubKey, scriptCode, flags);
+ checker.CheckSig(vchSig, vchPubKey, scriptCode);
if (fOk) {
isig++;
@@ -917,12 +917,12 @@ uint256 SignatureHash(const CScript& scriptCode, const CTransaction& txTo, unsig
return ss.GetHash();
}
-bool SignatureChecker::VerifySignature(const std::vector<unsigned char>& vchSig, const CPubKey& pubkey, const uint256& sighash, int flags) const
+bool SignatureChecker::VerifySignature(const std::vector<unsigned char>& vchSig, const CPubKey& pubkey, const uint256& sighash) const
{
return pubkey.Verify(sighash, vchSig);
}
-bool SignatureChecker::CheckSig(const vector<unsigned char>& vchSigIn, const vector<unsigned char>& vchPubKey, const CScript& scriptCode, int flags) const
+bool SignatureChecker::CheckSig(const vector<unsigned char>& vchSigIn, const vector<unsigned char>& vchPubKey, const CScript& scriptCode) const
{
CPubKey pubkey(vchPubKey);
if (!pubkey.IsValid())
@@ -937,7 +937,7 @@ bool SignatureChecker::CheckSig(const vector<unsigned char>& vchSigIn, const vec
uint256 sighash = SignatureHash(scriptCode, txTo, nIn, nHashType);
- if (!VerifySignature(vchSig, pubkey, sighash, flags))
+ if (!VerifySignature(vchSig, pubkey, sighash))
return false;
return true;
diff --git a/src/script/interpreter.h b/src/script/interpreter.h
index 801f7e0ce1..f5363a7535 100644
--- a/src/script/interpreter.h
+++ b/src/script/interpreter.h
@@ -31,8 +31,7 @@ enum
SCRIPT_VERIFY_P2SH = (1U << 0), // evaluate P2SH (BIP16) subscripts
SCRIPT_VERIFY_STRICTENC = (1U << 1), // enforce strict conformance to DER and SEC2 for signatures and pubkeys
SCRIPT_VERIFY_LOW_S = (1U << 2), // enforce low S values (<n/2) in signatures (depends on STRICTENC)
- SCRIPT_VERIFY_NOCACHE = (1U << 3), // do not store results in signature cache (but do query it)
- SCRIPT_VERIFY_NULLDUMMY = (1U << 4), // verify dummy stack item consumed by CHECKMULTISIG is of zero-length
+ SCRIPT_VERIFY_NULLDUMMY = (1U << 3), // verify dummy stack item consumed by CHECKMULTISIG is of zero-length
};
bool IsCanonicalPubKey(const std::vector<unsigned char> &vchPubKey, unsigned int flags);
@@ -43,7 +42,7 @@ uint256 SignatureHash(const CScript &scriptCode, const CTransaction& txTo, unsig
class BaseSignatureChecker
{
public:
- virtual bool CheckSig(const std::vector<unsigned char>& scriptSig, const std::vector<unsigned char>& vchPubKey, const CScript& scriptCode, int nFlags) const
+ virtual bool CheckSig(const std::vector<unsigned char>& scriptSig, const std::vector<unsigned char>& vchPubKey, const CScript& scriptCode) const
{
return false;
}
@@ -58,11 +57,11 @@ private:
unsigned int nIn;
protected:
- virtual bool VerifySignature(const std::vector<unsigned char>& vchSig, const CPubKey& vchPubKey, const uint256& sighash, int flags) const;
+ virtual bool VerifySignature(const std::vector<unsigned char>& vchSig, const CPubKey& vchPubKey, const uint256& sighash) const;
public:
SignatureChecker(const CTransaction& txToIn, unsigned int nInIn) : txTo(txToIn), nIn(nInIn) {}
- bool CheckSig(const std::vector<unsigned char>& scriptSig, const std::vector<unsigned char>& vchPubKey, const CScript& scriptCode, int nFlags) const;
+ bool CheckSig(const std::vector<unsigned char>& scriptSig, const std::vector<unsigned char>& vchPubKey, const CScript& scriptCode) const;
};
bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript& script, unsigned int flags, const BaseSignatureChecker& checker);
diff --git a/src/script/sigcache.cpp b/src/script/sigcache.cpp
index a1dec64dbc..981563b7ae 100644
--- a/src/script/sigcache.cpp
+++ b/src/script/sigcache.cpp
@@ -72,17 +72,17 @@ public:
}
-bool CachingSignatureChecker::VerifySignature(const std::vector<unsigned char>& vchSig, const CPubKey& pubkey, const uint256& sighash, int flags) const
+bool CachingSignatureChecker::VerifySignature(const std::vector<unsigned char>& vchSig, const CPubKey& pubkey, const uint256& sighash) const
{
static CSignatureCache signatureCache;
if (signatureCache.Get(sighash, vchSig, pubkey))
return true;
- if (!SignatureChecker::VerifySignature(vchSig, pubkey, sighash, flags))
+ if (!SignatureChecker::VerifySignature(vchSig, pubkey, sighash))
return false;
- if (!(flags & SCRIPT_VERIFY_NOCACHE))
+ if (store)
signatureCache.Set(sighash, vchSig, pubkey);
return true;
}
diff --git a/src/script/sigcache.h b/src/script/sigcache.h
index 8faa7ae01f..9537efbd11 100644
--- a/src/script/sigcache.h
+++ b/src/script/sigcache.h
@@ -14,21 +14,13 @@ class CPubKey;
class CachingSignatureChecker : public SignatureChecker
{
+private:
+ bool store;
+
public:
- CachingSignatureChecker(const CTransaction& txToIn, unsigned int nInIn) : SignatureChecker(txToIn, nInIn) {}
+ CachingSignatureChecker(const CTransaction& txToIn, unsigned int nInIn, bool storeIn=true) : SignatureChecker(txToIn, nInIn), store(storeIn) {}
- bool VerifySignature(const std::vector<unsigned char>& vchSig, const CPubKey& vchPubKey, const uint256& sighash, int flags) const;
+ bool VerifySignature(const std::vector<unsigned char>& vchSig, const CPubKey& vchPubKey, const uint256& sighash) const;
};
-// Wrappers using a default SignatureChecker.
-bool inline EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript& script, const CTransaction& txTo, unsigned int nIn, unsigned int flags)
-{
- return EvalScript(stack, script, flags, CachingSignatureChecker(txTo, nIn));
-}
-
-bool inline VerifyScript(const CScript& scriptSig, const CScript& scriptPubKey, const CTransaction& txTo, unsigned int nIn, unsigned int flags)
-{
- return VerifyScript(scriptSig, scriptPubKey, flags, CachingSignatureChecker(txTo, nIn));
-}
-
#endif
diff --git a/src/script/sign.cpp b/src/script/sign.cpp
index a524ac8e5e..da77e7d1f1 100644
--- a/src/script/sign.cpp
+++ b/src/script/sign.cpp
@@ -174,7 +174,7 @@ static CScript CombineMultisig(CScript scriptPubKey, const CMutableTransaction&
if (sigs.count(pubkey))
continue; // Already got a sig for this pubkey
- if (SignatureChecker(txTo, nIn).CheckSig(sig, pubkey, scriptPubKey, 0))
+ if (SignatureChecker(txTo, nIn).CheckSig(sig, pubkey, scriptPubKey))
{
sigs[pubkey] = sig;
break;