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:
furszy
2023-08-21 17:50:09 -03:00
parent 0c9fedfc45
commit 9d9a91c4ea
3 changed files with 11 additions and 7 deletions

View File

@@ -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):