Skip to content

Commit a3b065b

Browse files
committed
Error on missing amount in signrawtransaction*
Signatures using segregated witness commit to the amount being spent, so that value must be passed into signrawtransactionwithkey and signrawtransactionwithwallet. This ensures an error is issued if that doesn't happen, rather than just assuming the value is 0 and producing a signature that is almost certainly invalid.
1 parent 7209fec commit a3b065b

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/rpc/rawtransaction.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ UniValue SignTransaction(CMutableTransaction& mtx, const UniValue& prevTxsUnival
811811
}
812812
Coin newcoin;
813813
newcoin.out.scriptPubKey = scriptPubKey;
814-
newcoin.out.nValue = 0;
814+
newcoin.out.nValue = MAX_MONEY;
815815
if (prevOut.exists("amount")) {
816816
newcoin.out.nValue = AmountFromValue(find_value(prevOut, "amount"));
817817
}
@@ -884,6 +884,11 @@ UniValue SignTransaction(CMutableTransaction& mtx, const UniValue& prevTxsUnival
884884

885885
UpdateInput(txin, sigdata);
886886

887+
// amount must be specified for valid segwit signature
888+
if (amount == MAX_MONEY && !txin.scriptWitness.IsNull()) {
889+
throw JSONRPCError(RPC_TYPE_ERROR, strprintf("Missing amount for %s", coin.out.ToString()));
890+
}
891+
887892
ScriptError serror = SCRIPT_ERR_OK;
888893
if (!VerifyScript(txin.scriptSig, prevPubKey, &txin.scriptWitness, STANDARD_SCRIPT_VERIFY_FLAGS, TransactionSignatureChecker(&txConst, i, amount), &serror)) {
889894
if (serror == SCRIPT_ERR_INVALID_STACK_OPERATION) {

0 commit comments

Comments
 (0)