@@ -488,6 +488,26 @@ bool SignTransaction(CMutableTransaction& mtx, const SigningProvider* keystore,
488
488
// Use CTransaction for the constant parts of the
489
489
// transaction to avoid rehashing.
490
490
const CTransaction txConst (mtx);
491
+
492
+ PrecomputedTransactionData txdata;
493
+ std::vector<CTxOut> spent_outputs;
494
+ spent_outputs.resize (mtx.vin .size ());
495
+ bool have_all_spent_outputs = true ;
496
+ for (unsigned int i = 0 ; i < mtx.vin .size (); i++) {
497
+ CTxIn& txin = mtx.vin [i];
498
+ auto coin = coins.find (txin.prevout );
499
+ if (coin == coins.end () || coin->second .IsSpent ()) {
500
+ have_all_spent_outputs = false ;
501
+ } else {
502
+ spent_outputs[i] = CTxOut (coin->second .out .nValue , coin->second .out .scriptPubKey );
503
+ }
504
+ }
505
+ if (have_all_spent_outputs) {
506
+ txdata.Init (txConst, std::move (spent_outputs), true );
507
+ } else {
508
+ txdata.Init (txConst, {}, true );
509
+ }
510
+
491
511
// Sign what we can:
492
512
for (unsigned int i = 0 ; i < mtx.vin .size (); i++) {
493
513
CTxIn& txin = mtx.vin [i];
@@ -502,7 +522,7 @@ bool SignTransaction(CMutableTransaction& mtx, const SigningProvider* keystore,
502
522
SignatureData sigdata = DataFromTransaction (mtx, i, coin->second .out );
503
523
// Only sign SIGHASH_SINGLE if there's a corresponding output:
504
524
if (!fHashSingle || (i < mtx.vout .size ())) {
505
- ProduceSignature (*keystore, MutableTransactionSignatureCreator (&mtx, i, amount, nHashType), prevPubKey, sigdata);
525
+ ProduceSignature (*keystore, MutableTransactionSignatureCreator (&mtx, i, amount, &txdata, nHashType), prevPubKey, sigdata);
506
526
}
507
527
508
528
UpdateInput (txin, sigdata);
@@ -514,7 +534,7 @@ bool SignTransaction(CMutableTransaction& mtx, const SigningProvider* keystore,
514
534
}
515
535
516
536
ScriptError serror = SCRIPT_ERR_OK;
517
- if (!VerifyScript (txin.scriptSig , prevPubKey, &txin.scriptWitness , STANDARD_SCRIPT_VERIFY_FLAGS, TransactionSignatureChecker (&txConst, i, amount, MissingDataBehavior::FAIL), &serror)) {
537
+ if (!VerifyScript (txin.scriptSig , prevPubKey, &txin.scriptWitness , STANDARD_SCRIPT_VERIFY_FLAGS, TransactionSignatureChecker (&txConst, i, amount, txdata, MissingDataBehavior::FAIL), &serror)) {
518
538
if (serror == SCRIPT_ERR_INVALID_STACK_OPERATION) {
519
539
// Unable to sign input and verification failed (possible attempt to partially sign).
520
540
input_errors[i] = " Unable to sign input, invalid stack size (possibly missing key)" ;
0 commit comments