Skip to content

Commit b949020

Browse files
committed
Use Abstract instead of Semantic
We are moving away from the usage of "semantic" as a synonym for "abstract". Use `Abstract` instead of `Semantic` as the type alias for `crate::policy::r#abstract::Policy`.
1 parent 2c67f9a commit b949020

File tree

3 files changed

+56
-59
lines changed

3 files changed

+56
-59
lines changed

src/abstract/lift.rs

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::error;
1515
use crate::descriptor::Descriptor;
1616
use crate::miniscript::{Miniscript, ScriptContext};
1717
use crate::policy::concrete::Policy as Concrete;
18-
use crate::policy::r#abstract::Policy as Semantic;
18+
use crate::policy::r#abstract::Policy as Abstract;
1919
use crate::sync::Arc;
2020
use crate::{Error, MiniscriptKey, Terminal};
2121

@@ -24,7 +24,7 @@ use crate::{Error, MiniscriptKey, Terminal};
2424
///
2525
/// After Lifting all policies are converted into `KeyHash(Pk::HasH)` to
2626
/// maintain the following invariant(modulo resource limits):
27-
/// `Lift(Concrete) == Concrete -> Miniscript -> Script -> Miniscript -> Semantic`
27+
/// `Lift(Concrete) == Concrete -> Miniscript -> Script -> Miniscript -> Abstract`
2828
///
2929
/// Lifting from [`Miniscript`] or [`Descriptor`] can fail if the miniscript
3030
/// contains a timelock combination or if it contains a branch that exceeds
@@ -37,7 +37,7 @@ use crate::{Error, MiniscriptKey, Terminal};
3737
/// policies.
3838
pub trait Liftable<Pk: MiniscriptKey> {
3939
/// Converts this object into an abstract policy.
40-
fn lift(&self) -> Result<Semantic<Pk>, Error>;
40+
fn lift(&self) -> Result<Abstract<Pk>, Error>;
4141
}
4242

4343
/// Error occurring during lifting.
@@ -77,7 +77,7 @@ impl error::Error for LiftError {
7777
}
7878

7979
impl<Pk: MiniscriptKey, Ctx: ScriptContext> Miniscript<Pk, Ctx> {
80-
/// Lifting corresponds to conversion of a miniscript into a [`Semantic`]
80+
/// Lifting corresponds to conversion of a miniscript into a [`Abstract`]
8181
/// policy for human readable or machine analysis. However, naively lifting
8282
/// miniscripts can result in incorrect interpretations that don't
8383
/// correspond to the underlying semantics when we try to spend them on
@@ -96,7 +96,7 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Miniscript<Pk, Ctx> {
9696
}
9797

9898
impl<Pk: MiniscriptKey, Ctx: ScriptContext> Liftable<Pk> for Miniscript<Pk, Ctx> {
99-
fn lift(&self) -> Result<Semantic<Pk>, Error> {
99+
fn lift(&self) -> Result<Abstract<Pk>, Error> {
100100
// check whether the root miniscript can have a spending path that is
101101
// a combination of heightlock and timelock
102102
self.lift_check()?;
@@ -105,20 +105,20 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Liftable<Pk> for Miniscript<Pk, Ctx>
105105
}
106106

107107
impl<Pk: MiniscriptKey, Ctx: ScriptContext> Liftable<Pk> for Terminal<Pk, Ctx> {
108-
fn lift(&self) -> Result<Semantic<Pk>, Error> {
108+
fn lift(&self) -> Result<Abstract<Pk>, Error> {
109109
let ret = match *self {
110-
Terminal::PkK(ref pk) | Terminal::PkH(ref pk) => Semantic::Key(pk.clone()),
110+
Terminal::PkK(ref pk) | Terminal::PkH(ref pk) => Abstract::Key(pk.clone()),
111111
Terminal::RawPkH(ref _pkh) => {
112112
return Err(Error::LiftError(LiftError::RawDescriptorLift))
113113
}
114-
Terminal::After(t) => Semantic::After(t),
115-
Terminal::Older(t) => Semantic::Older(t),
116-
Terminal::Sha256(ref h) => Semantic::Sha256(h.clone()),
117-
Terminal::Hash256(ref h) => Semantic::Hash256(h.clone()),
118-
Terminal::Ripemd160(ref h) => Semantic::Ripemd160(h.clone()),
119-
Terminal::Hash160(ref h) => Semantic::Hash160(h.clone()),
120-
Terminal::False => Semantic::Unsatisfiable,
121-
Terminal::True => Semantic::Trivial,
114+
Terminal::After(t) => Abstract::After(t),
115+
Terminal::Older(t) => Abstract::Older(t),
116+
Terminal::Sha256(ref h) => Abstract::Sha256(h.clone()),
117+
Terminal::Hash256(ref h) => Abstract::Hash256(h.clone()),
118+
Terminal::Ripemd160(ref h) => Abstract::Ripemd160(h.clone()),
119+
Terminal::Hash160(ref h) => Abstract::Hash160(h.clone()),
120+
Terminal::False => Abstract::Unsatisfiable,
121+
Terminal::True => Abstract::Trivial,
122122
Terminal::Alt(ref sub)
123123
| Terminal::Swap(ref sub)
124124
| Terminal::Check(ref sub)
@@ -127,27 +127,27 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Liftable<Pk> for Terminal<Pk, Ctx> {
127127
| Terminal::NonZero(ref sub)
128128
| Terminal::ZeroNotEqual(ref sub) => sub.node.lift()?,
129129
Terminal::AndV(ref left, ref right) | Terminal::AndB(ref left, ref right) => {
130-
Semantic::Threshold(2, vec![left.node.lift()?, right.node.lift()?])
130+
Abstract::Threshold(2, vec![left.node.lift()?, right.node.lift()?])
131131
}
132-
Terminal::AndOr(ref a, ref b, ref c) => Semantic::Threshold(
132+
Terminal::AndOr(ref a, ref b, ref c) => Abstract::Threshold(
133133
1,
134134
vec![
135-
Semantic::Threshold(2, vec![a.node.lift()?, b.node.lift()?]),
135+
Abstract::Threshold(2, vec![a.node.lift()?, b.node.lift()?]),
136136
c.node.lift()?,
137137
],
138138
),
139139
Terminal::OrB(ref left, ref right)
140140
| Terminal::OrD(ref left, ref right)
141141
| Terminal::OrC(ref left, ref right)
142142
| Terminal::OrI(ref left, ref right) => {
143-
Semantic::Threshold(1, vec![left.node.lift()?, right.node.lift()?])
143+
Abstract::Threshold(1, vec![left.node.lift()?, right.node.lift()?])
144144
}
145145
Terminal::Thresh(k, ref subs) => {
146146
let semantic_subs: Result<_, Error> = subs.iter().map(|s| s.node.lift()).collect();
147-
Semantic::Threshold(k, semantic_subs?)
147+
Abstract::Threshold(k, semantic_subs?)
148148
}
149149
Terminal::Multi(k, ref keys) | Terminal::MultiA(k, ref keys) => {
150-
Semantic::Threshold(k, keys.iter().map(|k| Semantic::Key(k.clone())).collect())
150+
Abstract::Threshold(k, keys.iter().map(|k| Abstract::Key(k.clone())).collect())
151151
}
152152
}
153153
.normalized();
@@ -156,7 +156,7 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Liftable<Pk> for Terminal<Pk, Ctx> {
156156
}
157157

158158
impl<Pk: MiniscriptKey> Liftable<Pk> for Descriptor<Pk> {
159-
fn lift(&self) -> Result<Semantic<Pk>, Error> {
159+
fn lift(&self) -> Result<Abstract<Pk>, Error> {
160160
match *self {
161161
Descriptor::Bare(ref bare) => bare.lift(),
162162
Descriptor::Pkh(ref pkh) => pkh.lift(),
@@ -168,45 +168,45 @@ impl<Pk: MiniscriptKey> Liftable<Pk> for Descriptor<Pk> {
168168
}
169169
}
170170

171-
impl<Pk: MiniscriptKey> Liftable<Pk> for Semantic<Pk> {
172-
fn lift(&self) -> Result<Semantic<Pk>, Error> { Ok(self.clone()) }
171+
impl<Pk: MiniscriptKey> Liftable<Pk> for Abstract<Pk> {
172+
fn lift(&self) -> Result<Abstract<Pk>, Error> { Ok(self.clone()) }
173173
}
174174

175175
impl<Pk: MiniscriptKey> Liftable<Pk> for Concrete<Pk> {
176-
fn lift(&self) -> Result<Semantic<Pk>, Error> {
176+
fn lift(&self) -> Result<Abstract<Pk>, Error> {
177177
// do not lift if there is a possible satisfaction
178178
// involving combination of timelocks and heightlocks
179179
self.check_timelocks()?;
180180
let ret = match *self {
181-
Concrete::Unsatisfiable => Semantic::Unsatisfiable,
182-
Concrete::Trivial => Semantic::Trivial,
183-
Concrete::Key(ref pk) => Semantic::Key(pk.clone()),
184-
Concrete::After(t) => Semantic::After(t),
185-
Concrete::Older(t) => Semantic::Older(t),
186-
Concrete::Sha256(ref h) => Semantic::Sha256(h.clone()),
187-
Concrete::Hash256(ref h) => Semantic::Hash256(h.clone()),
188-
Concrete::Ripemd160(ref h) => Semantic::Ripemd160(h.clone()),
189-
Concrete::Hash160(ref h) => Semantic::Hash160(h.clone()),
181+
Concrete::Unsatisfiable => Abstract::Unsatisfiable,
182+
Concrete::Trivial => Abstract::Trivial,
183+
Concrete::Key(ref pk) => Abstract::Key(pk.clone()),
184+
Concrete::After(t) => Abstract::After(t),
185+
Concrete::Older(t) => Abstract::Older(t),
186+
Concrete::Sha256(ref h) => Abstract::Sha256(h.clone()),
187+
Concrete::Hash256(ref h) => Abstract::Hash256(h.clone()),
188+
Concrete::Ripemd160(ref h) => Abstract::Ripemd160(h.clone()),
189+
Concrete::Hash160(ref h) => Abstract::Hash160(h.clone()),
190190
Concrete::And(ref subs) => {
191191
let semantic_subs: Result<_, Error> = subs.iter().map(Liftable::lift).collect();
192-
Semantic::Threshold(2, semantic_subs?)
192+
Abstract::Threshold(2, semantic_subs?)
193193
}
194194
Concrete::Or(ref subs) => {
195195
let semantic_subs: Result<_, Error> =
196196
subs.iter().map(|(_p, sub)| sub.lift()).collect();
197-
Semantic::Threshold(1, semantic_subs?)
197+
Abstract::Threshold(1, semantic_subs?)
198198
}
199199
Concrete::Threshold(k, ref subs) => {
200200
let semantic_subs: Result<_, Error> = subs.iter().map(Liftable::lift).collect();
201-
Semantic::Threshold(k, semantic_subs?)
201+
Abstract::Threshold(k, semantic_subs?)
202202
}
203203
}
204204
.normalized();
205205
Ok(ret)
206206
}
207207
}
208208
impl<Pk: MiniscriptKey> Liftable<Pk> for Arc<Concrete<Pk>> {
209-
fn lift(&self) -> Result<Semantic<Pk>, Error> { self.as_ref().lift() }
209+
fn lift(&self) -> Result<Abstract<Pk>, Error> { self.as_ref().lift() }
210210
}
211211

212212
#[cfg(test)]
@@ -227,7 +227,7 @@ mod tests {
227227
use crate::{descriptor::TapTree, Descriptor, Tap};
228228

229229
type ConcretePol = crate::policy::concrete::Policy<String>;
230-
type SemanticPol = crate::policy::r#abstract::Policy<String>;
230+
type AbstractPol = crate::policy::r#abstract::Policy<String>;
231231

232232
fn concrete_policy_rtt(s: &str) {
233233
let conc = ConcretePol::from_str(s).unwrap();
@@ -236,7 +236,7 @@ mod tests {
236236
}
237237

238238
fn semantic_policy_rtt(s: &str) {
239-
let sem = SemanticPol::from_str(s).unwrap();
239+
let sem = AbstractPol::from_str(s).unwrap();
240240
let output = sem.normalized().to_string();
241241
assert_eq!(s.to_lowercase(), output.to_lowercase());
242242
}
@@ -269,8 +269,8 @@ mod tests {
269269

270270
//fuzzer crashes
271271
assert!(ConcretePol::from_str("thresh()").is_err());
272-
assert!(SemanticPol::from_str("thresh(0)").is_err());
273-
assert!(SemanticPol::from_str("thresh()").is_err());
272+
assert!(AbstractPol::from_str("thresh(0)").is_err());
273+
assert!(AbstractPol::from_str("thresh()").is_err());
274274
concrete_policy_rtt("ripemd160()");
275275
}
276276

@@ -336,17 +336,17 @@ mod tests {
336336
.parse()
337337
.unwrap();
338338
assert_eq!(
339-
Semantic::Threshold(
339+
Abstract::Threshold(
340340
1,
341341
vec![
342-
Semantic::Threshold(
342+
Abstract::Threshold(
343343
2,
344344
vec![
345-
Semantic::Key(key_a),
346-
Semantic::Older(Sequence::from_height(42))
345+
Abstract::Key(key_a),
346+
Abstract::Older(Sequence::from_height(42))
347347
]
348348
),
349-
Semantic::Key(key_b)
349+
Abstract::Key(key_b)
350350
]
351351
),
352352
ms_str.lift().unwrap()

src/policy/abstract.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// SPDX-License-Identifier: CC0-1.0
22

33
//! Abstract Policies
4-
//!
5-
//! We use the terms "semantic" and "abstract" interchangeably because
6-
//! "abstract" is a reserved keyword in Rust.
74
85
use core::str::FromStr;
96
use core::{fmt, str};
@@ -18,7 +15,7 @@ use crate::{errstr, expression, AbsLockTime, Error, ForEachKey, MiniscriptKey, T
1815
/// Abstract policy which corresponds to the semantics of a miniscript and
1916
/// which allows complex forms of analysis, e.g. filtering and normalization.
2017
///
21-
/// Semantic policies store only hashes of keys to ensure that objects
18+
/// Abstract policies store only hashes of keys to ensure that objects
2219
/// representing the same policy are lifted to the same abstract `Policy`,
2320
/// regardless of their choice of `pk` or `pk_h` nodes.
2421
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
@@ -380,7 +377,7 @@ impl_from_tree!(
380377
// thresh(1) and thresh(n) are disallowed in semantic policies
381378
if thresh <= 1 || thresh >= (nsubs as u32 - 1) {
382379
return Err(errstr(
383-
"Semantic Policy thresh cannot have k = 1 or k =n, use `and`/`or` instead",
380+
"Abstract Policy thresh cannot have k = 1 or k =n, use `and`/`or` instead",
384381
));
385382
}
386383
if thresh >= (nsubs as u32) {

src/policy/concrete.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use bitcoin::{absolute, Sequence};
1212
use {
1313
crate::descriptor::TapTree, crate::miniscript::ScriptContext, crate::policy::compiler,
1414
crate::policy::compiler::CompilerError, crate::policy::compiler::OrdF64,
15-
crate::policy::concrete::Policy as Concrete, crate::policy::r#abstract::Policy as Semantic,
15+
crate::policy::concrete::Policy as Concrete, crate::policy::r#abstract::Policy as Abstract,
1616
crate::r#abstract::Liftable, crate::Descriptor, crate::Miniscript, crate::Tap,
1717
core::cmp::Reverse,
1818
};
@@ -94,9 +94,9 @@ pub enum PolicyError {
9494
ZeroTime,
9595
/// `after` fragment can only have `n < 2^31`.
9696
TimeTooFar,
97-
/// Semantic Policy Error: `And` `Or` fragments must take args: `k > 1`.
97+
/// Abstract Policy Error: `And` `Or` fragments must take args: `k > 1`.
9898
InsufficientArgsforAnd,
99-
/// Semantic policy error: `And` `Or` fragments must take args: `k > 1`.
99+
/// Abstract policy error: `And` `Or` fragments must take args: `k > 1`.
100100
InsufficientArgsforOr,
101101
/// Entailment max terminals exceeded.
102102
EntailmentMaxTerminals,
@@ -136,10 +136,10 @@ impl fmt::Display for PolicyError {
136136
}
137137
PolicyError::ZeroTime => f.write_str("Time must be greater than 0; n > 0"),
138138
PolicyError::InsufficientArgsforAnd => {
139-
f.write_str("Semantic Policy 'And' fragment must have at least 2 args ")
139+
f.write_str("Abstract Policy 'And' fragment must have at least 2 args ")
140140
}
141141
PolicyError::InsufficientArgsforOr => {
142-
f.write_str("Semantic Policy 'Or' fragment must have at least 2 args ")
142+
f.write_str("Abstract Policy 'Or' fragment must have at least 2 args ")
143143
}
144144
PolicyError::EntailmentMaxTerminals => {
145145
write!(f, "Policy entailment only supports {} terminals", ENTAILMENT_MAX_TERMINALS)
@@ -234,8 +234,8 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
234234
for key in concrete_keys.into_iter() {
235235
if semantic_policy
236236
.clone()
237-
.satisfy_constraint(&Semantic::Key(key.clone()), true)
238-
== Semantic::Trivial
237+
.satisfy_constraint(&Abstract::Key(key.clone()), true)
238+
== Abstract::Trivial
239239
{
240240
match key_prob_map.get(&Concrete::Key(key.clone())) {
241241
Some(val) => {

0 commit comments

Comments
 (0)