11use bls12_381:: { G1Affine , G1Projective , Scalar } ;
2- use num_bigint:: { BigUint , Sign } ;
3- use num_integer:: Integer ;
4- use std:: convert:: TryFrom ;
52use std:: ops:: BitAndAssign ;
63use std:: ops:: BitOrAssign ;
74use std:: ops:: BitXorAssign ;
@@ -12,7 +9,7 @@ use crate::allocator::{Allocator, NodePtr, SExp};
129use crate :: cost:: { check_cost, Cost } ;
1310use crate :: err_utils:: err;
1411use crate :: node:: Node ;
15- use crate :: number:: { number_from_u8, ptr_from_number, Number } ;
12+ use crate :: number:: { number_from_u8, ptr_from_number, Number , Sign } ;
1613use crate :: op_utils:: {
1714 arg_count, atom, check_arg_count, i32_atom, int_atom, two_ints, u32_from_u8,
1815} ;
@@ -354,7 +351,7 @@ pub fn op_sha256(a: &mut Allocator, input: NodePtr, max_cost: Cost) -> Response
354351pub fn op_add ( a : & mut Allocator , input : NodePtr , max_cost : Cost ) -> Response {
355352 let mut cost = ARITH_BASE_COST ;
356353 let mut byte_count: usize = 0 ;
357- let mut total: Number = 0 . into ( ) ;
354+ let mut total = Number :: zero ( ) ;
358355 for arg in Node :: new ( a, input) {
359356 cost += ARITH_COST_PER_ARG ;
360357 check_cost (
@@ -365,7 +362,7 @@ pub fn op_add(a: &mut Allocator, input: NodePtr, max_cost: Cost) -> Response {
365362 let blob = int_atom ( & arg, "+" ) ?;
366363 let v: Number = number_from_u8 ( blob) ;
367364 byte_count += blob. len ( ) ;
368- total += v;
365+ total += & v;
369366 }
370367 let total = ptr_from_number ( a, & total) ?;
371368 cost += byte_count as Cost * ARITH_COST_PER_BYTE ;
@@ -375,7 +372,7 @@ pub fn op_add(a: &mut Allocator, input: NodePtr, max_cost: Cost) -> Response {
375372pub fn op_subtract ( a : & mut Allocator , input : NodePtr , max_cost : Cost ) -> Response {
376373 let mut cost = ARITH_BASE_COST ;
377374 let mut byte_count: usize = 0 ;
378- let mut total: Number = 0 . into ( ) ;
375+ let mut total = Number :: zero ( ) ;
379376 let mut is_first = true ;
380377 for arg in Node :: new ( a, input) {
381378 cost += ARITH_COST_PER_ARG ;
@@ -384,9 +381,9 @@ pub fn op_subtract(a: &mut Allocator, input: NodePtr, max_cost: Cost) -> Respons
384381 let v: Number = number_from_u8 ( blob) ;
385382 byte_count += blob. len ( ) ;
386383 if is_first {
387- total += v;
384+ total += & v;
388385 } else {
389- total -= v;
386+ total -= & v;
390387 } ;
391388 is_first = false ;
392389 }
@@ -434,7 +431,7 @@ pub fn op_div(a: &mut Allocator, input: NodePtr, _max_cost: Cost) -> Response {
434431
435432 // this is to preserve a buggy behavior from the initial implementation
436433 // of this operator.
437- if q == ( - 1 ) . into ( ) && r != 0 . into ( ) {
434+ if q == - 1 && r != 0 {
438435 q += 1 ;
439436 }
440437 let q1 = ptr_from_number ( a, & q) ?;
@@ -641,16 +638,14 @@ pub fn op_lsh(a: &mut Allocator, input: NodePtr, _max_cost: Cost) -> Response {
641638 check_arg_count ( & args, 2 , "lsh" ) ?;
642639 let a0 = args. first ( ) ?;
643640 let b0 = int_atom ( & a0, "lsh" ) ?;
644- let i0 = BigUint :: from_bytes_be ( b0) ;
641+ let i0 = Number :: from_unsigned_bytes_be ( b0) ;
645642 let l0 = b0. len ( ) ;
646643 let rest = args. rest ( ) ?;
647644 let a1 = i32_atom ( & rest. first ( ) ?, "lsh" ) ?;
648645 if a1 > 65535 || a1 < -65535 {
649646 return args. rest ( ) ?. first ( ) ?. err ( "shift too large" ) ;
650647 }
651648
652- let i0: Number = i0. into ( ) ;
653-
654649 let v: Number = if a1 > 0 { i0 << a1 } else { i0 >> -a1 } ;
655650
656651 let l1 = limbs_for_int ( & v) ;
@@ -739,7 +734,7 @@ fn logior_op(a: &mut Number, b: &Number) {
739734}
740735
741736pub fn op_logior ( a : & mut Allocator , input : NodePtr , max_cost : Cost ) -> Response {
742- let v: Number = ( 0 ) . into ( ) ;
737+ let v = Number :: zero ( ) ;
743738 binop_reduction ( "logior" , a, v, input, max_cost, logior_op)
744739}
745740
@@ -748,7 +743,7 @@ fn logxor_op(a: &mut Number, b: &Number) {
748743}
749744
750745pub fn op_logxor ( a : & mut Allocator , input : NodePtr , max_cost : Cost ) -> Response {
751- let v: Number = ( 0 ) . into ( ) ;
746+ let v = Number :: zero ( ) ;
752747 binop_reduction ( "logxor" , a, v, input, max_cost, logxor_op)
753748}
754749
@@ -804,10 +799,10 @@ pub fn op_softfork(a: &mut Allocator, input: NodePtr, max_cost: Cost) -> Respons
804799 Some ( ( p1, _) ) => {
805800 let n: Number = number_from_u8 ( int_atom ( & p1, "softfork" ) ?) ;
806801 if n. sign ( ) == Sign :: Plus {
807- if n > Number :: from ( max_cost) {
802+ if n > max_cost {
808803 return err ( a. null ( ) , "cost exceeded" ) ;
809804 }
810- let cost: Cost = TryFrom :: try_from ( & n ) . unwrap ( ) ;
805+ let cost: Cost = n . into ( ) ;
811806 Ok ( Reduction ( cost, args. null ( ) . node ) )
812807 } else {
813808 args. err ( "cost must be > 0" )
@@ -824,14 +819,13 @@ lazy_static! {
824819 0xd8 , 0x05 , 0x53 , 0xbd , 0xa4 , 0x02 , 0xff , 0xfe , 0x5b , 0xfe , 0xff , 0xff , 0xff , 0xff ,
825820 0x00 , 0x00 , 0x00 , 0x01 ,
826821 ] ;
827- let n = BigUint :: from_bytes_be( order_as_bytes) ;
828- n. into( )
822+ Number :: from_unsigned_bytes_be( order_as_bytes)
829823 } ;
830824}
831825
832826fn mod_group_order ( n : Number ) -> Number {
833- let order = GROUP_ORDER . clone ( ) ;
834- let mut remainder = n. mod_floor ( & order) ;
827+ let order: & Number = & GROUP_ORDER ;
828+ let mut remainder = n. mod_floor ( order) ;
835829 if remainder. sign ( ) == Sign :: Minus {
836830 remainder += order;
837831 }
0 commit comments