@@ -1161,10 +1161,19 @@ BOOST_AUTO_TEST_CASE(script_CHECKMULTISIG23)
1161
1161
BOOST_CHECK_MESSAGE (err == SCRIPT_ERR_INVALID_STACK_OPERATION, ScriptErrorString (err));
1162
1162
}
1163
1163
1164
+ /* Wrapper around ProduceSignature to combine two scriptsigs */
1165
+ SignatureData CombineSignatures (const CTxOut& txout, const CMutableTransaction& tx, const SignatureData& scriptSig1, const SignatureData& scriptSig2)
1166
+ {
1167
+ SignatureData data;
1168
+ data.MergeSignatureData (scriptSig1);
1169
+ data.MergeSignatureData (scriptSig2);
1170
+ ProduceSignature (DUMMY_SIGNING_PROVIDER, MutableTransactionSignatureCreator (&tx, 0 , txout.nValue ), txout.scriptPubKey , data);
1171
+ return data;
1172
+ }
1173
+
1164
1174
BOOST_AUTO_TEST_CASE (script_combineSigs)
1165
1175
{
1166
- // Test the CombineSignatures function
1167
- CAmount amount = 0 ;
1176
+ // Test the ProduceSignature's ability to combine signatures function
1168
1177
CBasicKeyStore keystore;
1169
1178
std::vector<CKey> keys;
1170
1179
std::vector<CPubKey> pubkeys;
@@ -1180,52 +1189,51 @@ BOOST_AUTO_TEST_CASE(script_combineSigs)
1180
1189
CMutableTransaction txFrom = BuildCreditingTransaction (GetScriptForDestination (keys[0 ].GetPubKey ().GetID ()));
1181
1190
CMutableTransaction txTo = BuildSpendingTransaction (CScript (), CScriptWitness (), txFrom);
1182
1191
CScript& scriptPubKey = txFrom.vout [0 ].scriptPubKey ;
1183
- CScript& scriptSig = txTo. vin [ 0 ]. scriptSig ;
1192
+ SignatureData scriptSig;
1184
1193
1185
1194
SignatureData empty;
1186
- SignatureData combined = CombineSignatures (scriptPubKey, MutableTransactionSignatureChecker (&txTo, 0 , amount) , empty, empty);
1195
+ SignatureData combined = CombineSignatures (txFrom. vout [ 0 ], txTo , empty, empty);
1187
1196
BOOST_CHECK (combined.scriptSig .empty ());
1188
1197
1189
1198
// Single signature case:
1190
1199
SignSignature (keystore, txFrom, txTo, 0 , SIGHASH_ALL); // changes scriptSig
1191
- combined = CombineSignatures (scriptPubKey, MutableTransactionSignatureChecker (&txTo, 0 , amount), SignatureData (scriptSig), empty);
1192
- BOOST_CHECK (combined.scriptSig == scriptSig);
1193
- combined = CombineSignatures (scriptPubKey, MutableTransactionSignatureChecker (&txTo, 0 , amount), empty, SignatureData (scriptSig));
1194
- BOOST_CHECK (combined.scriptSig == scriptSig);
1195
- CScript scriptSigCopy = scriptSig;
1200
+ scriptSig = DataFromTransaction (txTo, 0 , txFrom.vout [0 ]);
1201
+ combined = CombineSignatures (txFrom.vout [0 ], txTo, scriptSig, empty);
1202
+ BOOST_CHECK (combined.scriptSig == scriptSig.scriptSig );
1203
+ combined = CombineSignatures (txFrom.vout [0 ], txTo, empty, scriptSig);
1204
+ BOOST_CHECK (combined.scriptSig == scriptSig.scriptSig );
1205
+ SignatureData scriptSigCopy = scriptSig;
1196
1206
// Signing again will give a different, valid signature:
1197
1207
SignSignature (keystore, txFrom, txTo, 0 , SIGHASH_ALL);
1198
- combined = CombineSignatures (scriptPubKey, MutableTransactionSignatureChecker (&txTo, 0 , amount), SignatureData (scriptSigCopy), SignatureData (scriptSig));
1199
- BOOST_CHECK (combined.scriptSig == scriptSigCopy || combined.scriptSig == scriptSig);
1208
+ scriptSig = DataFromTransaction (txTo, 0 , txFrom.vout [0 ]);
1209
+ combined = CombineSignatures (txFrom.vout [0 ], txTo, scriptSigCopy, scriptSig);
1210
+ BOOST_CHECK (combined.scriptSig == scriptSigCopy.scriptSig || combined.scriptSig == scriptSig.scriptSig );
1200
1211
1201
1212
// P2SH, single-signature case:
1202
1213
CScript pkSingle; pkSingle << ToByteVector (keys[0 ].GetPubKey ()) << OP_CHECKSIG;
1203
1214
keystore.AddCScript (pkSingle);
1204
1215
scriptPubKey = GetScriptForDestination (CScriptID (pkSingle));
1205
1216
SignSignature (keystore, txFrom, txTo, 0 , SIGHASH_ALL);
1206
- combined = CombineSignatures (scriptPubKey, MutableTransactionSignatureChecker (&txTo, 0 , amount), SignatureData (scriptSig), empty);
1207
- BOOST_CHECK (combined.scriptSig == scriptSig);
1208
- combined = CombineSignatures (scriptPubKey, MutableTransactionSignatureChecker (&txTo, 0 , amount), empty, SignatureData (scriptSig));
1209
- BOOST_CHECK (combined.scriptSig == scriptSig);
1217
+ scriptSig = DataFromTransaction (txTo, 0 , txFrom.vout [0 ]);
1218
+ combined = CombineSignatures (txFrom.vout [0 ], txTo, scriptSig, empty);
1219
+ BOOST_CHECK (combined.scriptSig == scriptSig.scriptSig );
1220
+ combined = CombineSignatures (txFrom.vout [0 ], txTo, empty, scriptSig);
1221
+ BOOST_CHECK (combined.scriptSig == scriptSig.scriptSig );
1210
1222
scriptSigCopy = scriptSig;
1211
1223
SignSignature (keystore, txFrom, txTo, 0 , SIGHASH_ALL);
1212
- combined = CombineSignatures (scriptPubKey, MutableTransactionSignatureChecker (&txTo, 0 , amount), SignatureData (scriptSigCopy), SignatureData (scriptSig));
1213
- BOOST_CHECK (combined.scriptSig == scriptSigCopy || combined.scriptSig == scriptSig);
1214
- // dummy scriptSigCopy with placeholder, should always choose non-placeholder:
1215
- scriptSigCopy = CScript () << OP_0 << std::vector<unsigned char >(pkSingle.begin (), pkSingle.end ());
1216
- combined = CombineSignatures (scriptPubKey, MutableTransactionSignatureChecker (&txTo, 0 , amount), SignatureData (scriptSigCopy), SignatureData (scriptSig));
1217
- BOOST_CHECK (combined.scriptSig == scriptSig);
1218
- combined = CombineSignatures (scriptPubKey, MutableTransactionSignatureChecker (&txTo, 0 , amount), SignatureData (scriptSig), SignatureData (scriptSigCopy));
1219
- BOOST_CHECK (combined.scriptSig == scriptSig);
1224
+ scriptSig = DataFromTransaction (txTo, 0 , txFrom.vout [0 ]);
1225
+ combined = CombineSignatures (txFrom.vout [0 ], txTo, scriptSigCopy, scriptSig);
1226
+ BOOST_CHECK (combined.scriptSig == scriptSigCopy.scriptSig || combined.scriptSig == scriptSig.scriptSig );
1220
1227
1221
1228
// Hardest case: Multisig 2-of-3
1222
1229
scriptPubKey = GetScriptForMultisig (2 , pubkeys);
1223
1230
keystore.AddCScript (scriptPubKey);
1224
1231
SignSignature (keystore, txFrom, txTo, 0 , SIGHASH_ALL);
1225
- combined = CombineSignatures (scriptPubKey, MutableTransactionSignatureChecker (&txTo, 0 , amount), SignatureData (scriptSig), empty);
1226
- BOOST_CHECK (combined.scriptSig == scriptSig);
1227
- combined = CombineSignatures (scriptPubKey, MutableTransactionSignatureChecker (&txTo, 0 , amount), empty, SignatureData (scriptSig));
1228
- BOOST_CHECK (combined.scriptSig == scriptSig);
1232
+ scriptSig = DataFromTransaction (txTo, 0 , txFrom.vout [0 ]);
1233
+ combined = CombineSignatures (txFrom.vout [0 ], txTo, scriptSig, empty);
1234
+ BOOST_CHECK (combined.scriptSig == scriptSig.scriptSig );
1235
+ combined = CombineSignatures (txFrom.vout [0 ], txTo, empty, scriptSig);
1236
+ BOOST_CHECK (combined.scriptSig == scriptSig.scriptSig );
1229
1237
1230
1238
// A couple of partially-signed versions:
1231
1239
std::vector<unsigned char > sig1;
@@ -1252,22 +1260,28 @@ BOOST_AUTO_TEST_CASE(script_combineSigs)
1252
1260
CScript complete12 = CScript () << OP_0 << sig1 << sig2;
1253
1261
CScript complete13 = CScript () << OP_0 << sig1 << sig3;
1254
1262
CScript complete23 = CScript () << OP_0 << sig2 << sig3;
1255
-
1256
- combined = CombineSignatures (scriptPubKey, MutableTransactionSignatureChecker (&txTo, 0 , amount), SignatureData (partial1a), SignatureData (partial1b));
1263
+ SignatureData partial1_sigs;
1264
+ partial1_sigs.signatures .emplace (keys[0 ].GetPubKey ().GetID (), SigPair (keys[0 ].GetPubKey (), sig1));
1265
+ SignatureData partial2_sigs;
1266
+ partial2_sigs.signatures .emplace (keys[1 ].GetPubKey ().GetID (), SigPair (keys[1 ].GetPubKey (), sig2));
1267
+ SignatureData partial3_sigs;
1268
+ partial3_sigs.signatures .emplace (keys[2 ].GetPubKey ().GetID (), SigPair (keys[2 ].GetPubKey (), sig3));
1269
+
1270
+ combined = CombineSignatures (txFrom.vout [0 ], txTo, partial1_sigs, partial1_sigs);
1257
1271
BOOST_CHECK (combined.scriptSig == partial1a);
1258
- combined = CombineSignatures (scriptPubKey, MutableTransactionSignatureChecker (& txTo, 0 , amount), SignatureData (partial1a), SignatureData (partial2a) );
1272
+ combined = CombineSignatures (txFrom. vout [ 0 ], txTo, partial1_sigs, partial2_sigs );
1259
1273
BOOST_CHECK (combined.scriptSig == complete12);
1260
- combined = CombineSignatures (scriptPubKey, MutableTransactionSignatureChecker (& txTo, 0 , amount), SignatureData (partial2a), SignatureData (partial1a) );
1274
+ combined = CombineSignatures (txFrom. vout [ 0 ], txTo, partial2_sigs, partial1_sigs );
1261
1275
BOOST_CHECK (combined.scriptSig == complete12);
1262
- combined = CombineSignatures (scriptPubKey, MutableTransactionSignatureChecker (& txTo, 0 , amount), SignatureData (partial1b), SignatureData (partial2b) );
1276
+ combined = CombineSignatures (txFrom. vout [ 0 ], txTo, partial1_sigs, partial2_sigs );
1263
1277
BOOST_CHECK (combined.scriptSig == complete12);
1264
- combined = CombineSignatures (scriptPubKey, MutableTransactionSignatureChecker (& txTo, 0 , amount), SignatureData (partial3b), SignatureData (partial1b) );
1278
+ combined = CombineSignatures (txFrom. vout [ 0 ], txTo, partial3_sigs, partial1_sigs );
1265
1279
BOOST_CHECK (combined.scriptSig == complete13);
1266
- combined = CombineSignatures (scriptPubKey, MutableTransactionSignatureChecker (& txTo, 0 , amount), SignatureData (partial2a), SignatureData (partial3a) );
1280
+ combined = CombineSignatures (txFrom. vout [ 0 ], txTo, partial2_sigs, partial3_sigs );
1267
1281
BOOST_CHECK (combined.scriptSig == complete23);
1268
- combined = CombineSignatures (scriptPubKey, MutableTransactionSignatureChecker (& txTo, 0 , amount), SignatureData (partial3b), SignatureData (partial2b) );
1282
+ combined = CombineSignatures (txFrom. vout [ 0 ], txTo, partial3_sigs, partial2_sigs );
1269
1283
BOOST_CHECK (combined.scriptSig == complete23);
1270
- combined = CombineSignatures (scriptPubKey, MutableTransactionSignatureChecker (& txTo, 0 , amount), SignatureData (partial3b), SignatureData (partial3a) );
1284
+ combined = CombineSignatures (txFrom. vout [ 0 ], txTo, partial3_sigs, partial3_sigs );
1271
1285
BOOST_CHECK (combined.scriptSig == partial3c);
1272
1286
}
1273
1287
0 commit comments