Skip to content

Commit f08a187

Browse files
achow101claude
authored andcommitted
Merge bitcoin#25664: refactor: Redefine IsSolvable() using descriptors
1 parent 35c7990 commit f08a187

5 files changed

Lines changed: 10 additions & 28 deletions

File tree

src/script/sign.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -381,21 +381,6 @@ class DummySignatureCreator final : public BaseSignatureCreator {
381381
const BaseSignatureCreator& DUMMY_SIGNATURE_CREATOR = DummySignatureCreator(32, 32);
382382
const BaseSignatureCreator& DUMMY_MAXIMUM_SIGNATURE_CREATOR = DummySignatureCreator(33, 32);
383383

384-
bool IsSolvable(const SigningProvider& provider, const CScript& script)
385-
{
386-
// This check is to make sure that the script we created can actually be solved for and signed by us
387-
// if we were to have the private keys. This is just to make sure that the script is valid and that,
388-
// if found in a transaction, we would still accept and relay that transaction.
389-
SignatureData sigs;
390-
if (ProduceSignature(provider, DUMMY_SIGNATURE_CREATOR, script, sigs)) {
391-
// VerifyScript check is just defensive, and should never fail.
392-
bool verified = VerifyScript(sigs.scriptSig, script, STANDARD_SCRIPT_VERIFY_FLAGS, DUMMY_CHECKER);
393-
assert(verified);
394-
return true;
395-
}
396-
return false;
397-
}
398-
399384
bool SignTransaction(CMutableTransaction& mtx, const SigningProvider* keystore, const std::map<COutPoint, Coin>& coins, int nHashType, std::map<int, bilingual_str>& input_errors)
400385
{
401386
bool fHashSingle = ((nHashType & ~SIGHASH_ANYONECANPAY) == SIGHASH_SINGLE);

src/script/sign.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,6 @@ bool SignSignature(const SigningProvider &provider, const CTransaction& txFrom,
8686
SignatureData DataFromTransaction(const CMutableTransaction& tx, unsigned int nIn, const CTxOut& txout);
8787
void UpdateInput(CTxIn& input, const SignatureData& data);
8888

89-
/* Check whether we know how to sign for an output like this, assuming we
90-
* have all private keys. While this function does not need private keys, the passed
91-
* provider is used to look up public keys and redeemscripts by hash.
92-
* Solvability is unrelated to whether we consider this output to be ours. */
93-
bool IsSolvable(const SigningProvider& provider, const CScript& script);
9489

9590
/** Sign the CMutableTransaction */
9691
bool SignTransaction(CMutableTransaction& mtx, const SigningProvider* provider, const std::map<COutPoint, Coin>& coins, int sighash, std::map<int, bilingual_str>& input_errors);

src/test/descriptor_tests.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ void DoCheck(const std::string& prv, const std::string& pub, const std::string&
234234
// For each of the produced scripts, verify solvability, and when possible, try to sign a transaction spending it.
235235
for (size_t n = 0; n < spks.size(); ++n) {
236236
BOOST_CHECK_EQUAL(ref[n], HexStr(spks[n]));
237-
BOOST_CHECK_EQUAL(IsSolvable(FlatSigningProvider{key_provider}.Merge(FlatSigningProvider{script_provider}), spks[n]), (flags & UNSOLVABLE) == 0);
238237

239238
if (flags & SIGNABLE) {
240239
CMutableTransaction spend;
@@ -251,7 +250,7 @@ void DoCheck(const std::string& prv, const std::string& pub, const std::string&
251250
BOOST_CHECK(inferred->Expand(0, provider_inferred, spks_inferred, provider_inferred));
252251
BOOST_CHECK_EQUAL(spks_inferred.size(), 1U);
253252
BOOST_CHECK(spks_inferred[0] == spks[n]);
254-
BOOST_CHECK_EQUAL(IsSolvable(provider_inferred, spks_inferred[0]), !(flags & UNSOLVABLE));
253+
BOOST_CHECK_EQUAL(InferDescriptor(spks_inferred[0], provider_inferred)->IsSolvable(), !(flags & UNSOLVABLE));
255254
BOOST_CHECK(provider_inferred.origins == script_provider.origins);
256255
}
257256

src/test/fuzz/script.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ FUZZ_TARGET(script, .init = initialize_script)
8383

8484
const FlatSigningProvider signing_provider;
8585
(void)InferDescriptor(script, signing_provider);
86-
(void)IsSolvable(signing_provider, script);
8786

8887
(void)RecursiveDynamicUsage(script);
8988

src/wallet/rpc/addresses.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -499,11 +499,15 @@ RPCHelpMan getaddressinfo()
499499
isminetype mine = pwallet->IsMine(dest);
500500
ret.pushKV("ismine", bool(mine & ISMINE_SPENDABLE));
501501

502-
bool solvable = provider && IsSolvable(*provider, scriptPubKey);
503-
ret.pushKV("solvable", solvable);
504-
505-
if (solvable) {
506-
ret.pushKV("desc", InferDescriptor(scriptPubKey, *provider)->ToString());
502+
if (provider) {
503+
auto inferred = InferDescriptor(scriptPubKey, *provider);
504+
bool solvable = inferred->IsSolvable();
505+
ret.pushKV("solvable", solvable);
506+
if (solvable) {
507+
ret.pushKV("desc", inferred->ToString());
508+
}
509+
} else {
510+
ret.pushKV("solvable", false);
507511
}
508512

509513
DescriptorScriptPubKeyMan* desc_spk_man = dynamic_cast<DescriptorScriptPubKeyMan*>(pwallet->GetScriptPubKeyMan(scriptPubKey));

0 commit comments

Comments
 (0)