Skip to content

Commit

Permalink
dummy sig checker
Browse files Browse the repository at this point in the history
when --tx etc aren't specified, use dummy sig checker
  • Loading branch information
ajtowns committed May 9, 2024
1 parent c171271 commit d83bad9
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/bitcoin-util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,20 @@ static uint32_t parse_verify_flags(const std::string& strFlags)
}

//! Public key to be used as internal key for dummy Taproot spends.
static const std::vector<unsigned char> NUMS_PK{ParseHex("50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0")};
static const std::vector<unsigned char> NUMS_H{ParseHex("50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0")};

namespace {
/** Dummy signature checker which accepts all signatures. */
class DummySignatureChecker final : public BaseSignatureChecker
{
public:
DummySignatureChecker() = default;
bool CheckECDSASignature(const std::vector<unsigned char>& sig, const std::vector<unsigned char>& vchPubKey, const CScript& scriptCode, SigVersion sigversion) const override { return sig.size() != 0; }
bool CheckSchnorrSignature(Span<const unsigned char> sig, KeyVersion pubkeyver, Span<const unsigned char> pubkey, SigVersion sigversion, ScriptExecutionData& execdata, ScriptError* serror) const override { return sig.size() != 0; }
bool CheckLockTime(const CScriptNum& nLockTime) const override { return true; }
bool CheckSequence(const CScriptNum& nSequence) const override { return true; }
};
}

static int EvalScript(const ArgsManager& argsman, const std::vector<std::string>& args, std::string& strPrint)
{
Expand Down Expand Up @@ -253,6 +266,10 @@ static int EvalScript(const ArgsManager& argsman, const std::vector<std::string>
}
}

if (sigversion == SigVersion::TAPSCRIPT) {
execdata.m_internal_key.emplace(NUMS_H);
}

if (const auto txhex = argsman.GetArg("-tx"); txhex.has_value()) {
const int input = argsman.GetIntArg("-input", 0);
const auto spent_outputs_hex = argsman.GetArgs("-spent_output");
Expand Down Expand Up @@ -293,14 +310,13 @@ static int EvalScript(const ArgsManager& argsman, const std::vector<std::string>
checker = std::make_unique<TransactionSignatureChecker>(txTo.get(), input, amount, txdata, MissingDataBehavior::ASSERT_FAIL);

if (sigversion == SigVersion::TAPSCRIPT && input >= 0 && input_in_range) {
XOnlyPubKey ipk{NUMS_PK};
if (const auto ipkhex = argsman.GetArg("-ipk"); ipkhex.has_value()) {
if (!IsHex(*ipkhex) || ipkhex->size() != 64) {
strPrint = strprintf("Not a valid x-only pubkey: -ipk=%s", *ipkhex);
return EXIT_FAILURE;
}
auto ipkbytes = ParseHex(*ipkhex);
std::copy(ipkbytes.begin(), ipkbytes.end(), ipk.begin());
std::copy(ipkbytes.begin(), ipkbytes.end(), execdata.m_internal_key->begin());
}

const CTxIn& txin = txTo->vin.at(input);
Expand All @@ -319,10 +335,9 @@ static int EvalScript(const ArgsManager& argsman, const std::vector<std::string>
execdata.m_tapleaf_hash_init = true;
execdata.m_validation_weight_left = ::GetSerializeSize(stack) + ::GetSerializeSize(script) + VALIDATION_WEIGHT_OFFSET;
execdata.m_validation_weight_left_init = true;
execdata.m_internal_key = ipk;
}
} else {
checker = std::make_unique<BaseSignatureChecker>();
checker = std::make_unique<DummySignatureChecker>();
}

if (sigversion == SigVersion::TAPSCRIPT && !execdata.m_annex_init) {
Expand Down

0 comments on commit d83bad9

Please sign in to comment.