Skip to content

Commit f36e4f9

Browse files
authored
Merge pull request #121 from sanket1729/heightlocks
Detect miniscripts that have a satisfaction with a combination of time locks and height locks
2 parents 6af9cf7 + a662105 commit f36e4f9

File tree

9 files changed

+355
-72
lines changed

9 files changed

+355
-72
lines changed

examples/htlc.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ fn main() {
3939
);
4040

4141
assert_eq!(
42-
format!("{}", htlc_descriptor.lift()),
43-
"or(and(pkh(4377a5acd66dc5cb67148a24818d1e51fa183bd2),pkh(4377a5acd66dc5cb67148a24818d1e51fa183bd2),older(4444)),sha256(1111111111111111111111111111111111111111111111111111111111111111))");
42+
format!("{}", htlc_descriptor.lift().unwrap()),
43+
"or(and(pkh(4377a5acd66dc5cb67148a24818d1e51fa183bd2),pkh(4377a5acd66dc5cb67148a24818d1e51fa183bd2),older(4444)),sha256(1111111111111111111111111111111111111111111111111111111111111111))"
44+
);
4445

4546
assert_eq!(
4647
format!("{:x}", htlc_descriptor.script_pubkey()),

fuzz/fuzz_targets/compile_descriptor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fn do_test(data: &[u8]) {
1515
// Compile
1616
if let Ok(desc) = pol.compile::<Segwitv0>() {
1717
// Lift
18-
assert_eq!(desc.clone().lift(), pol.clone().lift());
18+
assert_eq!(desc.clone().lift().unwrap(), pol.clone().lift().unwrap());
1919
// Try to roundtrip the output of the compiler
2020
let output = desc.to_string();
2121
if let Ok(desc) = DummyScript::from_str(&output) {

src/miniscript/astelem.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ impl<Pk: MiniscriptKey + ToPublicKey, Ctx: ScriptContext> Terminal<Pk, Ctx> {
710710
Terminal::Check(ref sub) => sub.node.script_size() + 1,
711711
Terminal::DupIf(ref sub) => sub.node.script_size() + 3,
712712
Terminal::Verify(ref sub) => {
713-
sub.node.script_size() + if sub.ext.has_verify_form { 0 } else { 1 }
713+
sub.node.script_size() + if sub.ext.has_free_verify { 0 } else { 1 }
714714
}
715715
Terminal::NonZero(ref sub) => sub.node.script_size() + 4,
716716
Terminal::ZeroNotEqual(ref sub) => sub.node.script_size() + 1,

src/miniscript/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ mod tests {
659659
keys[4].to_string(),
660660
);
661661

662-
let mut abs = miniscript.lift();
662+
let mut abs = miniscript.lift().unwrap();
663663
assert_eq!(abs.n_keys(), 5);
664664
assert_eq!(abs.minimum_n_keys(), 2);
665665
abs = abs.at_age(10000);

src/miniscript/satisfy.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use bitcoin::hashes::{hash160, ripemd160, sha256, sha256d};
2525
use bitcoin::{self, secp256k1};
2626
use {MiniscriptKey, ToPublicKey};
2727

28+
use miniscript::types::extra_props::HEIGHT_TIME_THRESHOLD;
2829
use ScriptContext;
2930
use Terminal;
3031

@@ -94,7 +95,12 @@ pub struct Older(pub u32);
9495

9596
impl<Pk: MiniscriptKey> Satisfier<Pk> for Older {
9697
fn check_older(&self, n: u32) -> bool {
97-
n <= self.0
98+
// if n > self.0; we will be returning false anyways
99+
if n < HEIGHT_TIME_THRESHOLD && self.0 >= HEIGHT_TIME_THRESHOLD {
100+
false
101+
} else {
102+
n <= self.0
103+
}
98104
}
99105
}
100106

@@ -104,7 +110,12 @@ pub struct After(pub u32);
104110

105111
impl<Pk: MiniscriptKey> Satisfier<Pk> for After {
106112
fn check_after(&self, n: u32) -> bool {
107-
n <= self.0
113+
// if n > self.0; we will be returning false anyways
114+
if n < HEIGHT_TIME_THRESHOLD && self.0 >= HEIGHT_TIME_THRESHOLD {
115+
false
116+
} else {
117+
n <= self.0
118+
}
108119
}
109120
}
110121

0 commit comments

Comments
 (0)