Changeset View
Changeset View
Standalone View
Standalone View
src/script/sigencoding.cpp
Show First 20 Lines • Show All 162 Lines • ▼ Show 20 Lines | static bool CheckRawSignatureEncoding(const slicedvaltype &sig, uint32_t flags, | ||||
if ((flags & SCRIPT_VERIFY_LOW_S) && !CPubKey::CheckLowS(sig)) { | if ((flags & SCRIPT_VERIFY_LOW_S) && !CPubKey::CheckLowS(sig)) { | ||||
return set_error(serror, SCRIPT_ERR_SIG_HIGH_S); | return set_error(serror, SCRIPT_ERR_SIG_HIGH_S); | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
bool CheckDataSignatureEncoding(const valtype &vchSig, uint32_t flags, | static bool CheckTransactionSignatureHashType(const valtype &vchSig, | ||||
uint32_t flags, | |||||
ScriptError *serror) { | |||||
if (flags & SCRIPT_VERIFY_STRICTENC) { | |||||
SigHashType hashType = GetHashType(vchSig); | |||||
if (!hashType.isDefined()) { | |||||
return set_error(serror, SCRIPT_ERR_SIG_HASHTYPE); | |||||
} | |||||
bool usesForkId = hashType.hasForkId(); | |||||
bool forkIdEnabled = flags & SCRIPT_ENABLE_SIGHASH_FORKID; | |||||
if (!forkIdEnabled && usesForkId) { | |||||
return set_error(serror, SCRIPT_ERR_ILLEGAL_FORKID); | |||||
} | |||||
if (forkIdEnabled && !usesForkId) { | |||||
return set_error(serror, SCRIPT_ERR_MUST_USE_FORKID); | |||||
} | |||||
} | |||||
return true; | |||||
} | |||||
bool CheckDataECDSASignatureEncoding(const valtype &vchSig, uint32_t flags, | |||||
ScriptError *serror) { | ScriptError *serror) { | ||||
// Empty signature. Not strictly DER encoded, but allowed to provide a | // Empty signature. Not strictly DER encoded, but allowed to provide a | ||||
// compact way to provide an invalid signature for use with CHECK(MULTI)SIG | // compact way to provide an invalid signature for use with CHECK(MULTI)SIG | ||||
if (vchSig.size() == 0) { | if (vchSig.size() == 0) { | ||||
return true; | return true; | ||||
} | } | ||||
return CheckRawSignatureEncoding( | return CheckRawSignatureEncoding( | ||||
vchSig | boost::adaptors::sliced(0, vchSig.size()), flags, serror); | vchSig | boost::adaptors::sliced(0, vchSig.size()), flags, serror); | ||||
} | } | ||||
bool CheckTransactionSignatureEncoding(const valtype &vchSig, uint32_t flags, | bool CheckTransactionECDSASignatureEncoding(const valtype &vchSig, | ||||
uint32_t flags, | |||||
ScriptError *serror) { | ScriptError *serror) { | ||||
// Empty signature. Not strictly DER encoded, but allowed to provide a | // Empty signature. Not strictly DER encoded, but allowed to provide a | ||||
// compact way to provide an invalid signature for use with CHECK(MULTI)SIG | // compact way to provide an invalid signature for use with CHECK(MULTI)SIG | ||||
if (vchSig.size() == 0) { | if (vchSig.size() == 0) { | ||||
return true; | return true; | ||||
} | } | ||||
if (!CheckRawSignatureEncoding( | if (!CheckRawSignatureEncoding( | ||||
vchSig | boost::adaptors::sliced(0, vchSig.size() - 1), flags, | vchSig | boost::adaptors::sliced(0, vchSig.size() - 1), flags, | ||||
serror)) { | serror)) { | ||||
// serror is set | // serror is set | ||||
return false; | return false; | ||||
} | } | ||||
if (flags & SCRIPT_VERIFY_STRICTENC) { | return CheckTransactionSignatureHashType(vchSig, flags, serror); | ||||
if (!GetHashType(vchSig).isDefined()) { | |||||
return set_error(serror, SCRIPT_ERR_SIG_HASHTYPE); | |||||
} | |||||
bool usesForkId = GetHashType(vchSig).hasForkId(); | |||||
bool forkIdEnabled = flags & SCRIPT_ENABLE_SIGHASH_FORKID; | |||||
if (!forkIdEnabled && usesForkId) { | |||||
return set_error(serror, SCRIPT_ERR_ILLEGAL_FORKID); | |||||
} | } | ||||
if (forkIdEnabled && !usesForkId) { | bool CheckTransactionSchnorrSignatureEncoding(const valtype &vchSig, | ||||
return set_error(serror, SCRIPT_ERR_MUST_USE_FORKID); | uint32_t flags, | ||||
} | ScriptError *serror) { | ||||
// Empty signature. Not strictly valid, but allowed to provide a | |||||
// compact way to provide an invalid signature for use with CHECKMULTISIG | |||||
deadalnix: It's required we accept this for NULLFAILto work properly anyways. | |||||
markblundebergAuthorUnsubmitted Done Inline ActionsTrue. Actually right now only length=65 sigs get passed to CheckTransactionSchnorrSignatureEncoding. However in future when we add the new Schnorr CHECKMULTISIG mechanics, this function will be getting inputs of all lengths. I am going to rewrite the logic here. markblundeberg: True.
Actually right now only length=65 sigs get passed to… | |||||
if (vchSig.size() == 0) { | |||||
return true; | |||||
} | } | ||||
return true; | return CheckTransactionSignatureHashType(vchSig, flags, serror); | ||||
} | } | ||||
static bool IsCompressedOrUncompressedPubKey(const valtype &vchPubKey) { | static bool IsCompressedOrUncompressedPubKey(const valtype &vchPubKey) { | ||||
switch (vchPubKey.size()) { | switch (vchPubKey.size()) { | ||||
case 33: | case 33: | ||||
// Compressed public key: must start with 0x02 or 0x03. | // Compressed public key: must start with 0x02 or 0x03. | ||||
return vchPubKey[0] == 0x02 || vchPubKey[0] == 0x03; | return vchPubKey[0] == 0x02 || vchPubKey[0] == 0x03; | ||||
Show All 36 Lines |
It's required we accept this for NULLFAILto work properly anyways.