Skip to content

Commit

Permalink
compatibility with BIP66
Browse files Browse the repository at this point in the history
  • Loading branch information
recursive-rat4 committed Sep 19, 2015
1 parent 3cc0a58 commit 1adbbfc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,15 @@ bool static IsDefinedHashtypeSignature(const valtype &vchSig) {
return true;
}

bool static CheckSignatureEncoding(const valtype &vchSig) {
bool static CheckSignatureEncoding(const valtype &vchSig, unsigned int flags) {
// Empty signature. Not strictly DER encoded, but allowed to provide a
// compact way to provide an invalid signature for use with CHECK(MULTI)SIG
if ((flags & SCRIPT_VERIFY_ALLOW_EMPTY_SIG) && vchSig.size() == 0) {
return true;
}
if (!IsLowDERSignature(vchSig)) {
return false;
} else if (!IsDefinedHashtypeSignature(vchSig)) {
} else if (!(flags & SCRIPT_VERIFY_FIX_HASHTYPE) && !IsDefinedHashtypeSignature(vchSig)) {
return false;
}
return true;
Expand Down Expand Up @@ -1048,10 +1053,10 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co
// Drop the signature, since there's no way for a signature to sign itself
scriptCode.FindAndDelete(CScript(vchSig));

if ((flags & SCRIPT_VERIFY_STRICTENC) && (!CheckSignatureEncoding(vchSig) || !CheckPubKeyEncoding(vchPubKey)))
if ((flags & SCRIPT_VERIFY_STRICTENC) && (!CheckSignatureEncoding(vchSig, flags) || !CheckPubKeyEncoding(vchPubKey)))
return false;

bool fSuccess = CheckSignatureEncoding(vchSig) && CheckPubKeyEncoding(vchPubKey) &&
bool fSuccess = CheckSignatureEncoding(vchSig, flags) && CheckPubKeyEncoding(vchPubKey) &&
CheckSig(vchSig, vchPubKey, scriptCode, txTo, nIn, nHashType, flags);

popstack(stack);
Expand Down Expand Up @@ -1111,11 +1116,11 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co
valtype& vchSig = stacktop(-isig);
valtype& vchPubKey = stacktop(-ikey);

if ((flags & SCRIPT_VERIFY_STRICTENC) && (!CheckSignatureEncoding(vchSig) || !CheckPubKeyEncoding(vchPubKey)))
if ((flags & SCRIPT_VERIFY_STRICTENC) && (!CheckSignatureEncoding(vchSig, flags) || !CheckPubKeyEncoding(vchPubKey)))
return false;

// Check signature
bool fOk = CheckSignatureEncoding(vchSig) && CheckPubKeyEncoding(vchPubKey) &&
bool fOk = CheckSignatureEncoding(vchSig, flags) && CheckPubKeyEncoding(vchPubKey) &&
CheckSig(vchSig, vchPubKey, scriptCode, txTo, nIn, nHashType, flags);

if (fOk)
Expand Down
2 changes: 2 additions & 0 deletions src/script.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ enum
SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS = (1U << 2),

SCRIPT_VERIFY_STRICTENC = (1U << 3),
SCRIPT_VERIFY_ALLOW_EMPTY_SIG = (1U << 4),
SCRIPT_VERIFY_FIX_HASHTYPE = (1U << 5),
};

// Mandatory script verification flags that all new blocks must comply with for
Expand Down

0 comments on commit 1adbbfc

Please sign in to comment.