Skip to content

Commit f365e23

Browse files
committed
miniscript: check for max num of pubkeys in Multi
sanity_check() would not error with 21 pubkeys. Reported by Daniela Brozzoni.
1 parent 505ddc6 commit f365e23

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/miniscript/context.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ use std::{fmt, hash};
1717
use bitcoin;
1818
use bitcoin::blockdata::constants::MAX_BLOCK_WEIGHT;
1919
use miniscript::limits::{
20-
MAX_OPS_PER_SCRIPT, MAX_SCRIPTSIG_SIZE, MAX_SCRIPT_ELEMENT_SIZE, MAX_SCRIPT_SIZE,
21-
MAX_STACK_SIZE, MAX_STANDARD_P2WSH_SCRIPT_SIZE, MAX_STANDARD_P2WSH_STACK_ITEMS,
20+
MAX_OPS_PER_SCRIPT, MAX_PUBKEYS_PER_MULTISIG, MAX_SCRIPTSIG_SIZE, MAX_SCRIPT_ELEMENT_SIZE,
21+
MAX_SCRIPT_SIZE, MAX_STACK_SIZE, MAX_STANDARD_P2WSH_SCRIPT_SIZE,
22+
MAX_STANDARD_P2WSH_STACK_ITEMS,
2223
};
2324
use miniscript::types;
2425
use util::witness_to_scriptsig;
@@ -67,6 +68,8 @@ pub enum ScriptContextError {
6768
TaprootMultiDisabled,
6869
/// Stack size exceeded in script execution
6970
StackSizeLimitExceeded { actual: usize, limit: usize },
71+
/// More than 20 keys in a Multi fragment
72+
CheckMultiSigLimitExceeded,
7073
}
7174

7275
impl fmt::Display for ScriptContextError {
@@ -132,6 +135,12 @@ impl fmt::Display for ScriptContextError {
132135
actual, limit
133136
)
134137
}
138+
ScriptContextError::CheckMultiSigLimitExceeded => {
139+
write!(
140+
f,
141+
"CHECkMULTISIG ('multi()' descriptor) only supports up to 20 pubkeys"
142+
)
143+
}
135144
}
136145
}
137146
}
@@ -323,6 +332,16 @@ impl ScriptContext for Legacy {
323332
if ms.ext.pk_cost > MAX_SCRIPT_ELEMENT_SIZE {
324333
return Err(ScriptContextError::MaxRedeemScriptSizeExceeded);
325334
}
335+
336+
match ms.node {
337+
Terminal::Multi(_k, ref pks) => {
338+
if pks.len() > MAX_PUBKEYS_PER_MULTISIG {
339+
return Err(ScriptContextError::CheckMultiSigLimitExceeded);
340+
}
341+
}
342+
_ => {}
343+
}
344+
326345
Ok(())
327346
}
328347

@@ -408,6 +427,9 @@ impl ScriptContext for Segwitv0 {
408427
Ok(())
409428
}
410429
Terminal::Multi(_k, ref pks) => {
430+
if pks.len() > MAX_PUBKEYS_PER_MULTISIG {
431+
return Err(ScriptContextError::CheckMultiSigLimitExceeded);
432+
}
411433
for pk in pks.iter() {
412434
if pk.is_uncompressed() {
413435
return Err(ScriptContextError::CompressedOnly(pk.to_string()));

0 commit comments

Comments
 (0)