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