MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / ProduceSignature

Function ProduceSignature

src/script/sign.cpp:745–817  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

743}
744
745bool ProduceSignature(const SigningProvider& provider, const BaseSignatureCreator& creator, const CScript& fromPubKey, SignatureData& sigdata)
746{
747 if (sigdata.complete) return true;
748
749 std::vector<valtype> result;
750 TxoutType whichType;
751 bool solved = SignStep(provider, creator, fromPubKey, result, whichType, SigVersion::BASE, sigdata);
752 bool P2SH = false;
753 CScript subscript;
754
755 if (solved && whichType == TxoutType::SCRIPTHASH)
756 {
757 // Solver returns the subscript that needs to be evaluated;
758 // the final scriptSig is the signatures from that
759 // and then the serialized subscript:
760 subscript = CScript(result[0].begin(), result[0].end());
761 sigdata.redeem_script = subscript;
762 solved = solved && SignStep(provider, creator, subscript, result, whichType, SigVersion::BASE, sigdata) && whichType != TxoutType::SCRIPTHASH;
763 P2SH = true;
764 }
765
766 if (solved && whichType == TxoutType::WITNESS_V0_KEYHASH)
767 {
768 CScript witnessscript;
769 witnessscript << OP_DUP << OP_HASH160 << ToByteVector(result[0]) << OP_EQUALVERIFY << OP_CHECKSIG;
770 TxoutType subType;
771 solved = solved && SignStep(provider, creator, witnessscript, result, subType, SigVersion::WITNESS_V0, sigdata);
772 sigdata.scriptWitness.stack = result;
773 sigdata.witness = true;
774 result.clear();
775 }
776 else if (solved && whichType == TxoutType::WITNESS_V0_SCRIPTHASH)
777 {
778 CScript witnessscript(result[0].begin(), result[0].end());
779 sigdata.witness_script = witnessscript;
780
781 TxoutType subType{TxoutType::NONSTANDARD};
782 solved = solved && SignStep(provider, creator, witnessscript, result, subType, SigVersion::WITNESS_V0, sigdata) && subType != TxoutType::SCRIPTHASH && subType != TxoutType::WITNESS_V0_SCRIPTHASH && subType != TxoutType::WITNESS_V0_KEYHASH;
783
784 // If we couldn't find a solution with the legacy satisfier, try satisfying the script using Miniscript.
785 // Note we need to check if the result stack is empty before, because it might be used even if the Script
786 // isn't fully solved. For instance the CHECKMULTISIG satisfaction in SignStep() pushes partial signatures
787 // and the extractor relies on this behaviour to combine witnesses.
788 if (!solved && result.empty()) {
789 WshSatisfier ms_satisfier{provider, sigdata, creator, witnessscript};
790 const auto ms = miniscript::FromScript(witnessscript, ms_satisfier);
791 solved = ms && ms->Satisfy(ms_satisfier, result) == miniscript::Availability::YES;
792 }
793 result.emplace_back(witnessscript.begin(), witnessscript.end());
794
795 sigdata.scriptWitness.stack = result;
796 sigdata.witness = true;
797 result.clear();
798 } else if (whichType == TxoutType::WITNESS_V1_TAPROOT && !P2SH) {
799 sigdata.witness = true;
800 if (solved) {
801 sigdata.scriptWitness.stack = std::move(result);
802 }

Callers 13

MutateTxSignFunction · 0.85
UpdatePSBTOutputFunction · 0.85
SignPSBTInputFunction · 0.85
CanProvideMethod · 0.85
SignTransactionFunction · 0.85
BOOST_FIXTURE_TEST_CASEFunction · 0.85
CombineSignaturesFunction · 0.85
CombineSignaturesFunction · 0.85
DoCheckFunction · 0.85
script_sign.cppFile · 0.85
SignSignatureFunction · 0.85

Calls 12

SignStepFunction · 0.85
ToByteVectorFunction · 0.85
FromScriptFunction · 0.85
VerifyScriptFunction · 0.85
SatisfyMethod · 0.80
CScriptClass · 0.70
PushAllFunction · 0.70
beginMethod · 0.45
endMethod · 0.45
clearMethod · 0.45
emptyMethod · 0.45
emplace_backMethod · 0.45

Tested by 6

BOOST_FIXTURE_TEST_CASEFunction · 0.68
CombineSignaturesFunction · 0.68
CombineSignaturesFunction · 0.68
DoCheckFunction · 0.68
SignSignatureFunction · 0.68