Blackcoin Lore
This commit is contained in:
@@ -63,7 +63,7 @@ static inline void popstack(vector<valtype>& stack)
|
||||
stack.pop_back();
|
||||
}
|
||||
|
||||
bool static IsCompressedOrUncompressedPubKey(const valtype &vchPubKey) {
|
||||
bool IsCompressedOrUncompressedPubKey(const vector<unsigned char> &vchPubKey) {
|
||||
if (vchPubKey.size() < 33) {
|
||||
// Non-canonical public key: too short
|
||||
return false;
|
||||
@@ -95,7 +95,7 @@ bool static IsCompressedOrUncompressedPubKey(const valtype &vchPubKey) {
|
||||
*
|
||||
* This function is consensus-critical since BIP66.
|
||||
*/
|
||||
bool static IsValidSignatureEncoding(const std::vector<unsigned char> &sig) {
|
||||
bool static IsValidSignatureEncoding(const std::vector<unsigned char> &sig, bool haveHashType = true) {
|
||||
// Format: 0x30 [total-length] 0x02 [R-length] [R] 0x02 [S-length] [S] [sighash]
|
||||
// * total-length: 1-byte length descriptor of everything that follows,
|
||||
// excluding the sighash byte.
|
||||
@@ -116,7 +116,7 @@ bool static IsValidSignatureEncoding(const std::vector<unsigned char> &sig) {
|
||||
if (sig[0] != 0x30) return false;
|
||||
|
||||
// Make sure the length covers the entire signature.
|
||||
if (sig[1] != sig.size() - 3) return false;
|
||||
if (sig[1] != sig.size() - (haveHashType ? 3 : 2)) return false;
|
||||
|
||||
// Extract the length of the R element.
|
||||
unsigned int lenR = sig[3];
|
||||
@@ -129,7 +129,7 @@ bool static IsValidSignatureEncoding(const std::vector<unsigned char> &sig) {
|
||||
|
||||
// Verify that the length of the signature matches the sum of the length
|
||||
// of the elements.
|
||||
if ((size_t)(lenR + lenS + 7) != sig.size()) return false;
|
||||
if ((size_t)(lenR + lenS + (haveHashType ? 7 : 6)) != sig.size()) return false;
|
||||
|
||||
// Check whether the R element is an integer.
|
||||
if (sig[2] != 0x02) return false;
|
||||
@@ -160,17 +160,33 @@ bool static IsValidSignatureEncoding(const std::vector<unsigned char> &sig) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool static IsLowDERSignature(const valtype &vchSig, ScriptError* serror) {
|
||||
if (!IsValidSignatureEncoding(vchSig)) {
|
||||
bool IsLowDERSignature(const valtype &vchSig, ScriptError* serror, bool haveHashType) {
|
||||
if (!IsValidSignatureEncoding(vchSig, haveHashType)) {
|
||||
return set_error(serror, SCRIPT_ERR_SIG_DER);
|
||||
}
|
||||
std::vector<unsigned char> vchSigCopy(vchSig.begin(), vchSig.begin() + vchSig.size() - 1);
|
||||
if (!CPubKey::CheckLowS(vchSigCopy)) {
|
||||
unsigned int nLenR = vchSig[3];
|
||||
unsigned int nLenS = vchSig[5+nLenR];
|
||||
const unsigned char *S = &vchSig[6+nLenR];
|
||||
// If the S value is above the order of the curve divided by two, its
|
||||
// complement modulo the order could have been used instead, which is
|
||||
// one byte shorter when encoded correctly.
|
||||
if (!CPubKey::CheckSignatureElement(S, nLenS, true))
|
||||
return set_error(serror, SCRIPT_ERR_SIG_HIGH_S);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//bool IsLowDERSignature(const valtype &vchSig, ScriptError* serror) {
|
||||
// if (!IsValidSignatureEncoding(vchSig)) {
|
||||
// return set_error(serror, SCRIPT_ERR_SIG_DER);
|
||||
// }
|
||||
// std::vector<unsigned char> vchSigCopy(vchSig.begin(), vchSig.begin() + vchSig.size() - 1);
|
||||
// if (!CPubKey::CheckLowS(vchSigCopy)) {
|
||||
// return set_error(serror, SCRIPT_ERR_SIG_HIGH_S);
|
||||
// }
|
||||
// return true;
|
||||
//}
|
||||
|
||||
bool static IsDefinedHashtypeSignature(const valtype &vchSig) {
|
||||
if (vchSig.size() == 0) {
|
||||
return false;
|
||||
@@ -200,7 +216,7 @@ bool CheckSignatureEncoding(const vector<unsigned char> &vchSig, unsigned int fl
|
||||
}
|
||||
|
||||
bool static CheckPubKeyEncoding(const valtype &vchSig, unsigned int flags, ScriptError* serror) {
|
||||
if ((flags & SCRIPT_VERIFY_STRICTENC) != 0 && !IsCompressedOrUncompressedPubKey(vchSig)) {
|
||||
if ((flags & (SCRIPT_VERIFY_DERKEY | SCRIPT_VERIFY_STRICTENC)) != 0 && !IsCompressedOrUncompressedPubKey(vchSig)) {
|
||||
return set_error(serror, SCRIPT_ERR_PUBKEYTYPE);
|
||||
}
|
||||
return true;
|
||||
@@ -1089,6 +1105,8 @@ public:
|
||||
void Serialize(S &s, int nType, int nVersion) const {
|
||||
// Serialize nVersion
|
||||
::Serialize(s, txTo.nVersion, nType, nVersion);
|
||||
// Serialize nTime
|
||||
::Serialize(s, txTo.nTime, nType, nVersion);
|
||||
// Serialize vin
|
||||
unsigned int nInputs = fAnyoneCanPay ? 1 : txTo.vin.size();
|
||||
::WriteCompactSize(s, nInputs);
|
||||
|
||||
@@ -82,6 +82,10 @@ enum
|
||||
// See BIP65 for details.
|
||||
SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY = (1U << 9),
|
||||
|
||||
// Evaluating a pubkey that is not (0x04 + 64 bytes) or (0x02 or 0x03 + 32 bytes) by checksig causes script failure.
|
||||
// (softfork safe)
|
||||
SCRIPT_VERIFY_DERKEY = (1U << 10),
|
||||
|
||||
// support CHECKSEQUENCEVERIFY opcode
|
||||
//
|
||||
// See BIP112 for details
|
||||
@@ -138,6 +142,9 @@ public:
|
||||
MutableTransactionSignatureChecker(const CMutableTransaction* txToIn, unsigned int nInIn) : TransactionSignatureChecker(&txTo, nInIn), txTo(*txToIn) {}
|
||||
};
|
||||
|
||||
bool IsCompressedOrUncompressedPubKey(const std::vector<unsigned char> &vchPubKey);
|
||||
bool IsLowDERSignature(const std::vector<unsigned char> &vchSig, ScriptError* serror, bool haveHashType = true);
|
||||
|
||||
bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript& script, unsigned int flags, const BaseSignatureChecker& checker, ScriptError* error = NULL);
|
||||
bool VerifyScript(const CScript& scriptSig, const CScript& scriptPubKey, unsigned int flags, const BaseSignatureChecker& checker, ScriptError* error = NULL);
|
||||
|
||||
|
||||
@@ -221,6 +221,16 @@ bool CScript::IsPayToScriptHash() const
|
||||
(*this)[22] == OP_EQUAL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool CScript::IsPayToPublicKey() const
|
||||
{
|
||||
// Extra-fast test for pay-to-pubkey CScripts:
|
||||
return (this->size() == 35 &&
|
||||
(*this)[0] == 0x21 &&
|
||||
(*this)[34] == OP_CHECKSIG);
|
||||
}
|
||||
|
||||
bool CScript::IsPushOnly(const_iterator pc) const
|
||||
{
|
||||
while (pc < end())
|
||||
|
||||
@@ -612,18 +612,15 @@ public:
|
||||
|
||||
bool IsPayToScriptHash() const;
|
||||
|
||||
bool IsPayToPublicKey() const;
|
||||
|
||||
/** Called by IsStandardTx and P2SH/BIP62 VerifyScript (which makes it consensus-critical). */
|
||||
bool IsPushOnly(const_iterator pc) const;
|
||||
bool IsPushOnly() const;
|
||||
|
||||
/**
|
||||
* Returns whether the script is guaranteed to fail at execution,
|
||||
* regardless of the initial stack. This allows outputs to be pruned
|
||||
* instantly when entering the UTXO set.
|
||||
*/
|
||||
bool IsUnspendable() const
|
||||
{
|
||||
return (size() > 0 && *begin() == OP_RETURN);
|
||||
return (size() > 0 && *begin() == OP_RETURN);
|
||||
}
|
||||
|
||||
void clear()
|
||||
|
||||
@@ -40,7 +40,12 @@ extern unsigned nMaxDatacarrierBytes;
|
||||
* Failing one of these tests may trigger a DoS ban - see CheckInputs() for
|
||||
* details.
|
||||
*/
|
||||
static const unsigned int MANDATORY_SCRIPT_VERIFY_FLAGS = SCRIPT_VERIFY_P2SH;
|
||||
static const unsigned int MANDATORY_SCRIPT_VERIFY_FLAGS = SCRIPT_VERIFY_P2SH |
|
||||
SCRIPT_VERIFY_DERKEY |
|
||||
SCRIPT_VERIFY_LOW_S |
|
||||
SCRIPT_VERIFY_NULLDUMMY |
|
||||
SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY |
|
||||
SCRIPT_VERIFY_DERSIG;
|
||||
|
||||
enum txnouttype
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user