Skip to content

Commit b16f93c

Browse files
committed
script/sign: remove needless IsSolvable() utility
It was used back when we didn't have a concept of descriptor. Now we can check for solvability using descriptors.
1 parent c232ef2 commit b16f93c

File tree

7 files changed

+4
-32
lines changed

7 files changed

+4
-32
lines changed

src/script/sign.cpp

-19
Original file line numberDiff line numberDiff line change
@@ -627,25 +627,6 @@ class DummySignatureCreator final : public BaseSignatureCreator {
627627
const BaseSignatureCreator& DUMMY_SIGNATURE_CREATOR = DummySignatureCreator(32, 32);
628628
const BaseSignatureCreator& DUMMY_MAXIMUM_SIGNATURE_CREATOR = DummySignatureCreator(33, 32);
629629

630-
bool IsSolvable(const SigningProvider& provider, const CScript& script)
631-
{
632-
// This check is to make sure that the script we created can actually be solved for and signed by us
633-
// if we were to have the private keys. This is just to make sure that the script is valid and that,
634-
// if found in a transaction, we would still accept and relay that transaction. In particular,
635-
// it will reject witness outputs that require signing with an uncompressed public key.
636-
SignatureData sigs;
637-
// Make sure that STANDARD_SCRIPT_VERIFY_FLAGS includes SCRIPT_VERIFY_WITNESS_PUBKEYTYPE, the most
638-
// important property this function is designed to test for.
639-
static_assert(STANDARD_SCRIPT_VERIFY_FLAGS & SCRIPT_VERIFY_WITNESS_PUBKEYTYPE, "IsSolvable requires standard script flags to include WITNESS_PUBKEYTYPE");
640-
if (ProduceSignature(provider, DUMMY_SIGNATURE_CREATOR, script, sigs)) {
641-
// VerifyScript check is just defensive, and should never fail.
642-
bool verified = VerifyScript(sigs.scriptSig, script, &sigs.scriptWitness, STANDARD_SCRIPT_VERIFY_FLAGS, DUMMY_CHECKER);
643-
assert(verified);
644-
return true;
645-
}
646-
return false;
647-
}
648-
649630
bool IsSegWitOutput(const SigningProvider& provider, const CScript& script)
650631
{
651632
int version;

src/script/sign.h

-6
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,6 @@ bool SignSignature(const SigningProvider &provider, const CTransaction& txFrom,
9797
SignatureData DataFromTransaction(const CMutableTransaction& tx, unsigned int nIn, const CTxOut& txout);
9898
void UpdateInput(CTxIn& input, const SignatureData& data);
9999

100-
/* Check whether we know how to sign for an output like this, assuming we
101-
* have all private keys. While this function does not need private keys, the passed
102-
* provider is used to look up public keys and redeemscripts by hash.
103-
* Solvability is unrelated to whether we consider this output to be ours. */
104-
bool IsSolvable(const SigningProvider& provider, const CScript& script);
105-
106100
/** Check whether a scriptPubKey is known to be segwit. */
107101
bool IsSegWitOutput(const SigningProvider& provider, const CScript& script);
108102

src/test/descriptor_tests.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,6 @@ void DoCheck(const std::string& prv, const std::string& pub, const std::string&
302302
// For each of the produced scripts, verify solvability, and when possible, try to sign a transaction spending it.
303303
for (size_t n = 0; n < spks.size(); ++n) {
304304
BOOST_CHECK_EQUAL(ref[n], HexStr(spks[n]));
305-
BOOST_CHECK_EQUAL(IsSolvable(Merge(key_provider, script_provider), spks[n]), (flags & UNSOLVABLE) == 0);
306305

307306
if (flags & SIGNABLE) {
308307
CMutableTransaction spend;
@@ -324,7 +323,7 @@ void DoCheck(const std::string& prv, const std::string& pub, const std::string&
324323
BOOST_CHECK(inferred->Expand(0, provider_inferred, spks_inferred, provider_inferred));
325324
BOOST_CHECK_EQUAL(spks_inferred.size(), 1U);
326325
BOOST_CHECK(spks_inferred[0] == spks[n]);
327-
BOOST_CHECK_EQUAL(IsSolvable(provider_inferred, spks_inferred[0]), !(flags & UNSOLVABLE));
326+
BOOST_CHECK_EQUAL(InferDescriptor(spks_inferred[0], provider_inferred)->IsSolvable(), !(flags & UNSOLVABLE));
328327
BOOST_CHECK(GetKeyOriginData(provider_inferred, flags) == GetKeyOriginData(script_provider, flags));
329328
}
330329

src/test/fuzz/key.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,6 @@ FUZZ_TARGET_INIT(key, initialize_key)
138138
assert(tx_multisig_script.size() == 37);
139139

140140
FillableSigningProvider fillable_signing_provider;
141-
assert(IsSolvable(fillable_signing_provider, tx_pubkey_script));
142-
assert(IsSolvable(fillable_signing_provider, tx_multisig_script));
143141
assert(!IsSegWitOutput(fillable_signing_provider, tx_pubkey_script));
144142
assert(!IsSegWitOutput(fillable_signing_provider, tx_multisig_script));
145143
assert(fillable_signing_provider.GetKeys().size() == 0);

src/test/fuzz/script.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ FUZZ_TARGET_INIT(script, initialize_script)
8989
const FlatSigningProvider signing_provider;
9090
(void)InferDescriptor(script, signing_provider);
9191
(void)IsSegWitOutput(signing_provider, script);
92-
(void)IsSolvable(signing_provider, script);
9392

9493
(void)RecursiveDynamicUsage(script);
9594

src/wallet/rpc/addresses.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ RPCHelpMan getaddressinfo()
578578

579579
if (provider) {
580580
auto inferred = InferDescriptor(scriptPubKey, *provider);
581-
bool solvable = inferred->IsSolvable() || IsSolvable(*provider, scriptPubKey);
581+
bool solvable = inferred->IsSolvable();
582582
ret.pushKV("solvable", solvable);
583583
if (solvable) {
584584
ret.pushKV("desc", inferred->ToString());

src/wallet/scriptpubkeyman.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1453,7 +1453,8 @@ void LegacyScriptPubKeyMan::LearnRelatedScripts(const CPubKey& key, OutputType t
14531453
CTxDestination witdest = WitnessV0KeyHash(key.GetID());
14541454
CScript witprog = GetScriptForDestination(witdest);
14551455
// Make sure the resulting program is solvable.
1456-
assert(IsSolvable(*this, witprog));
1456+
const auto desc = InferDescriptor(witprog, *this);
1457+
assert(desc && desc->IsSolvable());
14571458
AddCScript(witprog);
14581459
}
14591460
}

0 commit comments

Comments
 (0)