@@ -526,15 +526,15 @@ pub enum Arith {
526
526
/// Eq
527
527
/// [X] [Y] EQUAL
528
528
Eq ( Expr , Expr ) ,
529
- /// Le
529
+ /// Lt
530
530
/// [X] [Y] LESSTHAN
531
- Le ( Expr , Expr ) ,
531
+ Lt ( Expr , Expr ) ,
532
532
/// Leq
533
533
/// [X] [Y] LESSTHANOREQUAL
534
534
Leq ( Expr , Expr ) ,
535
- /// Ge
535
+ /// Gt
536
536
/// [X] [Y] GREATERTHAN
537
- Ge ( Expr , Expr ) ,
537
+ Gt ( Expr , Expr ) ,
538
538
/// Geq
539
539
/// [X] [Y] GREATERTHANOREQUAL
540
540
Geq ( Expr , Expr ) ,
@@ -545,9 +545,9 @@ impl Arith {
545
545
pub fn depth ( & self ) -> usize {
546
546
match self {
547
547
Arith :: Eq ( x, y)
548
- | Arith :: Le ( x, y)
548
+ | Arith :: Lt ( x, y)
549
549
| Arith :: Leq ( x, y)
550
- | Arith :: Ge ( x, y)
550
+ | Arith :: Gt ( x, y)
551
551
| Arith :: Geq ( x, y) => cmp:: max ( x. depth , y. depth ) ,
552
552
}
553
553
}
@@ -556,9 +556,9 @@ impl Arith {
556
556
pub fn script_size ( & self ) -> usize {
557
557
match self {
558
558
Arith :: Eq ( x, y)
559
- | Arith :: Le ( x, y)
559
+ | Arith :: Lt ( x, y)
560
560
| Arith :: Leq ( x, y)
561
- | Arith :: Ge ( x, y)
561
+ | Arith :: Gt ( x, y)
562
562
| Arith :: Geq ( x, y) => x. script_size + y. script_size + 1 ,
563
563
}
564
564
}
@@ -572,9 +572,9 @@ impl Arith {
572
572
) -> Result < bool , EvalError > {
573
573
let res = match self {
574
574
Arith :: Eq ( x, y) => x. eval ( curr_ind, tx, utxos) ? == y. eval ( curr_ind, tx, utxos) ?,
575
- Arith :: Le ( x, y) => x. eval ( curr_ind, tx, utxos) ? < y. eval ( curr_ind, tx, utxos) ?,
575
+ Arith :: Lt ( x, y) => x. eval ( curr_ind, tx, utxos) ? < y. eval ( curr_ind, tx, utxos) ?,
576
576
Arith :: Leq ( x, y) => x. eval ( curr_ind, tx, utxos) ? <= y. eval ( curr_ind, tx, utxos) ?,
577
- Arith :: Ge ( x, y) => x. eval ( curr_ind, tx, utxos) ? > y. eval ( curr_ind, tx, utxos) ?,
577
+ Arith :: Gt ( x, y) => x. eval ( curr_ind, tx, utxos) ? > y. eval ( curr_ind, tx, utxos) ?,
578
578
Arith :: Geq ( x, y) => x. eval ( curr_ind, tx, utxos) ? >= y. eval ( curr_ind, tx, utxos) ?,
579
579
} ;
580
580
Ok ( res)
@@ -588,7 +588,7 @@ impl Arith {
588
588
let builder = y. push_to_builder ( builder) ;
589
589
builder. push_opcode ( OP_EQUAL )
590
590
}
591
- Arith :: Le ( x, y) => {
591
+ Arith :: Lt ( x, y) => {
592
592
let builder = x. push_to_builder ( builder) ;
593
593
let builder = y. push_to_builder ( builder) ;
594
594
builder. push_opcode ( OP_LESSTHAN64 )
@@ -598,7 +598,7 @@ impl Arith {
598
598
let builder = y. push_to_builder ( builder) ;
599
599
builder. push_opcode ( OP_LESSTHANOREQUAL64 )
600
600
}
601
- Arith :: Ge ( x, y) => {
601
+ Arith :: Gt ( x, y) => {
602
602
let builder = x. push_to_builder ( builder) ;
603
603
let builder = y. push_to_builder ( builder) ;
604
604
builder. push_opcode ( OP_GREATERTHAN64 )
@@ -623,9 +623,9 @@ impl Arith {
623
623
let ( x, pos) = Expr :: from_tokens ( tokens, pos) ?;
624
624
match last_opcode {
625
625
Tk :: Equal => Some ( ( Self :: Eq ( x, y) , pos) ) ,
626
- Tk :: Le64 => Some ( ( Self :: Le ( x, y) , pos) ) ,
626
+ Tk :: Le64 => Some ( ( Self :: Lt ( x, y) , pos) ) ,
627
627
Tk :: Leq64 => Some ( ( Self :: Leq ( x, y) , pos) ) ,
628
- Tk :: Ge64 => Some ( ( Self :: Ge ( x, y) , pos) ) ,
628
+ Tk :: Ge64 => Some ( ( Self :: Gt ( x, y) , pos) ) ,
629
629
Tk :: Geq64 => Some ( ( Self :: Geq ( x, y) , pos) ) ,
630
630
_ => None ,
631
631
}
@@ -770,12 +770,12 @@ impl FromTree for Box<Arith> {
770
770
impl FromTree for Arith {
771
771
fn from_tree ( top : & expression:: Tree < ' _ > ) -> Result < Self , Error > {
772
772
match ( top. name , top. args . len ( ) ) {
773
- // Disambiguiate with num_eq to avoid confusion with asset_eq
774
- ( "num_eq " , 2 ) => expression:: binary ( top, Arith :: Eq ) ,
775
- ( "geq " , 2 ) => expression:: binary ( top, Arith :: Geq ) ,
776
- ( "ge " , 2 ) => expression:: binary ( top, Arith :: Ge ) ,
777
- ( "le " , 2 ) => expression:: binary ( top, Arith :: Le ) ,
778
- ( "leq " , 2 ) => expression:: binary ( top, Arith :: Leq ) ,
773
+ // Disambiguiate with num64_eq to avoid confusion with asset_eq
774
+ ( "num64_eq " , 2 ) => expression:: binary ( top, Arith :: Eq ) ,
775
+ ( "num64_geq " , 2 ) => expression:: binary ( top, Arith :: Geq ) ,
776
+ ( "num64_gt " , 2 ) => expression:: binary ( top, Arith :: Gt ) ,
777
+ ( "num64_lt " , 2 ) => expression:: binary ( top, Arith :: Lt ) ,
778
+ ( "num64_leq " , 2 ) => expression:: binary ( top, Arith :: Leq ) ,
779
779
_ => Err ( Error :: Unexpected ( format ! (
780
780
"{}({} args) while parsing Extension" ,
781
781
top. name,
@@ -788,23 +788,23 @@ impl FromTree for Arith {
788
788
impl fmt:: Display for Arith {
789
789
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
790
790
match & self {
791
- Arith :: Eq ( x, y) => write ! ( f, "num_eq ({},{})" , x, y) ,
792
- Arith :: Leq ( x, y) => write ! ( f, "leq ({},{})" , x, y) ,
793
- Arith :: Le ( x, y) => write ! ( f, "le ({},{})" , x, y) ,
794
- Arith :: Geq ( x, y) => write ! ( f, "geq ({},{})" , x, y) ,
795
- Arith :: Ge ( x, y) => write ! ( f, "ge ({},{})" , x, y) ,
791
+ Arith :: Eq ( x, y) => write ! ( f, "num64_eq ({},{})" , x, y) ,
792
+ Arith :: Leq ( x, y) => write ! ( f, "num64_leq ({},{})" , x, y) ,
793
+ Arith :: Lt ( x, y) => write ! ( f, "num64_lt ({},{})" , x, y) ,
794
+ Arith :: Geq ( x, y) => write ! ( f, "num64_geq ({},{})" , x, y) ,
795
+ Arith :: Gt ( x, y) => write ! ( f, "num64_gt ({},{})" , x, y) ,
796
796
}
797
797
}
798
798
}
799
799
800
800
impl fmt:: Debug for Arith {
801
801
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
802
802
match & self {
803
- Arith :: Eq ( x, y) => write ! ( f, "num_eq ({:?},{:?})" , x, y) ,
804
- Arith :: Leq ( x, y) => write ! ( f, "leq ({:?},{:?})" , x, y) ,
805
- Arith :: Le ( x, y) => write ! ( f, "le ({:?},{:?})" , x, y) ,
806
- Arith :: Geq ( x, y) => write ! ( f, "geq ({:?},{:?})" , x, y) ,
807
- Arith :: Ge ( x, y) => write ! ( f, "ge ({:?},{:?})" , x, y) ,
803
+ Arith :: Eq ( x, y) => write ! ( f, "num64_eq ({:?},{:?})" , x, y) ,
804
+ Arith :: Leq ( x, y) => write ! ( f, "num64_leq ({:?},{:?})" , x, y) ,
805
+ Arith :: Lt ( x, y) => write ! ( f, "num64_lt ({:?},{:?})" , x, y) ,
806
+ Arith :: Geq ( x, y) => write ! ( f, "num64_geq ({:?},{:?})" , x, y) ,
807
+ Arith :: Gt ( x, y) => write ! ( f, "num64_gt ({:?},{:?})" , x, y) ,
808
808
}
809
809
}
810
810
}
@@ -1065,37 +1065,39 @@ mod tests {
1065
1065
#[ test]
1066
1066
fn arith_parse ( ) {
1067
1067
// This does not test the evaluation
1068
- _arith_parse ( "num_eq (8,8)" ) ;
1069
- _arith_parse ( "ge (9223372036854775807,9223372036854775806)" ) ; // 2**63-1
1068
+ _arith_parse ( "num64_eq (8,8)" ) ;
1069
+ _arith_parse ( "num64_gt (9223372036854775807,9223372036854775806)" ) ; // 2**63-1
1070
1070
1071
1071
// negatives and comparisons
1072
- _arith_parse ( "num_eq (-8,-8)" ) ; // negative nums
1073
- _arith_parse ( "ge (-8,-9)" ) ;
1074
- _arith_parse ( "geq (-8,-8)" ) ;
1075
- _arith_parse ( "leq (-8,-7)" ) ;
1076
- _arith_parse ( "le (-8,-7)" ) ;
1072
+ _arith_parse ( "num64_eq (-8,-8)" ) ; // negative nums
1073
+ _arith_parse ( "num64_gt (-8,-9)" ) ;
1074
+ _arith_parse ( "num64_geq (-8,-8)" ) ;
1075
+ _arith_parse ( "num64_leq (-8,-7)" ) ;
1076
+ _arith_parse ( "num64_lt (-8,-7)" ) ;
1077
1077
1078
1078
// test terminals parsing
1079
- _arith_parse ( "num_eq (inp_v(0),100)" ) ;
1080
- _arith_parse ( "num_eq (out_v(0),100)" ) ;
1081
- _arith_parse ( "num_eq (inp_issue_v(0),100)" ) ;
1082
- _arith_parse ( "num_eq (inp_reissue_v(0),100)" ) ;
1083
- _arith_parse ( "num_eq (inp_v(0),out_v(0))" ) ;
1084
- _arith_parse ( "num_eq (inp_issue_v(1),inp_reissue_v(1))" ) ;
1079
+ _arith_parse ( "num64_eq (inp_v(0),100)" ) ;
1080
+ _arith_parse ( "num64_eq (out_v(0),100)" ) ;
1081
+ _arith_parse ( "num64_eq (inp_issue_v(0),100)" ) ;
1082
+ _arith_parse ( "num64_eq (inp_reissue_v(0),100)" ) ;
1083
+ _arith_parse ( "num64_eq (inp_v(0),out_v(0))" ) ;
1084
+ _arith_parse ( "num64_eq (inp_issue_v(1),inp_reissue_v(1))" ) ;
1085
1085
1086
1086
// test combinator
1087
- _arith_parse ( "num_eq (add(4,3),mul(1,7))" ) ;
1088
- _arith_parse ( "num_eq (sub(3,3),div(0,9))" ) ;
1089
- _arith_parse ( "num_eq (mod(9,3),0)" ) ;
1090
- _arith_parse ( "num_eq (bitand(0,134),0)" ) ;
1091
- _arith_parse ( "num_eq (bitor(1,3),3)" ) ;
1092
- _arith_parse ( "num_eq (bitxor(1,3),2)" ) ;
1093
- _arith_parse ( "num_eq (bitinv(0),-9223372036854775808)" ) ;
1094
- _arith_parse ( "num_eq (neg(1),-1)" ) ;
1087
+ _arith_parse ( "num64_eq (add(4,3),mul(1,7))" ) ;
1088
+ _arith_parse ( "num64_eq (sub(3,3),div(0,9))" ) ;
1089
+ _arith_parse ( "num64_eq (mod(9,3),0)" ) ;
1090
+ _arith_parse ( "num64_eq (bitand(0,134),0)" ) ;
1091
+ _arith_parse ( "num64_eq (bitor(1,3),3)" ) ;
1092
+ _arith_parse ( "num64_eq (bitxor(1,3),2)" ) ;
1093
+ _arith_parse ( "num64_eq (bitinv(0),-9223372036854775808)" ) ;
1094
+ _arith_parse ( "num64_eq (neg(1),-1)" ) ;
1095
1095
1096
1096
// test some misc combinations with other miniscript fragments
1097
- _arith_parse ( "and_v(v:pk(K),ge(8,7))" ) ;
1098
- _arith_parse ( "and_v(v:pk(K),num_eq(mul(inp_v(0),out_v(1)),sub(add(3,inp_issue_v(1)),-9)))" ) ;
1097
+ _arith_parse ( "and_v(v:pk(K),num64_gt(8,7))" ) ;
1098
+ _arith_parse (
1099
+ "and_v(v:pk(K),num64_eq(mul(inp_v(0),out_v(1)),sub(add(3,inp_issue_v(1)),-9)))" ,
1100
+ ) ;
1099
1101
}
1100
1102
1101
1103
fn _arith_parse ( s : & str ) {
0 commit comments