Merge #12939: Extract consts for WITNESS_V0 hash sizes
3450a9b
Extract consts for WITNESS_V0 hash sizes (Ben Woosley)
Pull request description:
Tree-SHA512: 57ba84dfa36aa61cabffce747388143cf1c8724dd2fc42aecf93748158b75dbe278b21a32483a100b8c303f6ad01d048da03b0a5c172175febbe70938ed4339d
This commit is contained in:
commit
e561cf4fa8
4 changed files with 11 additions and 7 deletions
|
@ -230,7 +230,7 @@ bool IsWitnessStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Check P2WSH standard limits
|
// Check P2WSH standard limits
|
||||||
if (witnessversion == 0 && witnessprogram.size() == 32) {
|
if (witnessversion == 0 && witnessprogram.size() == WITNESS_V0_SCRIPTHASH_SIZE) {
|
||||||
if (tx.vin[i].scriptWitness.stack.back().size() > MAX_STANDARD_P2WSH_SCRIPT_SIZE)
|
if (tx.vin[i].scriptWitness.stack.back().size() > MAX_STANDARD_P2WSH_SCRIPT_SIZE)
|
||||||
return false;
|
return false;
|
||||||
size_t sizeWitnessStack = tx.vin[i].scriptWitness.stack.size() - 1;
|
size_t sizeWitnessStack = tx.vin[i].scriptWitness.stack.size() - 1;
|
||||||
|
|
|
@ -1361,7 +1361,7 @@ static bool VerifyWitnessProgram(const CScriptWitness& witness, int witversion,
|
||||||
CScript scriptPubKey;
|
CScript scriptPubKey;
|
||||||
|
|
||||||
if (witversion == 0) {
|
if (witversion == 0) {
|
||||||
if (program.size() == 32) {
|
if (program.size() == WITNESS_V0_SCRIPTHASH_SIZE) {
|
||||||
// Version 0 segregated witness program: SHA256(CScript) inside the program, CScript + inputs in witness
|
// Version 0 segregated witness program: SHA256(CScript) inside the program, CScript + inputs in witness
|
||||||
if (witness.stack.size() == 0) {
|
if (witness.stack.size() == 0) {
|
||||||
return set_error(serror, SCRIPT_ERR_WITNESS_PROGRAM_WITNESS_EMPTY);
|
return set_error(serror, SCRIPT_ERR_WITNESS_PROGRAM_WITNESS_EMPTY);
|
||||||
|
@ -1373,7 +1373,7 @@ static bool VerifyWitnessProgram(const CScriptWitness& witness, int witversion,
|
||||||
if (memcmp(hashScriptPubKey.begin(), program.data(), 32)) {
|
if (memcmp(hashScriptPubKey.begin(), program.data(), 32)) {
|
||||||
return set_error(serror, SCRIPT_ERR_WITNESS_PROGRAM_MISMATCH);
|
return set_error(serror, SCRIPT_ERR_WITNESS_PROGRAM_MISMATCH);
|
||||||
}
|
}
|
||||||
} else if (program.size() == 20) {
|
} else if (program.size() == WITNESS_V0_KEYHASH_SIZE) {
|
||||||
// Special case for pay-to-pubkeyhash; signature + pubkey in witness
|
// Special case for pay-to-pubkeyhash; signature + pubkey in witness
|
||||||
if (witness.stack.size() != 2) {
|
if (witness.stack.size() != 2) {
|
||||||
return set_error(serror, SCRIPT_ERR_WITNESS_PROGRAM_MISMATCH); // 2 items in witness
|
return set_error(serror, SCRIPT_ERR_WITNESS_PROGRAM_MISMATCH); // 2 items in witness
|
||||||
|
@ -1530,10 +1530,10 @@ bool VerifyScript(const CScript& scriptSig, const CScript& scriptPubKey, const C
|
||||||
size_t static WitnessSigOps(int witversion, const std::vector<unsigned char>& witprogram, const CScriptWitness& witness, int flags)
|
size_t static WitnessSigOps(int witversion, const std::vector<unsigned char>& witprogram, const CScriptWitness& witness, int flags)
|
||||||
{
|
{
|
||||||
if (witversion == 0) {
|
if (witversion == 0) {
|
||||||
if (witprogram.size() == 20)
|
if (witprogram.size() == WITNESS_V0_KEYHASH_SIZE)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (witprogram.size() == 32 && witness.stack.size() > 0) {
|
if (witprogram.size() == WITNESS_V0_SCRIPTHASH_SIZE && witness.stack.size() > 0) {
|
||||||
CScript subscript(witness.stack.back().begin(), witness.stack.back().end());
|
CScript subscript(witness.stack.back().begin(), witness.stack.back().end());
|
||||||
return subscript.GetSigOpCount(true);
|
return subscript.GetSigOpCount(true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -129,6 +129,10 @@ enum class SigVersion
|
||||||
WITNESS_V0 = 1,
|
WITNESS_V0 = 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Signature hash sizes */
|
||||||
|
static constexpr size_t WITNESS_V0_SCRIPTHASH_SIZE = 32;
|
||||||
|
static constexpr size_t WITNESS_V0_KEYHASH_SIZE = 20;
|
||||||
|
|
||||||
uint256 SignatureHash(const CScript &scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType, const CAmount& amount, SigVersion sigversion, const PrecomputedTransactionData* cache = nullptr);
|
uint256 SignatureHash(const CScript &scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType, const CAmount& amount, SigVersion sigversion, const PrecomputedTransactionData* cache = nullptr);
|
||||||
|
|
||||||
class BaseSignatureChecker
|
class BaseSignatureChecker
|
||||||
|
|
|
@ -66,12 +66,12 @@ bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<std::v
|
||||||
int witnessversion;
|
int witnessversion;
|
||||||
std::vector<unsigned char> witnessprogram;
|
std::vector<unsigned char> witnessprogram;
|
||||||
if (scriptPubKey.IsWitnessProgram(witnessversion, witnessprogram)) {
|
if (scriptPubKey.IsWitnessProgram(witnessversion, witnessprogram)) {
|
||||||
if (witnessversion == 0 && witnessprogram.size() == 20) {
|
if (witnessversion == 0 && witnessprogram.size() == WITNESS_V0_KEYHASH_SIZE) {
|
||||||
typeRet = TX_WITNESS_V0_KEYHASH;
|
typeRet = TX_WITNESS_V0_KEYHASH;
|
||||||
vSolutionsRet.push_back(witnessprogram);
|
vSolutionsRet.push_back(witnessprogram);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (witnessversion == 0 && witnessprogram.size() == 32) {
|
if (witnessversion == 0 && witnessprogram.size() == WITNESS_V0_SCRIPTHASH_SIZE) {
|
||||||
typeRet = TX_WITNESS_V0_SCRIPTHASH;
|
typeRet = TX_WITNESS_V0_SCRIPTHASH;
|
||||||
vSolutionsRet.push_back(witnessprogram);
|
vSolutionsRet.push_back(witnessprogram);
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in a new issue