Changeset View
Changeset View
Standalone View
Standalone View
src/script/sigencoding.cpp
Show First 20 Lines • Show All 167 Lines • ▼ Show 20 Lines | static bool CheckRawECDSASignatureEncoding(const slicedvaltype &sig, | ||||
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; | ||||
} | } | ||||
static bool CheckRawSchnorrSignatureEncoding(const slicedvaltype &sig, | |||||
uint32_t flags, | |||||
ScriptError *serror) { | |||||
if (sig.size() == 64) { | |||||
// In a generic-signature context, 64-byte signatures are interpreted | |||||
// as Schnorr signatures (which are never incorrectly encoded). | |||||
return true; | |||||
} | |||||
deadalnix: The fact you duplicated logic is a tell the design isn't quite right. | |||||
return set_error(serror, SCRIPT_ERR_SIG_NONSCHNORR); | |||||
} | |||||
static bool CheckRawSignatureEncoding(const slicedvaltype &sig, uint32_t flags, | static bool CheckRawSignatureEncoding(const slicedvaltype &sig, uint32_t flags, | ||||
ScriptError *serror) { | ScriptError *serror) { | ||||
if (sig.size() == 64) { | if (sig.size() == 64) { | ||||
// In a generic-signature context, 64-byte signatures are interpreted | // In a generic-signature context, 64-byte signatures are interpreted | ||||
// as Schnorr signatures (which are never incorrectly encoded). | // as Schnorr signatures (which are never incorrectly encoded). | ||||
return true; | return true; | ||||
} | } | ||||
return CheckRawECDSASignatureEncoding(sig, flags, serror); | return CheckRawECDSASignatureEncoding(sig, flags, serror); | ||||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | return CheckTransactionSignatureEncodingImpl( | ||||
vchSig, flags, serror, | vchSig, flags, serror, | ||||
[](const slicedvaltype &templateSig, uint32_t templateFlags, | [](const slicedvaltype &templateSig, uint32_t templateFlags, | ||||
ScriptError *templateSerror) { | ScriptError *templateSerror) { | ||||
return CheckRawECDSASignatureEncoding(templateSig, templateFlags, | return CheckRawECDSASignatureEncoding(templateSig, templateFlags, | ||||
templateSerror); | templateSerror); | ||||
}); | }); | ||||
} | } | ||||
bool CheckTransactionSchnorrSignatureEncoding(const valtype &vchSig, | |||||
uint32_t flags, | |||||
ScriptError *serror) { | |||||
return CheckTransactionSignatureEncodingImpl( | |||||
vchSig, flags, serror, | |||||
[](const slicedvaltype &templateSig, uint32_t templateFlags, | |||||
ScriptError *templateSerror) { | |||||
return CheckRawSchnorrSignatureEncoding(templateSig, templateFlags, | |||||
templateSerror); | |||||
}); | |||||
} | |||||
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; | ||||
case 65: | case 65: | ||||
// Non-compressed public key: must start with 0x04. | // Non-compressed public key: must start with 0x04. | ||||
Show All 34 Lines |
The fact you duplicated logic is a tell the design isn't quite right.