Skip to content

Commit 028b0d9

Browse files
committed
Merge #13425: Moving final scriptSig construction from CombineSignatures to ProduceSignature (PSBT signer logic)
b815600 Remove CombineSignatures and replace tests (Andrew Chow) ed94c8b Replace CombineSignatures with ProduceSignature (Andrew Chow) 0422beb Make SignatureData able to store signatures and scripts (Andrew Chow) b6edb4f Inline Sign1 and SignN (Andrew Chow) Pull request description: Currently CombineSignatures is used to create the final scriptSig or an input. However ProduceSignature is capable of doing this itself. Using both CombineSignatures and ProduceSignature results in code duplication which is unnecessary. To move the scriptSig construction to ProduceSignatures, the SignatureData class contains two maps to hold pubkeys mapped to signatures, and script ids mapped to scripts. DataFromTransaction is extended to be able to extract signatures, their public keys, and scripts from existing ScriptSigs. The SignaureData are then passed down to SignStep which can use the aforementioned maps to get the signatures, pubkeys, and scripts that it needs, falling back to the actual SigningProvider and SignatureCreator if the data are not available in the SignatureData. Additionally, Sign1 and SignN have been removed and their functionality inlined into SignStep since Sign1 is really just a wrapper around CreateSig. Since ProduceSignature can produce the final scriptSig or scriptWitness by using SignatureData which has extracted data from the transaction, CombineSignatures is unnecessary as ProduceSignature is able to replicate all of CombineSignatures' functionality. This also furthers BIP 174 support and begins moving towards a BIP 174 style backend. The tests have also been updated to use the new combining methodology. Tree-SHA512: 78cd58a4ebe37f79229bd5eee2958a0bb45cd7f36d0e993eee13ff685b3665dd76ef2dfd5f47d34678995bb587f5594100ee5f6c09b1c69ee96d3684d470d01e
2 parents 40334c7 + b815600 commit 028b0d9

File tree

7 files changed

+283
-260
lines changed

7 files changed

+283
-260
lines changed

src/bench/verify_script.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#endif
1010
#include <script/script.h>
1111
#include <script/sign.h>
12+
#include <script/standard.h>
1213
#include <streams.h>
1314

1415
#include <array>

src/bitcoin-tx.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -645,13 +645,11 @@ static void MutateTxSign(CMutableTransaction& tx, const std::string& flagStr)
645645
const CScript& prevPubKey = coin.out.scriptPubKey;
646646
const CAmount& amount = coin.out.nValue;
647647

648-
SignatureData sigdata;
648+
SignatureData sigdata = DataFromTransaction(mergedTx, i, coin.out);
649649
// Only sign SIGHASH_SINGLE if there's a corresponding output:
650650
if (!fHashSingle || (i < mergedTx.vout.size()))
651651
ProduceSignature(keystore, MutableTransactionSignatureCreator(&mergedTx, i, amount, nHashType), prevPubKey, sigdata);
652652

653-
// ... and merge in other signatures:
654-
sigdata = CombineSignatures(prevPubKey, MutableTransactionSignatureChecker(&mergedTx, i, amount), sigdata, DataFromTransaction(txv, i));
655653
UpdateInput(txin, sigdata);
656654
}
657655

src/rpc/rawtransaction.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -733,17 +733,15 @@ static UniValue combinerawtransaction(const JSONRPCRequest& request)
733733
if (coin.IsSpent()) {
734734
throw JSONRPCError(RPC_VERIFY_ERROR, "Input not found or already spent");
735735
}
736-
const CScript& prevPubKey = coin.out.scriptPubKey;
737-
const CAmount& amount = coin.out.nValue;
738-
739736
SignatureData sigdata;
740737

741738
// ... and merge in other signatures:
742739
for (const CMutableTransaction& txv : txVariants) {
743740
if (txv.vin.size() > i) {
744-
sigdata = CombineSignatures(prevPubKey, TransactionSignatureChecker(&txConst, i, amount), sigdata, DataFromTransaction(txv, i));
741+
sigdata.MergeSignatureData(DataFromTransaction(txv, i, coin.out));
745742
}
746743
}
744+
ProduceSignature(DUMMY_SIGNING_PROVIDER, MutableTransactionSignatureCreator(&mergedTx, i, coin.out.nValue, 1), coin.out.scriptPubKey, sigdata);
747745

748746
UpdateInput(txin, sigdata);
749747
}
@@ -872,12 +870,11 @@ UniValue SignTransaction(CMutableTransaction& mtx, const UniValue& prevTxsUnival
872870
const CScript& prevPubKey = coin.out.scriptPubKey;
873871
const CAmount& amount = coin.out.nValue;
874872

875-
SignatureData sigdata;
873+
SignatureData sigdata = DataFromTransaction(mtx, i, coin.out);
876874
// Only sign SIGHASH_SINGLE if there's a corresponding output:
877875
if (!fHashSingle || (i < mtx.vout.size())) {
878876
ProduceSignature(*keystore, MutableTransactionSignatureCreator(&mtx, i, amount, nHashType), prevPubKey, sigdata);
879877
}
880-
sigdata = CombineSignatures(prevPubKey, TransactionSignatureChecker(&txConst, i, amount), sigdata, DataFromTransaction(mtx, i));
881878

882879
UpdateInput(txin, sigdata);
883880

0 commit comments

Comments
 (0)