mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 15:09:59 +01:00
Remove CombineSignatures and replace tests
Removes CombineSignatures and replaces its use in tests with ProduceSignature to test the same behavior for ProduceSignature.
This commit is contained in:
@@ -377,146 +377,6 @@ bool SignSignature(const SigningProvider &provider, const CTransaction& txFrom,
|
||||
return SignSignature(provider, txout.scriptPubKey, txTo, nIn, txout.nValue, nHashType);
|
||||
}
|
||||
|
||||
static std::vector<valtype> CombineMultisig(const CScript& scriptPubKey, const BaseSignatureChecker& checker,
|
||||
const std::vector<valtype>& vSolutions,
|
||||
const std::vector<valtype>& sigs1, const std::vector<valtype>& sigs2, SigVersion sigversion)
|
||||
{
|
||||
// Combine all the signatures we've got:
|
||||
std::set<valtype> allsigs;
|
||||
for (const valtype& v : sigs1)
|
||||
{
|
||||
if (!v.empty())
|
||||
allsigs.insert(v);
|
||||
}
|
||||
for (const valtype& v : sigs2)
|
||||
{
|
||||
if (!v.empty())
|
||||
allsigs.insert(v);
|
||||
}
|
||||
|
||||
// Build a map of pubkey -> signature by matching sigs to pubkeys:
|
||||
assert(vSolutions.size() > 1);
|
||||
unsigned int nSigsRequired = vSolutions.front()[0];
|
||||
unsigned int nPubKeys = vSolutions.size()-2;
|
||||
std::map<valtype, valtype> sigs;
|
||||
for (const valtype& sig : allsigs)
|
||||
{
|
||||
for (unsigned int i = 0; i < nPubKeys; i++)
|
||||
{
|
||||
const valtype& pubkey = vSolutions[i+1];
|
||||
if (sigs.count(pubkey))
|
||||
continue; // Already got a sig for this pubkey
|
||||
|
||||
if (checker.CheckSig(sig, pubkey, scriptPubKey, sigversion))
|
||||
{
|
||||
sigs[pubkey] = sig;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Now build a merged CScript:
|
||||
unsigned int nSigsHave = 0;
|
||||
std::vector<valtype> result; result.push_back(valtype()); // pop-one-too-many workaround
|
||||
for (unsigned int i = 0; i < nPubKeys && nSigsHave < nSigsRequired; i++)
|
||||
{
|
||||
if (sigs.count(vSolutions[i+1]))
|
||||
{
|
||||
result.push_back(sigs[vSolutions[i+1]]);
|
||||
++nSigsHave;
|
||||
}
|
||||
}
|
||||
// Fill any missing with OP_0:
|
||||
for (unsigned int i = nSigsHave; i < nSigsRequired; i++)
|
||||
result.push_back(valtype());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static Stacks CombineSignatures(const CScript& scriptPubKey, const BaseSignatureChecker& checker,
|
||||
const txnouttype txType, const std::vector<valtype>& vSolutions,
|
||||
Stacks sigs1, Stacks sigs2, SigVersion sigversion)
|
||||
{
|
||||
switch (txType)
|
||||
{
|
||||
case TX_NONSTANDARD:
|
||||
case TX_NULL_DATA:
|
||||
case TX_WITNESS_UNKNOWN:
|
||||
// Don't know anything about this, assume bigger one is correct:
|
||||
if (sigs1.script.size() >= sigs2.script.size())
|
||||
return sigs1;
|
||||
return sigs2;
|
||||
case TX_PUBKEY:
|
||||
case TX_PUBKEYHASH:
|
||||
// Signatures are bigger than placeholders or empty scripts:
|
||||
if (sigs1.script.empty() || sigs1.script[0].empty())
|
||||
return sigs2;
|
||||
return sigs1;
|
||||
case TX_WITNESS_V0_KEYHASH:
|
||||
// Signatures are bigger than placeholders or empty scripts:
|
||||
if (sigs1.witness.empty() || sigs1.witness[0].empty())
|
||||
return sigs2;
|
||||
return sigs1;
|
||||
case TX_SCRIPTHASH:
|
||||
if (sigs1.script.empty() || sigs1.script.back().empty())
|
||||
return sigs2;
|
||||
else if (sigs2.script.empty() || sigs2.script.back().empty())
|
||||
return sigs1;
|
||||
else
|
||||
{
|
||||
// Recur to combine:
|
||||
valtype spk = sigs1.script.back();
|
||||
CScript pubKey2(spk.begin(), spk.end());
|
||||
|
||||
txnouttype txType2;
|
||||
std::vector<std::vector<unsigned char> > vSolutions2;
|
||||
Solver(pubKey2, txType2, vSolutions2);
|
||||
sigs1.script.pop_back();
|
||||
sigs2.script.pop_back();
|
||||
Stacks result = CombineSignatures(pubKey2, checker, txType2, vSolutions2, sigs1, sigs2, sigversion);
|
||||
result.script.push_back(spk);
|
||||
return result;
|
||||
}
|
||||
case TX_MULTISIG:
|
||||
return Stacks(CombineMultisig(scriptPubKey, checker, vSolutions, sigs1.script, sigs2.script, sigversion));
|
||||
case TX_WITNESS_V0_SCRIPTHASH:
|
||||
if (sigs1.witness.empty() || sigs1.witness.back().empty())
|
||||
return sigs2;
|
||||
else if (sigs2.witness.empty() || sigs2.witness.back().empty())
|
||||
return sigs1;
|
||||
else
|
||||
{
|
||||
// Recur to combine:
|
||||
CScript pubKey2(sigs1.witness.back().begin(), sigs1.witness.back().end());
|
||||
txnouttype txType2;
|
||||
std::vector<valtype> vSolutions2;
|
||||
Solver(pubKey2, txType2, vSolutions2);
|
||||
sigs1.witness.pop_back();
|
||||
sigs1.script = sigs1.witness;
|
||||
sigs1.witness.clear();
|
||||
sigs2.witness.pop_back();
|
||||
sigs2.script = sigs2.witness;
|
||||
sigs2.witness.clear();
|
||||
Stacks result = CombineSignatures(pubKey2, checker, txType2, vSolutions2, sigs1, sigs2, SigVersion::WITNESS_V0);
|
||||
result.witness = result.script;
|
||||
result.script.clear();
|
||||
result.witness.push_back(valtype(pubKey2.begin(), pubKey2.end()));
|
||||
return result;
|
||||
}
|
||||
default:
|
||||
return Stacks();
|
||||
}
|
||||
}
|
||||
|
||||
SignatureData CombineSignatures(const CScript& scriptPubKey, const BaseSignatureChecker& checker,
|
||||
const SignatureData& scriptSig1, const SignatureData& scriptSig2)
|
||||
{
|
||||
txnouttype txType;
|
||||
std::vector<std::vector<unsigned char> > vSolutions;
|
||||
Solver(scriptPubKey, txType, vSolutions);
|
||||
|
||||
return CombineSignatures(scriptPubKey, checker, txType, vSolutions, Stacks(scriptSig1), Stacks(scriptSig2), SigVersion::BASE).Output();
|
||||
}
|
||||
|
||||
namespace {
|
||||
/** Dummy signature checker which accepts all signatures. */
|
||||
class DummySignatureChecker final : public BaseSignatureChecker
|
||||
|
||||
@@ -80,9 +80,6 @@ bool ProduceSignature(const SigningProvider& provider, const BaseSignatureCreato
|
||||
bool SignSignature(const SigningProvider &provider, const CScript& fromPubKey, CMutableTransaction& txTo, unsigned int nIn, const CAmount& amount, int nHashType);
|
||||
bool SignSignature(const SigningProvider &provider, const CTransaction& txFrom, CMutableTransaction& txTo, unsigned int nIn, int nHashType);
|
||||
|
||||
/** Combine two script signatures using a generic signature checker, intelligently, possibly with OP_0 placeholders. */
|
||||
SignatureData CombineSignatures(const CScript& scriptPubKey, const BaseSignatureChecker& checker, const SignatureData& scriptSig1, const SignatureData& scriptSig2);
|
||||
|
||||
/** Extract signature data from a transaction input, and insert it. */
|
||||
SignatureData DataFromTransaction(const CMutableTransaction& tx, unsigned int nIn, const CTxOut& txout);
|
||||
void UpdateInput(CTxIn& input, const SignatureData& data);
|
||||
|
||||
Reference in New Issue
Block a user