Skip to content

Commit 79f20fa

Browse files
committed
Merge bitcoin/bitcoin#30561: refactor: move SignSignature helpers to test utils
58499b0 refactor: move `SignSignature` helpers to test utils (Sebastian Falbesoner) Pull request description: These helpers haven't been used in production code since segwit was merged more than eight years ago (see commit 605e847, PR #8149), so it seems appropriate to move them to the test utils module. As suggested by instagibbs, see bitcoin/bitcoin#30352 (comment). ACKs for top commit: instagibbs: ACK 58499b0 pablomartin4btc: ACK 58499b0 Tree-SHA512: a52d3b92b477246f2ceb57c3690d0229a492b65a15dae331faeae9d96e5907f7fe1176edc1530243e0f088586984fd7ba435a0a2d2f2531c04d076fdf3f4095f
2 parents 197aa24 + 58499b0 commit 79f20fa

File tree

7 files changed

+44
-40
lines changed

7 files changed

+44
-40
lines changed

src/script/sign.cpp

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -694,27 +694,6 @@ void SignatureData::MergeSignatureData(SignatureData sigdata)
694694
signatures.insert(std::make_move_iterator(sigdata.signatures.begin()), std::make_move_iterator(sigdata.signatures.end()));
695695
}
696696

697-
bool SignSignature(const SigningProvider &provider, const CScript& fromPubKey, CMutableTransaction& txTo, unsigned int nIn, const CAmount& amount, int nHashType, SignatureData& sig_data)
698-
{
699-
assert(nIn < txTo.vin.size());
700-
701-
MutableTransactionSignatureCreator creator(txTo, nIn, amount, nHashType);
702-
703-
bool ret = ProduceSignature(provider, creator, fromPubKey, sig_data);
704-
UpdateInput(txTo.vin.at(nIn), sig_data);
705-
return ret;
706-
}
707-
708-
bool SignSignature(const SigningProvider &provider, const CTransaction& txFrom, CMutableTransaction& txTo, unsigned int nIn, int nHashType, SignatureData& sig_data)
709-
{
710-
assert(nIn < txTo.vin.size());
711-
const CTxIn& txin = txTo.vin[nIn];
712-
assert(txin.prevout.n < txFrom.vout.size());
713-
const CTxOut& txout = txFrom.vout[txin.prevout.n];
714-
715-
return SignSignature(provider, txout.scriptPubKey, txTo, nIn, txout.nValue, nHashType, sig_data);
716-
}
717-
718697
namespace {
719698
/** Dummy signature checker which accepts all signatures. */
720699
class DummySignatureChecker final : public BaseSignatureChecker

src/script/sign.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -97,25 +97,6 @@ struct SignatureData {
9797
/** Produce a script signature using a generic signature creator. */
9898
bool ProduceSignature(const SigningProvider& provider, const BaseSignatureCreator& creator, const CScript& scriptPubKey, SignatureData& sigdata);
9999

100-
/**
101-
* Produce a satisfying script (scriptSig or witness).
102-
*
103-
* @param provider Utility containing the information necessary to solve a script.
104-
* @param fromPubKey The script to produce a satisfaction for.
105-
* @param txTo The spending transaction.
106-
* @param nIn The index of the input in `txTo` referring the output being spent.
107-
* @param amount The value of the output being spent.
108-
* @param nHashType Signature hash type.
109-
* @param sig_data Additional data provided to solve a script. Filled with the resulting satisfying
110-
* script and whether the satisfaction is complete.
111-
*
112-
* @return True if the produced script is entirely satisfying `fromPubKey`.
113-
**/
114-
bool SignSignature(const SigningProvider &provider, const CScript& fromPubKey, CMutableTransaction& txTo,
115-
unsigned int nIn, const CAmount& amount, int nHashType, SignatureData& sig_data);
116-
bool SignSignature(const SigningProvider &provider, const CTransaction& txFrom, CMutableTransaction& txTo,
117-
unsigned int nIn, int nHashType, SignatureData& sig_data);
118-
119100
/** Extract signature data from a transaction input, and insert it. */
120101
SignatureData DataFromTransaction(const CMutableTransaction& tx, unsigned int nIn, const CTxOut& txout);
121102
void UpdateInput(CTxIn& input, const SignatureData& data);

src/test/fuzz/script_sign.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <test/fuzz/FuzzedDataProvider.h>
1414
#include <test/fuzz/fuzz.h>
1515
#include <test/fuzz/util.h>
16+
#include <test/util/transaction_utils.h>
1617
#include <util/chaintype.h>
1718
#include <util/translation.h>
1819

src/test/multisig_tests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <script/sign.h>
1111
#include <script/signingprovider.h>
1212
#include <test/util/setup_common.h>
13+
#include <test/util/transaction_utils.h>
1314
#include <tinyformat.h>
1415
#include <uint256.h>
1516

src/test/script_p2sh_tests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <script/sign.h>
1212
#include <script/signingprovider.h>
1313
#include <test/util/setup_common.h>
14+
#include <test/util/transaction_utils.h>
1415
#include <validation.h>
1516

1617
#include <vector>

src/test/util/transaction_utils.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,24 @@ void BulkTransaction(CMutableTransaction& tx, int32_t target_weight)
9090
assert(GetTransactionWeight(CTransaction(tx)) >= target_weight);
9191
assert(GetTransactionWeight(CTransaction(tx)) <= target_weight + 3);
9292
}
93+
94+
bool SignSignature(const SigningProvider &provider, const CScript& fromPubKey, CMutableTransaction& txTo, unsigned int nIn, const CAmount& amount, int nHashType, SignatureData& sig_data)
95+
{
96+
assert(nIn < txTo.vin.size());
97+
98+
MutableTransactionSignatureCreator creator(txTo, nIn, amount, nHashType);
99+
100+
bool ret = ProduceSignature(provider, creator, fromPubKey, sig_data);
101+
UpdateInput(txTo.vin.at(nIn), sig_data);
102+
return ret;
103+
}
104+
105+
bool SignSignature(const SigningProvider &provider, const CTransaction& txFrom, CMutableTransaction& txTo, unsigned int nIn, int nHashType, SignatureData& sig_data)
106+
{
107+
assert(nIn < txTo.vin.size());
108+
const CTxIn& txin = txTo.vin[nIn];
109+
assert(txin.prevout.n < txFrom.vout.size());
110+
const CTxOut& txout = txFrom.vout[txin.prevout.n];
111+
112+
return SignSignature(provider, txout.scriptPubKey, txTo, nIn, txout.nValue, nHashType, sig_data);
113+
}

src/test/util/transaction_utils.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#define BITCOIN_TEST_UTIL_TRANSACTION_UTILS_H
77

88
#include <primitives/transaction.h>
9+
#include <script/sign.h>
910

1011
#include <array>
1112

@@ -30,4 +31,23 @@ std::vector<CMutableTransaction> SetupDummyInputs(FillableSigningProvider& keyst
3031
// by appending a single output with padded output script
3132
void BulkTransaction(CMutableTransaction& tx, int32_t target_weight);
3233

34+
/**
35+
* Produce a satisfying script (scriptSig or witness).
36+
*
37+
* @param provider Utility containing the information necessary to solve a script.
38+
* @param fromPubKey The script to produce a satisfaction for.
39+
* @param txTo The spending transaction.
40+
* @param nIn The index of the input in `txTo` referring the output being spent.
41+
* @param amount The value of the output being spent.
42+
* @param nHashType Signature hash type.
43+
* @param sig_data Additional data provided to solve a script. Filled with the resulting satisfying
44+
* script and whether the satisfaction is complete.
45+
*
46+
* @return True if the produced script is entirely satisfying `fromPubKey`.
47+
**/
48+
bool SignSignature(const SigningProvider &provider, const CScript& fromPubKey, CMutableTransaction& txTo,
49+
unsigned int nIn, const CAmount& amount, int nHashType, SignatureData& sig_data);
50+
bool SignSignature(const SigningProvider &provider, const CTransaction& txFrom, CMutableTransaction& txTo,
51+
unsigned int nIn, int nHashType, SignatureData& sig_data);
52+
3353
#endif // BITCOIN_TEST_UTIL_TRANSACTION_UTILS_H

0 commit comments

Comments
 (0)