Skip to content

Commit 5aa50ab

Browse files
committed
rpc/util: multisig: only check redeemScript size is <= 520 for P2SH
This increase the maximum number of pubkeys to 20 (valid in P2WSH and P2SH-P2WSH) and only checks the redeemScript doesn't exceed MAX_SCRIPT_ELEMENT_SIZE for P2SH, as this checked is removed under Segwit context. Signed-off-by: Antoine Poinsot <[email protected]>
1 parent 063df9e commit 5aa50ab

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/rpc/util.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,16 +231,12 @@ CTxDestination AddAndGetMultisigDestination(const int required, const std::vecto
231231
if ((int)pubkeys.size() < required) {
232232
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("not enough keys supplied (got %u keys, but need at least %d to redeem)", pubkeys.size(), required));
233233
}
234-
if (pubkeys.size() > 16) {
235-
throw JSONRPCError(RPC_INVALID_PARAMETER, "Number of keys involved in the multisignature address creation > 16\nReduce the number");
234+
if (pubkeys.size() > MAX_PUBKEYS_PER_MULTISIG) {
235+
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Number of keys involved in the multisignature address creation > %d\nReduce the number", MAX_PUBKEYS_PER_MULTISIG));
236236
}
237237

238238
script_out = GetScriptForMultisig(required, pubkeys);
239239

240-
if (script_out.size() > MAX_SCRIPT_ELEMENT_SIZE) {
241-
throw JSONRPCError(RPC_INVALID_PARAMETER, (strprintf("redeemScript exceeds size limit: %d > %d", script_out.size(), MAX_SCRIPT_ELEMENT_SIZE)));
242-
}
243-
244240
// Check if any keys are uncompressed. If so, the type is legacy
245241
for (const CPubKey& pk : pubkeys) {
246242
if (!pk.IsCompressed()) {
@@ -249,6 +245,10 @@ CTxDestination AddAndGetMultisigDestination(const int required, const std::vecto
249245
}
250246
}
251247

248+
if (type == OutputType::LEGACY && script_out.size() > MAX_SCRIPT_ELEMENT_SIZE) {
249+
throw JSONRPCError(RPC_INVALID_PARAMETER, (strprintf("redeemScript exceeds size limit: %d > %d", script_out.size(), MAX_SCRIPT_ELEMENT_SIZE)));
250+
}
251+
252252
// Make the address
253253
CTxDestination dest = AddAndGetDestinationForScript(keystore, script_out, type);
254254

0 commit comments

Comments
 (0)