@@ -15,7 +15,7 @@ use std::error;
15
15
use crate :: descriptor:: Descriptor ;
16
16
use crate :: miniscript:: { Miniscript , ScriptContext } ;
17
17
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 ;
19
19
use crate :: sync:: Arc ;
20
20
use crate :: { Error , MiniscriptKey , Terminal } ;
21
21
@@ -24,7 +24,7 @@ use crate::{Error, MiniscriptKey, Terminal};
24
24
///
25
25
/// After Lifting all policies are converted into `KeyHash(Pk::HasH)` to
26
26
/// maintain the following invariant(modulo resource limits):
27
- /// `Lift(Concrete) == Concrete -> Miniscript -> Script -> Miniscript -> Semantic `
27
+ /// `Lift(Concrete) == Concrete -> Miniscript -> Script -> Miniscript -> Abstract `
28
28
///
29
29
/// Lifting from [`Miniscript`] or [`Descriptor`] can fail if the miniscript
30
30
/// contains a timelock combination or if it contains a branch that exceeds
@@ -37,7 +37,7 @@ use crate::{Error, MiniscriptKey, Terminal};
37
37
/// policies.
38
38
pub trait Liftable < Pk : MiniscriptKey > {
39
39
/// Converts this object into an abstract policy.
40
- fn lift ( & self ) -> Result < Semantic < Pk > , Error > ;
40
+ fn lift ( & self ) -> Result < Abstract < Pk > , Error > ;
41
41
}
42
42
43
43
/// Error occurring during lifting.
@@ -77,7 +77,7 @@ impl error::Error for LiftError {
77
77
}
78
78
79
79
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 `]
81
81
/// policy for human readable or machine analysis. However, naively lifting
82
82
/// miniscripts can result in incorrect interpretations that don't
83
83
/// correspond to the underlying semantics when we try to spend them on
@@ -96,7 +96,7 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Miniscript<Pk, Ctx> {
96
96
}
97
97
98
98
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 > {
100
100
// check whether the root miniscript can have a spending path that is
101
101
// a combination of heightlock and timelock
102
102
self . lift_check ( ) ?;
@@ -105,20 +105,20 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Liftable<Pk> for Miniscript<Pk, Ctx>
105
105
}
106
106
107
107
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 > {
109
109
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 ( ) ) ,
111
111
Terminal :: RawPkH ( ref _pkh) => {
112
112
return Err ( Error :: LiftError ( LiftError :: RawDescriptorLift ) )
113
113
}
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 ,
122
122
Terminal :: Alt ( ref sub)
123
123
| Terminal :: Swap ( ref sub)
124
124
| Terminal :: Check ( ref sub)
@@ -127,27 +127,27 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Liftable<Pk> for Terminal<Pk, Ctx> {
127
127
| Terminal :: NonZero ( ref sub)
128
128
| Terminal :: ZeroNotEqual ( ref sub) => sub. node . lift ( ) ?,
129
129
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( ) ?] )
131
131
}
132
- Terminal :: AndOr ( ref a, ref b, ref c) => Semantic :: Threshold (
132
+ Terminal :: AndOr ( ref a, ref b, ref c) => Abstract :: Threshold (
133
133
1 ,
134
134
vec ! [
135
- Semantic :: Threshold ( 2 , vec![ a. node. lift( ) ?, b. node. lift( ) ?] ) ,
135
+ Abstract :: Threshold ( 2 , vec![ a. node. lift( ) ?, b. node. lift( ) ?] ) ,
136
136
c. node. lift( ) ?,
137
137
] ,
138
138
) ,
139
139
Terminal :: OrB ( ref left, ref right)
140
140
| Terminal :: OrD ( ref left, ref right)
141
141
| Terminal :: OrC ( ref left, ref right)
142
142
| 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( ) ?] )
144
144
}
145
145
Terminal :: Thresh ( k, ref subs) => {
146
146
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?)
148
148
}
149
149
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 ( ) )
151
151
}
152
152
}
153
153
. normalized ( ) ;
@@ -156,7 +156,7 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Liftable<Pk> for Terminal<Pk, Ctx> {
156
156
}
157
157
158
158
impl < Pk : MiniscriptKey > Liftable < Pk > for Descriptor < Pk > {
159
- fn lift ( & self ) -> Result < Semantic < Pk > , Error > {
159
+ fn lift ( & self ) -> Result < Abstract < Pk > , Error > {
160
160
match * self {
161
161
Descriptor :: Bare ( ref bare) => bare. lift ( ) ,
162
162
Descriptor :: Pkh ( ref pkh) => pkh. lift ( ) ,
@@ -168,45 +168,45 @@ impl<Pk: MiniscriptKey> Liftable<Pk> for Descriptor<Pk> {
168
168
}
169
169
}
170
170
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 ( ) ) }
173
173
}
174
174
175
175
impl < Pk : MiniscriptKey > Liftable < Pk > for Concrete < Pk > {
176
- fn lift ( & self ) -> Result < Semantic < Pk > , Error > {
176
+ fn lift ( & self ) -> Result < Abstract < Pk > , Error > {
177
177
// do not lift if there is a possible satisfaction
178
178
// involving combination of timelocks and heightlocks
179
179
self . check_timelocks ( ) ?;
180
180
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 ( ) ) ,
190
190
Concrete :: And ( ref subs) => {
191
191
let semantic_subs: Result < _ , Error > = subs. iter ( ) . map ( Liftable :: lift) . collect ( ) ;
192
- Semantic :: Threshold ( 2 , semantic_subs?)
192
+ Abstract :: Threshold ( 2 , semantic_subs?)
193
193
}
194
194
Concrete :: Or ( ref subs) => {
195
195
let semantic_subs: Result < _ , Error > =
196
196
subs. iter ( ) . map ( |( _p, sub) | sub. lift ( ) ) . collect ( ) ;
197
- Semantic :: Threshold ( 1 , semantic_subs?)
197
+ Abstract :: Threshold ( 1 , semantic_subs?)
198
198
}
199
199
Concrete :: Threshold ( k, ref subs) => {
200
200
let semantic_subs: Result < _ , Error > = subs. iter ( ) . map ( Liftable :: lift) . collect ( ) ;
201
- Semantic :: Threshold ( k, semantic_subs?)
201
+ Abstract :: Threshold ( k, semantic_subs?)
202
202
}
203
203
}
204
204
. normalized ( ) ;
205
205
Ok ( ret)
206
206
}
207
207
}
208
208
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 ( ) }
210
210
}
211
211
212
212
#[ cfg( test) ]
@@ -227,7 +227,7 @@ mod tests {
227
227
use crate :: { descriptor:: TapTree , Descriptor , Tap } ;
228
228
229
229
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 > ;
231
231
232
232
fn concrete_policy_rtt ( s : & str ) {
233
233
let conc = ConcretePol :: from_str ( s) . unwrap ( ) ;
@@ -236,7 +236,7 @@ mod tests {
236
236
}
237
237
238
238
fn semantic_policy_rtt ( s : & str ) {
239
- let sem = SemanticPol :: from_str ( s) . unwrap ( ) ;
239
+ let sem = AbstractPol :: from_str ( s) . unwrap ( ) ;
240
240
let output = sem. normalized ( ) . to_string ( ) ;
241
241
assert_eq ! ( s. to_lowercase( ) , output. to_lowercase( ) ) ;
242
242
}
@@ -269,8 +269,8 @@ mod tests {
269
269
270
270
//fuzzer crashes
271
271
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( ) ) ;
274
274
concrete_policy_rtt ( "ripemd160()" ) ;
275
275
}
276
276
@@ -336,17 +336,17 @@ mod tests {
336
336
. parse ( )
337
337
. unwrap ( ) ;
338
338
assert_eq ! (
339
- Semantic :: Threshold (
339
+ Abstract :: Threshold (
340
340
1 ,
341
341
vec![
342
- Semantic :: Threshold (
342
+ Abstract :: Threshold (
343
343
2 ,
344
344
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 ) )
347
347
]
348
348
) ,
349
- Semantic :: Key ( key_b)
349
+ Abstract :: Key ( key_b)
350
350
]
351
351
) ,
352
352
ms_str. lift( ) . unwrap( )
0 commit comments