Skip to content

Commit ad786f5

Browse files
committed
compiler: test the maximum witness script size limit
Signed-off-by: Antoine Poinsot <[email protected]>
1 parent bd3a22a commit ad786f5

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/policy/compiler.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,6 +1472,32 @@ mod tests {
14721472

14731473
#[test]
14741474
fn segwit_limits() {
1475+
// Hit the maximum witness script size limit.
1476+
// or(thresh(52, [pubkey; 52]), thresh(52, [pubkey; 52])) results in a 3642-bytes long
1477+
// witness script with only 54 stack elements
1478+
let (keys, _) = pubkeys_and_a_sig(104);
1479+
let keys_a: Vec<Concrete<bitcoin::PublicKey>> = keys[..keys.len() / 2]
1480+
.iter()
1481+
.map(|pubkey| Concrete::Key(*pubkey))
1482+
.collect();
1483+
let keys_b: Vec<Concrete<bitcoin::PublicKey>> = keys[keys.len() / 2..]
1484+
.iter()
1485+
.map(|pubkey| Concrete::Key(*pubkey))
1486+
.collect();
1487+
1488+
let thresh_res: Result<SegwitMiniScript, _> = Concrete::Or(vec![
1489+
(1, Concrete::Threshold(keys_a.len(), keys_a)),
1490+
(1, Concrete::Threshold(keys_b.len(), keys_b)),
1491+
])
1492+
.compile();
1493+
let script_size = thresh_res.clone().and_then(|m| Ok(m.script_size(NullCtx)));
1494+
assert_eq!(
1495+
thresh_res,
1496+
Err(CompilerError::LimitsExceeded),
1497+
"Compilation succeeded with a witscript size of '{:?}'",
1498+
script_size,
1499+
);
1500+
14751501
// Hit the maximum witness stack elements limit
14761502
let (keys, _) = pubkeys_and_a_sig(100);
14771503
let keys: Vec<Concrete<bitcoin::PublicKey>> =

0 commit comments

Comments
 (0)