diff options
author | MarcoFalke <falke.marco@gmail.com> | 2022-01-05 17:47:34 +0100 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2022-01-05 17:48:55 +0100 |
commit | 34118bfaddc3a6c1593345c7d2369d1004a887d1 (patch) | |
tree | cb37b1269e140a4f47d7859f14b6d99411a6173c /src/bitcoin-tx.cpp | |
parent | 121d47afe3e67ff7f94d26e08a39573dccf652aa (diff) | |
parent | 8bd34dc774788cbf3cad8e139542a0ed9f3e8bb4 (diff) |
Merge bitcoin/bitcoin#23784: bitcoin-tx: Require that input amount is provided for witness transactions
8bd34dc774788cbf3cad8e139542a0ed9f3e8bb4 test: check that bitcoin-tx detects missing input amount for segwit transactions (Sebastian Falbesoner)
c337b27d7cfd468048bcf816e585a1f7d59e066d 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 https://github.com/bitcoin/bitcoin/commit/8bd34dc774788cbf3cad8e139542a0ed9f3e8bb4
Tree-SHA512: 334b418f89527363ad7e3326b4126e86a05fd64876c49a8280de38e64cfac52cb62c4b24b83603dd68b6bcebbe57c64161832edffb1cac7e9c68426f6b6eae1f
Diffstat (limited to 'src/bitcoin-tx.cpp')
-rw-r--r-- | src/bitcoin-tx.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/bitcoin-tx.cpp b/src/bitcoin-tx.cpp index 8602e362c8..edec883264 100644 --- a/src/bitcoin-tx.cpp +++ b/src/bitcoin-tx.cpp @@ -630,7 +630,7 @@ static void MutateTxSign(CMutableTransaction& tx, const std::string& flagStr) } Coin newcoin; newcoin.out.scriptPubKey = scriptPubKey; - newcoin.out.nValue = 0; + newcoin.out.nValue = MAX_MONEY; if (prevOut.exists("amount")) { newcoin.out.nValue = AmountFromValue(prevOut["amount"]); } @@ -669,6 +669,10 @@ static void MutateTxSign(CMutableTransaction& tx, const std::string& flagStr) if (!fHashSingle || (i < mergedTx.vout.size())) ProduceSignature(keystore, MutableTransactionSignatureCreator(&mergedTx, i, amount, nHashType), prevPubKey, sigdata); + if (amount == MAX_MONEY && !sigdata.scriptWitness.IsNull()) { + throw std::runtime_error(strprintf("Missing amount for CTxOut with scriptPubKey=%s", HexStr(prevPubKey))); + } + UpdateInput(txin, sigdata); } |