mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-05-15 20:50:41 +02:00
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.
This commit is contained in:
parent
c232ef20c0
commit
b16f93cadd
@ -627,25 +627,6 @@ public:
|
|||||||
const BaseSignatureCreator& DUMMY_SIGNATURE_CREATOR = DummySignatureCreator(32, 32);
|
const BaseSignatureCreator& DUMMY_SIGNATURE_CREATOR = DummySignatureCreator(32, 32);
|
||||||
const BaseSignatureCreator& DUMMY_MAXIMUM_SIGNATURE_CREATOR = DummySignatureCreator(33, 32);
|
const BaseSignatureCreator& DUMMY_MAXIMUM_SIGNATURE_CREATOR = DummySignatureCreator(33, 32);
|
||||||
|
|
||||||
bool IsSolvable(const SigningProvider& provider, const CScript& script)
|
|
||||||
{
|
|
||||||
// This check is to make sure that the script we created can actually be solved for and signed by us
|
|
||||||
// if we were to have the private keys. This is just to make sure that the script is valid and that,
|
|
||||||
// if found in a transaction, we would still accept and relay that transaction. In particular,
|
|
||||||
// it will reject witness outputs that require signing with an uncompressed public key.
|
|
||||||
SignatureData sigs;
|
|
||||||
// Make sure that STANDARD_SCRIPT_VERIFY_FLAGS includes SCRIPT_VERIFY_WITNESS_PUBKEYTYPE, the most
|
|
||||||
// important property this function is designed to test for.
|
|
||||||
static_assert(STANDARD_SCRIPT_VERIFY_FLAGS & SCRIPT_VERIFY_WITNESS_PUBKEYTYPE, "IsSolvable requires standard script flags to include WITNESS_PUBKEYTYPE");
|
|
||||||
if (ProduceSignature(provider, DUMMY_SIGNATURE_CREATOR, script, sigs)) {
|
|
||||||
// VerifyScript check is just defensive, and should never fail.
|
|
||||||
bool verified = VerifyScript(sigs.scriptSig, script, &sigs.scriptWitness, STANDARD_SCRIPT_VERIFY_FLAGS, DUMMY_CHECKER);
|
|
||||||
assert(verified);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IsSegWitOutput(const SigningProvider& provider, const CScript& script)
|
bool IsSegWitOutput(const SigningProvider& provider, const CScript& script)
|
||||||
{
|
{
|
||||||
int version;
|
int version;
|
||||||
|
@ -97,12 +97,6 @@ bool SignSignature(const SigningProvider &provider, const CTransaction& txFrom,
|
|||||||
SignatureData DataFromTransaction(const CMutableTransaction& tx, unsigned int nIn, const CTxOut& txout);
|
SignatureData DataFromTransaction(const CMutableTransaction& tx, unsigned int nIn, const CTxOut& txout);
|
||||||
void UpdateInput(CTxIn& input, const SignatureData& data);
|
void UpdateInput(CTxIn& input, const SignatureData& data);
|
||||||
|
|
||||||
/* Check whether we know how to sign for an output like this, assuming we
|
|
||||||
* have all private keys. While this function does not need private keys, the passed
|
|
||||||
* provider is used to look up public keys and redeemscripts by hash.
|
|
||||||
* Solvability is unrelated to whether we consider this output to be ours. */
|
|
||||||
bool IsSolvable(const SigningProvider& provider, const CScript& script);
|
|
||||||
|
|
||||||
/** Check whether a scriptPubKey is known to be segwit. */
|
/** Check whether a scriptPubKey is known to be segwit. */
|
||||||
bool IsSegWitOutput(const SigningProvider& provider, const CScript& script);
|
bool IsSegWitOutput(const SigningProvider& provider, const CScript& script);
|
||||||
|
|
||||||
|
@ -302,7 +302,6 @@ void DoCheck(const std::string& prv, const std::string& pub, const std::string&
|
|||||||
// For each of the produced scripts, verify solvability, and when possible, try to sign a transaction spending it.
|
// For each of the produced scripts, verify solvability, and when possible, try to sign a transaction spending it.
|
||||||
for (size_t n = 0; n < spks.size(); ++n) {
|
for (size_t n = 0; n < spks.size(); ++n) {
|
||||||
BOOST_CHECK_EQUAL(ref[n], HexStr(spks[n]));
|
BOOST_CHECK_EQUAL(ref[n], HexStr(spks[n]));
|
||||||
BOOST_CHECK_EQUAL(IsSolvable(Merge(key_provider, script_provider), spks[n]), (flags & UNSOLVABLE) == 0);
|
|
||||||
|
|
||||||
if (flags & SIGNABLE) {
|
if (flags & SIGNABLE) {
|
||||||
CMutableTransaction spend;
|
CMutableTransaction spend;
|
||||||
@ -324,7 +323,7 @@ void DoCheck(const std::string& prv, const std::string& pub, const std::string&
|
|||||||
BOOST_CHECK(inferred->Expand(0, provider_inferred, spks_inferred, provider_inferred));
|
BOOST_CHECK(inferred->Expand(0, provider_inferred, spks_inferred, provider_inferred));
|
||||||
BOOST_CHECK_EQUAL(spks_inferred.size(), 1U);
|
BOOST_CHECK_EQUAL(spks_inferred.size(), 1U);
|
||||||
BOOST_CHECK(spks_inferred[0] == spks[n]);
|
BOOST_CHECK(spks_inferred[0] == spks[n]);
|
||||||
BOOST_CHECK_EQUAL(IsSolvable(provider_inferred, spks_inferred[0]), !(flags & UNSOLVABLE));
|
BOOST_CHECK_EQUAL(InferDescriptor(spks_inferred[0], provider_inferred)->IsSolvable(), !(flags & UNSOLVABLE));
|
||||||
BOOST_CHECK(GetKeyOriginData(provider_inferred, flags) == GetKeyOriginData(script_provider, flags));
|
BOOST_CHECK(GetKeyOriginData(provider_inferred, flags) == GetKeyOriginData(script_provider, flags));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,8 +138,6 @@ FUZZ_TARGET_INIT(key, initialize_key)
|
|||||||
assert(tx_multisig_script.size() == 37);
|
assert(tx_multisig_script.size() == 37);
|
||||||
|
|
||||||
FillableSigningProvider fillable_signing_provider;
|
FillableSigningProvider fillable_signing_provider;
|
||||||
assert(IsSolvable(fillable_signing_provider, tx_pubkey_script));
|
|
||||||
assert(IsSolvable(fillable_signing_provider, tx_multisig_script));
|
|
||||||
assert(!IsSegWitOutput(fillable_signing_provider, tx_pubkey_script));
|
assert(!IsSegWitOutput(fillable_signing_provider, tx_pubkey_script));
|
||||||
assert(!IsSegWitOutput(fillable_signing_provider, tx_multisig_script));
|
assert(!IsSegWitOutput(fillable_signing_provider, tx_multisig_script));
|
||||||
assert(fillable_signing_provider.GetKeys().size() == 0);
|
assert(fillable_signing_provider.GetKeys().size() == 0);
|
||||||
|
@ -89,7 +89,6 @@ FUZZ_TARGET_INIT(script, initialize_script)
|
|||||||
const FlatSigningProvider signing_provider;
|
const FlatSigningProvider signing_provider;
|
||||||
(void)InferDescriptor(script, signing_provider);
|
(void)InferDescriptor(script, signing_provider);
|
||||||
(void)IsSegWitOutput(signing_provider, script);
|
(void)IsSegWitOutput(signing_provider, script);
|
||||||
(void)IsSolvable(signing_provider, script);
|
|
||||||
|
|
||||||
(void)RecursiveDynamicUsage(script);
|
(void)RecursiveDynamicUsage(script);
|
||||||
|
|
||||||
|
@ -578,7 +578,7 @@ RPCHelpMan getaddressinfo()
|
|||||||
|
|
||||||
if (provider) {
|
if (provider) {
|
||||||
auto inferred = InferDescriptor(scriptPubKey, *provider);
|
auto inferred = InferDescriptor(scriptPubKey, *provider);
|
||||||
bool solvable = inferred->IsSolvable() || IsSolvable(*provider, scriptPubKey);
|
bool solvable = inferred->IsSolvable();
|
||||||
ret.pushKV("solvable", solvable);
|
ret.pushKV("solvable", solvable);
|
||||||
if (solvable) {
|
if (solvable) {
|
||||||
ret.pushKV("desc", inferred->ToString());
|
ret.pushKV("desc", inferred->ToString());
|
||||||
|
@ -1453,7 +1453,8 @@ void LegacyScriptPubKeyMan::LearnRelatedScripts(const CPubKey& key, OutputType t
|
|||||||
CTxDestination witdest = WitnessV0KeyHash(key.GetID());
|
CTxDestination witdest = WitnessV0KeyHash(key.GetID());
|
||||||
CScript witprog = GetScriptForDestination(witdest);
|
CScript witprog = GetScriptForDestination(witdest);
|
||||||
// Make sure the resulting program is solvable.
|
// Make sure the resulting program is solvable.
|
||||||
assert(IsSolvable(*this, witprog));
|
const auto desc = InferDescriptor(witprog, *this);
|
||||||
|
assert(desc && desc->IsSolvable());
|
||||||
AddCScript(witprog);
|
AddCScript(witprog);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user