mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-08 10:31:50 -05:00
rpc: bugfix, incorrect segwit redeem script size used in signrawtransactionwithkey
The process currently fails to sign redeem scripts that are longer than 520 bytes. Even when it shouldn't. The 520 bytes redeem scripts limit is a legacy p2sh rule, and not a segwit limitation. Segwit redeem scripts are not restricted by the script item size limit. The reason why this occurs, is the usage of the same keystore used by the legacy spkm. Which contains blockage for any redeem scripts longer than the script item size limit.
This commit is contained in:
parent
0c9fedfc45
commit
9d9a91c4ea
3 changed files with 11 additions and 7 deletions
|
@ -785,7 +785,7 @@ static RPCHelpMan signrawtransactionwithkey()
|
|||
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed. Make sure the tx has at least one input.");
|
||||
}
|
||||
|
||||
FillableSigningProvider keystore;
|
||||
FlatSigningProvider keystore;
|
||||
const UniValue& keys = request.params[1].get_array();
|
||||
for (unsigned int idx = 0; idx < keys.size(); ++idx) {
|
||||
UniValue k = keys[idx];
|
||||
|
@ -793,7 +793,11 @@ static RPCHelpMan signrawtransactionwithkey()
|
|||
if (!key.IsValid()) {
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid private key");
|
||||
}
|
||||
keystore.AddKey(key);
|
||||
|
||||
CPubKey pubkey = key.GetPubKey();
|
||||
CKeyID key_id = pubkey.GetID();
|
||||
keystore.pubkeys.emplace(key_id, pubkey);
|
||||
keystore.keys.emplace(key_id, key);
|
||||
}
|
||||
|
||||
// Fetch previous transactions (inputs):
|
||||
|
|
|
@ -181,7 +181,7 @@ static void TxInErrorToJSON(const CTxIn& txin, UniValue& vErrorsRet, const std::
|
|||
vErrorsRet.push_back(entry);
|
||||
}
|
||||
|
||||
void ParsePrevouts(const UniValue& prevTxsUnival, FillableSigningProvider* keystore, std::map<COutPoint, Coin>& coins)
|
||||
void ParsePrevouts(const UniValue& prevTxsUnival, FlatSigningProvider* keystore, std::map<COutPoint, Coin>& coins)
|
||||
{
|
||||
if (!prevTxsUnival.isNull()) {
|
||||
const UniValue& prevTxs = prevTxsUnival.get_array();
|
||||
|
@ -247,11 +247,11 @@ void ParsePrevouts(const UniValue& prevTxsUnival, FillableSigningProvider* keyst
|
|||
// work from witnessScript when possible
|
||||
std::vector<unsigned char> scriptData(!ws.isNull() ? ParseHexV(ws, "witnessScript") : ParseHexV(rs, "redeemScript"));
|
||||
CScript script(scriptData.begin(), scriptData.end());
|
||||
keystore->AddCScript(script);
|
||||
keystore->scripts.emplace(CScriptID(script), script);
|
||||
// Automatically also add the P2WSH wrapped version of the script (to deal with P2SH-P2WSH).
|
||||
// This is done for redeemScript only for compatibility, it is encouraged to use the explicit witnessScript field instead.
|
||||
CScript witness_output_script{GetScriptForDestination(WitnessV0ScriptHash(script))};
|
||||
keystore->AddCScript(witness_output_script);
|
||||
keystore->scripts.emplace(CScriptID(witness_output_script), witness_output_script);
|
||||
|
||||
if (!ws.isNull() && !rs.isNull()) {
|
||||
// if both witnessScript and redeemScript are provided,
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#include <optional>
|
||||
|
||||
struct bilingual_str;
|
||||
class FillableSigningProvider;
|
||||
struct FlatSigningProvider;
|
||||
class UniValue;
|
||||
struct CMutableTransaction;
|
||||
class Coin;
|
||||
|
@ -38,7 +38,7 @@ void SignTransactionResultToJSON(CMutableTransaction& mtx, bool complete, const
|
|||
* @param keystore A pointer to the temporary keystore if there is one
|
||||
* @param coins Map of unspent outputs - coins in mempool and current chain UTXO set, may be extended by previous txns outputs after call
|
||||
*/
|
||||
void ParsePrevouts(const UniValue& prevTxsUnival, FillableSigningProvider* keystore, std::map<COutPoint, Coin>& coins);
|
||||
void ParsePrevouts(const UniValue& prevTxsUnival, FlatSigningProvider* keystore, std::map<COutPoint, Coin>& coins);
|
||||
|
||||
/** Normalize univalue-represented inputs and add them to the transaction */
|
||||
void AddInputs(CMutableTransaction& rawTx, const UniValue& inputs_in, bool rbf);
|
||||
|
|
Loading…
Add table
Reference in a new issue