Skip to content

Commit 43c3d22

Browse files
committed
Merge #707: 10.x backport
a4576ae Dead code fixes (Sanket Kanjalkar) fd75028 release 10.1.0 (Andrew Poelstra) 26a9570 Add offending test case (Sanket Kanjalkar) 20b961a Track miniscript tree depth explicitly (Sanket Kanjalkar) ab279b2 bug fix 10.x (Sanket Kanjalkar) Pull request description: ACKs for top commit: apoelstra: ACK a4576ae Tree-SHA512: a2fd1d50b66c08672f98b115abd16049479878f969f0acd091f80d79e0d9ed84f4d78a6a8919d3751a2a189ad1fb355c932ee52e43fdc4a76fb101b931376772
2 parents c9118b3 + a4576ae commit 43c3d22

File tree

6 files changed

+63
-6
lines changed

6 files changed

+63
-6
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 10.1.0 - July 9, 2024
2+
3+
- Explicitly track recursion depth in fragments [#704](https://github.com/rust-bitcoin/rust-miniscript/pull/704)
4+
15
# 10.0.0 - May 24, 2023
26

37
- Works with rust-bitcoin 0.30.0

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "miniscript"
3-
version = "10.0.0"
3+
version = "10.1.0"
44
authors = ["Andrew Poelstra <[email protected]>, Sanket Kanjalkar <[email protected]>"]
55
license = "CC0-1.0"
66
homepage = "https://github.com/rust-bitcoin/rust-miniscript/"

src/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ mod macros;
117117
mod pub_macros;
118118

119119
use internals::hex::exts::DisplayHex;
120-
pub use pub_macros::*;
121120

122121
pub mod descriptor;
123122
pub mod expression;
@@ -899,6 +898,7 @@ mod tests {
899898
}
900899
}
901900

901+
#[allow(unused_imports)] // this is an internal prelude module; not all imports are used with every feature combination
902902
mod prelude {
903903
// Mutex implementation from LDK
904904
// https://github.com/lightningdevkit/rust-lightning/blob/9bdce47f0e0516e37c89c09f1975dfc06b5870b1/lightning-invoice/src/sync.rs
@@ -962,10 +962,9 @@ mod prelude {
962962
};
963963
#[cfg(any(feature = "std", test))]
964964
pub use std::{
965-
borrow::{Borrow, Cow, ToOwned},
965+
borrow::{Borrow, ToOwned},
966966
boxed::Box,
967967
collections::{vec_deque::VecDeque, BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet},
968-
rc, slice,
969968
string::{String, ToString},
970969
sync,
971970
sync::Mutex,

src/miniscript/mod.rs

+20-2
Large diffs are not rendered by default.

src/miniscript/types/extra_props.rs

+32
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ pub struct ExtData {
139139
/// This does **not** include initial witness elements. This element only captures
140140
/// the additional elements that are pushed during execution.
141141
pub exec_stack_elem_count_dissat: Option<usize>,
142+
/// The miniscript tree depth/height of this node.
143+
/// Used for checking the max depth of the miniscript tree to prevent stack overflow.
144+
pub tree_height: usize,
142145
}
143146

144147
impl Property for ExtData {
@@ -165,6 +168,7 @@ impl Property for ExtData {
165168
timelock_info: TimelockInfo::default(),
166169
exec_stack_elem_count_sat: Some(1),
167170
exec_stack_elem_count_dissat: None,
171+
tree_height : 0,
168172
}
169173
}
170174

@@ -180,6 +184,7 @@ impl Property for ExtData {
180184
timelock_info: TimelockInfo::default(),
181185
exec_stack_elem_count_sat: None,
182186
exec_stack_elem_count_dissat: Some(1),
187+
tree_height : 0,
183188
}
184189
}
185190

@@ -201,6 +206,7 @@ impl Property for ExtData {
201206
timelock_info: TimelockInfo::default(),
202207
exec_stack_elem_count_sat: Some(1), // pushes the pk
203208
exec_stack_elem_count_dissat: Some(1),
209+
tree_height: 0,
204210
}
205211
}
206212

@@ -222,6 +228,7 @@ impl Property for ExtData {
222228
timelock_info: TimelockInfo::default(),
223229
exec_stack_elem_count_sat: Some(2), // dup and hash push
224230
exec_stack_elem_count_dissat: Some(2),
231+
tree_height: 0,
225232
}
226233
}
227234

@@ -245,6 +252,7 @@ impl Property for ExtData {
245252
timelock_info: TimelockInfo::default(),
246253
exec_stack_elem_count_sat: Some(n), // n pks
247254
exec_stack_elem_count_dissat: Some(n),
255+
tree_height: 0,
248256
}
249257
}
250258

@@ -267,6 +275,7 @@ impl Property for ExtData {
267275
timelock_info: TimelockInfo::default(),
268276
exec_stack_elem_count_sat: Some(2), // the two nums before num equal verify
269277
exec_stack_elem_count_dissat: Some(2),
278+
tree_height: 0,
270279
}
271280
}
272281

@@ -287,6 +296,7 @@ impl Property for ExtData {
287296
timelock_info: TimelockInfo::default(),
288297
exec_stack_elem_count_sat: Some(2), // either size <32> or <hash256> <32 byte>
289298
exec_stack_elem_count_dissat: Some(2),
299+
tree_height: 0,
290300
}
291301
}
292302

@@ -302,6 +312,7 @@ impl Property for ExtData {
302312
timelock_info: TimelockInfo::default(),
303313
exec_stack_elem_count_sat: Some(2), // either size <32> or <hash256> <32 byte>
304314
exec_stack_elem_count_dissat: Some(2),
315+
tree_height: 0,
305316
}
306317
}
307318

@@ -317,6 +328,7 @@ impl Property for ExtData {
317328
timelock_info: TimelockInfo::default(),
318329
exec_stack_elem_count_sat: Some(2), // either size <32> or <hash256> <20 byte>
319330
exec_stack_elem_count_dissat: Some(2),
331+
tree_height: 0,
320332
}
321333
}
322334

@@ -332,6 +344,7 @@ impl Property for ExtData {
332344
timelock_info: TimelockInfo::default(),
333345
exec_stack_elem_count_sat: Some(2), // either size <32> or <hash256> <20 byte>
334346
exec_stack_elem_count_dissat: Some(2),
347+
tree_height: 0,
335348
}
336349
}
337350

@@ -357,6 +370,7 @@ impl Property for ExtData {
357370
},
358371
exec_stack_elem_count_sat: Some(1), // <t>
359372
exec_stack_elem_count_dissat: None,
373+
tree_height: 0,
360374
}
361375
}
362376

@@ -378,6 +392,7 @@ impl Property for ExtData {
378392
},
379393
exec_stack_elem_count_sat: Some(1), // <t>
380394
exec_stack_elem_count_dissat: None,
395+
tree_height: 0,
381396
}
382397
}
383398

@@ -393,6 +408,7 @@ impl Property for ExtData {
393408
timelock_info: self.timelock_info,
394409
exec_stack_elem_count_sat: self.exec_stack_elem_count_sat,
395410
exec_stack_elem_count_dissat: self.exec_stack_elem_count_dissat,
411+
tree_height : self.tree_height + 1,
396412
})
397413
}
398414

@@ -408,6 +424,7 @@ impl Property for ExtData {
408424
timelock_info: self.timelock_info,
409425
exec_stack_elem_count_sat: self.exec_stack_elem_count_sat,
410426
exec_stack_elem_count_dissat: self.exec_stack_elem_count_dissat,
427+
tree_height : self.tree_height + 1,
411428
})
412429
}
413430

@@ -423,6 +440,7 @@ impl Property for ExtData {
423440
timelock_info: self.timelock_info,
424441
exec_stack_elem_count_sat: self.exec_stack_elem_count_sat,
425442
exec_stack_elem_count_dissat: self.exec_stack_elem_count_dissat,
443+
tree_height : self.tree_height + 1,
426444
})
427445
}
428446

@@ -441,6 +459,7 @@ impl Property for ExtData {
441459
// Even all V types push something onto the stack and then remove them
442460
exec_stack_elem_count_sat: self.exec_stack_elem_count_sat,
443461
exec_stack_elem_count_dissat: Some(1),
462+
tree_height : self.tree_height + 1,
444463
})
445464
}
446465

@@ -457,6 +476,7 @@ impl Property for ExtData {
457476
timelock_info: self.timelock_info,
458477
exec_stack_elem_count_sat: self.exec_stack_elem_count_sat,
459478
exec_stack_elem_count_dissat: None,
479+
tree_height : self.tree_height + 1,
460480
})
461481
}
462482

@@ -472,6 +492,7 @@ impl Property for ExtData {
472492
timelock_info: self.timelock_info,
473493
exec_stack_elem_count_sat: self.exec_stack_elem_count_sat,
474494
exec_stack_elem_count_dissat: Some(1),
495+
tree_height : self.tree_height + 1,
475496
})
476497
}
477498

@@ -488,6 +509,7 @@ impl Property for ExtData {
488509
// Technically max(1, self.exec_stack_elem_count_sat), same rationale as cast_dupif
489510
exec_stack_elem_count_sat: self.exec_stack_elem_count_sat,
490511
exec_stack_elem_count_dissat: self.exec_stack_elem_count_dissat,
512+
tree_height : self.tree_height + 1,
491513
})
492514
}
493515

@@ -528,6 +550,7 @@ impl Property for ExtData {
528550
l.exec_stack_elem_count_dissat,
529551
r.exec_stack_elem_count_dissat.map(|x| x + 1),
530552
),
553+
tree_height : cmp::max(l.tree_height, r.tree_height) + 1,
531554
})
532555
}
533556

@@ -555,6 +578,7 @@ impl Property for ExtData {
555578
r.exec_stack_elem_count_sat,
556579
),
557580
exec_stack_elem_count_dissat: None,
581+
tree_height : cmp::max(l.tree_height, r.tree_height) + 1,
558582
})
559583
}
560584

@@ -603,6 +627,7 @@ impl Property for ExtData {
603627
l.exec_stack_elem_count_dissat,
604628
r.exec_stack_elem_count_dissat.map(|x| x + 1),
605629
),
630+
tree_height : cmp::max(l.tree_height, r.tree_height) + 1,
606631
})
607632
}
608633

@@ -640,6 +665,7 @@ impl Property for ExtData {
640665
l.exec_stack_elem_count_dissat,
641666
r.exec_stack_elem_count_dissat.map(|x| x + 1),
642667
),
668+
tree_height : cmp::max(l.tree_height, r.tree_height) + 1,
643669
};
644670
Ok(res)
645671
}
@@ -671,6 +697,7 @@ impl Property for ExtData {
671697
opt_max(r.exec_stack_elem_count_sat, l.exec_stack_elem_count_dissat),
672698
),
673699
exec_stack_elem_count_dissat: None,
700+
tree_height : cmp::max(l.tree_height, r.tree_height) + 1,
674701
})
675702
}
676703

@@ -717,6 +744,7 @@ impl Property for ExtData {
717744
l.exec_stack_elem_count_dissat,
718745
r.exec_stack_elem_count_dissat,
719746
),
747+
tree_height : cmp::max(l.tree_height, r.tree_height) + 1,
720748
})
721749
}
722750

@@ -762,6 +790,7 @@ impl Property for ExtData {
762790
a.exec_stack_elem_count_dissat,
763791
c.exec_stack_elem_count_dissat,
764792
),
793+
tree_height : cmp::max(a.tree_height, cmp::max(b.tree_height, c.tree_height)) + 1,
765794
})
766795
}
767796

@@ -781,6 +810,7 @@ impl Property for ExtData {
781810
// the max element count is same as max sat element count when satisfying one element + 1
782811
let mut exec_stack_elem_count_sat_vec = Vec::with_capacity(n);
783812
let mut exec_stack_elem_count_dissat = Some(0);
813+
let mut max_child_height = 0;
784814

785815
for i in 0..n {
786816
let sub = sub_ck(i)?;
@@ -814,6 +844,7 @@ impl Property for ExtData {
814844
exec_stack_elem_count_dissat,
815845
sub.exec_stack_elem_count_dissat,
816846
);
847+
max_child_height = cmp::max(max_child_height, sub.tree_height) + 1;
817848
}
818849

819850
stack_elem_count_sat_vec.sort_by(sat_minus_option_dissat);
@@ -885,6 +916,7 @@ impl Property for ExtData {
885916
timelock_info: TimelockInfo::combine_threshold(k, timelocks),
886917
exec_stack_elem_count_sat,
887918
exec_stack_elem_count_dissat,
919+
tree_height : max_child_height + 1,
888920
})
889921
}
890922

src/psbt/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1086,9 +1086,11 @@ impl PsbtFields for psbt::Input {
10861086
) -> &mut BTreeMap<bitcoin::key::XOnlyPublicKey, (Vec<TapLeafHash>, bip32::KeySource)> {
10871087
&mut self.tap_key_origins
10881088
}
1089+
#[allow(dead_code)]
10891090
fn proprietary(&mut self) -> &mut BTreeMap<psbt::raw::ProprietaryKey, Vec<u8>> {
10901091
&mut self.proprietary
10911092
}
1093+
#[allow(dead_code)]
10921094
fn unknown(&mut self) -> &mut BTreeMap<psbt::raw::Key, Vec<u8>> {
10931095
&mut self.unknown
10941096
}
@@ -1119,9 +1121,11 @@ impl PsbtFields for psbt::Output {
11191121
) -> &mut BTreeMap<bitcoin::key::XOnlyPublicKey, (Vec<TapLeafHash>, bip32::KeySource)> {
11201122
&mut self.tap_key_origins
11211123
}
1124+
#[allow(dead_code)]
11221125
fn proprietary(&mut self) -> &mut BTreeMap<psbt::raw::ProprietaryKey, Vec<u8>> {
11231126
&mut self.proprietary
11241127
}
1128+
#[allow(dead_code)]
11251129
fn unknown(&mut self) -> &mut BTreeMap<psbt::raw::Key, Vec<u8>> {
11261130
&mut self.unknown
11271131
}

0 commit comments

Comments
 (0)