Skip to content

Commit 34118bf

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#23784: bitcoin-tx: Require that input amount is provided for witness transactions
8bd34dc test: check that bitcoin-tx detects missing input amount for segwit transactions (Sebastian Falbesoner) c337b27 Require that input amount is provided for bitcoin-tx witness transactions (Ben Woosley) Pull request description: This PR picks up the obviously abandoned PR #13608 (last activity was three and a half years ago) by rebasing it on master and adding missing tests. Original PR description: "_Applies fix from #12458 / #13547 to bitcoin-tx._" The private key is the compressed version of the one used in most other util tests (5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsreAnchuDf, corresponds to the scalar value k=1 in big endian), since segwit signing refuses uncompressed keys. The error message from the picked up PR is changed to not include the amount, as showing any value would be just confusing. ACKs for top commit: josibake: ACK bitcoin/bitcoin@8bd34dc Tree-SHA512: 334b418f89527363ad7e3326b4126e86a05fd64876c49a8280de38e64cfac52cb62c4b24b83603dd68b6bcebbe57c64161832edffb1cac7e9c68426f6b6eae1f
2 parents 121d47a + 8bd34dc commit 34118bf

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ EXTRA_DIST += \
323323
test/util/data/txcreatescript4.json \
324324
test/util/data/txcreatescript5.hex \
325325
test/util/data/txcreatescript6.hex \
326+
test/util/data/txcreatesignsegwit1.hex \
326327
test/util/data/txcreatesignv1.hex \
327328
test/util/data/txcreatesignv1.json \
328329
test/util/data/txcreatesignv2.hex \

src/bitcoin-tx.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ static void MutateTxSign(CMutableTransaction& tx, const std::string& flagStr)
630630
}
631631
Coin newcoin;
632632
newcoin.out.scriptPubKey = scriptPubKey;
633-
newcoin.out.nValue = 0;
633+
newcoin.out.nValue = MAX_MONEY;
634634
if (prevOut.exists("amount")) {
635635
newcoin.out.nValue = AmountFromValue(prevOut["amount"]);
636636
}
@@ -669,6 +669,10 @@ static void MutateTxSign(CMutableTransaction& tx, const std::string& flagStr)
669669
if (!fHashSingle || (i < mergedTx.vout.size()))
670670
ProduceSignature(keystore, MutableTransactionSignatureCreator(&mergedTx, i, amount, nHashType), prevPubKey, sigdata);
671671

672+
if (amount == MAX_MONEY && !sigdata.scriptWitness.IsNull()) {
673+
throw std::runtime_error(strprintf("Missing amount for CTxOut with scriptPubKey=%s", HexStr(prevPubKey)));
674+
}
675+
672676
UpdateInput(txin, sigdata);
673677
}
674678

test/util/data/bitcoin-util-test.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,29 @@
416416
"error_txt": "error: txid must be hexadecimal string (not '4d49a71ec9da436f71ec4ee231d04f292a29cd316f598bb7068feccabdc5948512')",
417417
"description": "Tests the check for invalid txid valid hex, but too long"
418418
},
419+
{ "exec": "./bitcoin-tx",
420+
"args":
421+
["-create",
422+
"in=00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff:0",
423+
"set=privatekeys:[\"KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73sVHnoWn\"]",
424+
"set=prevtxs:[{\"txid\":\"00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff\",\"vout\":0,\"amount\":\"0\", \"scriptPubKey\":\"0014751e76e8199196d454941c45d1b3a323f1433bd6\"}]",
425+
"sign=ALL",
426+
"outaddr=0.001:193P6LtvS4nCnkDvM9uXn1gsSRqh4aDAz7"],
427+
"output_cmp": "txcreatesignsegwit1.hex",
428+
"description": "Creates a new transaction with a single witness input and a single output, and then signs the transaction"
429+
},
430+
{ "exec": "./bitcoin-tx",
431+
"args":
432+
["-create",
433+
"in=00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff:0",
434+
"set=privatekeys:[\"KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73sVHnoWn\"]",
435+
"set=prevtxs:[{\"txid\":\"00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff\",\"vout\":0,\"scriptPubKey\":\"0014751e76e8199196d454941c45d1b3a323f1433bd6\"}]",
436+
"sign=ALL",
437+
"outaddr=0.001:193P6LtvS4nCnkDvM9uXn1gsSRqh4aDAz7"],
438+
"return_code": 1,
439+
"error_txt": "Missing amount for CTxOut with scriptPubKey=0014751e76e8199196d454941c45d1b3a323f1433bd6",
440+
"description": "Tests the check for missing input amount for witness transactions"
441+
},
419442
{ "exec": "./bitcoin-tx",
420443
"args":
421444
["-create", "outpubkey=0:02a5613bd857b7048924264d1e70e08fb2a7e6527d32b7ab1bb993ac59964ff397", "nversion=1"],
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
02000000000101ffeeddccbbaa99887766554433221100ffeeddccbbaa998877665544332211000000000000ffffffff01a0860100000000001976a9145834479edbbe0539b31ffd3a8f8ebadc2165ed0188ac0247304402202e8d8677912f73909ffbdb3ee87d10cce41d398ee206e534fa18330b566ece34022004f944f018a03c9f5b4cf0e9b0ae4f14049b55e7b6810a6ac26cd67cb4dcb31f01210279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f8179800000000

0 commit comments

Comments
 (0)