snarkvm_circuit_program/data/literal/cast_lossy/
integer.rs

1// Copyright (c) 2019-2025 Provable Inc.
2// This file is part of the snarkVM library.
3
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at:
7
8// http://www.apache.org/licenses/LICENSE-2.0
9
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16use super::*;
17
18impl<E: Environment, I: IntegerType> CastLossy<Address<E>> for Integer<E, I> {
19    /// Casts an `Integer` to an `Address`.
20    ///
21    /// This operation converts the integer into a field element, and then attempts to recover
22    /// the group element to construct the address. See the documentation of `Field::cast_lossy`
23    /// on the `Group` type for more details.
24    #[inline]
25    fn cast_lossy(&self) -> Address<E> {
26        let field: Field<E> = self.cast_lossy();
27        field.cast_lossy()
28    }
29}
30
31impl<E: Environment, I: IntegerType> CastLossy<Boolean<E>> for Integer<E, I> {
32    /// Casts an `Integer` to a `Boolean`, with lossy truncation.
33    /// This operation returns the least significant bit of the field.
34    #[inline]
35    fn cast_lossy(&self) -> Boolean<E> {
36        let bits_le = self.to_bits_le();
37        debug_assert!(!bits_le.is_empty(), "An integer must have at least one bit");
38        bits_le[0].clone()
39    }
40}
41
42impl<E: Environment, I: IntegerType> CastLossy<Field<E>> for Integer<E, I> {
43    /// Casts an `Integer` to a `Field`.
44    /// This is safe because casting from an integer to a field is **always** lossless.
45    #[inline]
46    fn cast_lossy(&self) -> Field<E> {
47        self.to_field()
48    }
49}
50
51impl<E: Environment, I: IntegerType> CastLossy<Group<E>> for Integer<E, I> {
52    /// Casts an `Integer` to a `Group`.
53    ///
54    /// This operation converts the integer into a field element, and then attempts to recover
55    /// the group element. See the documentation of `Field::cast_lossy` on the `Group` type
56    /// for more details.
57    #[inline]
58    fn cast_lossy(&self) -> Group<E> {
59        let field: Field<E> = self.cast_lossy();
60        field.cast_lossy()
61    }
62}
63
64impl<E: Environment, I0: IntegerType, I1: IntegerType> CastLossy<Integer<E, I1>> for Integer<E, I0> {
65    /// Casts an `Integer` to an `Integer` of a different type, with lossy truncation.
66    fn cast_lossy(&self) -> Integer<E, I1> {
67        let mut bits_le = self.to_bits_le();
68        // If the source type is smaller than the destination type, then perform the appropriate extension.
69        let padding = match I0::is_signed() {
70            // If the source type is signed, then sign extend.
71            true => self.msb().clone(),
72            // Otherwise, zero extend.
73            false => Boolean::constant(false),
74        };
75        bits_le.resize(I1::BITS as usize, padding);
76        // Construct the integer from the bits.
77        Integer::from_bits_le(&bits_le)
78    }
79}
80
81impl<E: Environment, I: IntegerType> CastLossy<Scalar<E>> for Integer<E, I> {
82    /// Casts an `Integer` to a `Scalar`.
83    /// This is safe because casting from an integer to a scalar is **always** lossless.
84    #[inline]
85    fn cast_lossy(&self) -> Scalar<E> {
86        self.to_scalar()
87    }
88}
89
90#[cfg(test)]
91mod tests {
92    use super::*;
93    use console::CastLossy as _;
94    use console_root::{
95        network::MainnetV0,
96        prelude::{One, TestRng, Uniform, Zero},
97    };
98    use snarkvm_circuit_types::environment::{Circuit, Eject, Inject, Mode, UpdatableCount, count_is, count_less_than};
99
100    use std::fmt::Debug;
101
102    const ITERATIONS: usize = 100;
103
104    fn sample_values<I: IntegerType>(
105        i: usize,
106        mode: Mode,
107        rng: &mut TestRng,
108    ) -> (console_root::types::integers::Integer<MainnetV0, I>, Integer<Circuit, I>) {
109        let console_value = match i {
110            0 => console_root::types::integers::Integer::<MainnetV0, I>::zero(),
111            1 => console_root::types::integers::Integer::<MainnetV0, I>::one(),
112            2 => console_root::types::integers::Integer::<MainnetV0, I>::new(I::MAX),
113            3 => console_root::types::integers::Integer::<MainnetV0, I>::new(I::MIN),
114            4 if I::is_signed() => -console_root::types::integers::Integer::<MainnetV0, I>::one(),
115            _ => Uniform::rand(rng),
116        };
117        let circuit_value = Integer::<Circuit, I>::new(mode, console_value);
118        (console_value, circuit_value)
119    }
120
121    mod i8 {
122        use super::*;
123
124        fn sample_values(i: usize, mode: Mode, rng: &mut TestRng) -> (console_root::types::I8<MainnetV0>, I8<Circuit>) {
125            super::sample_values(i, mode, rng)
126        }
127
128        check_cast_lossy!(cast_lossy, I8<Circuit>, console_root::types::I8<MainnetV0>);
129
130        #[test]
131        fn test_i8_to_address() {
132            check_cast_lossy::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
133                Mode::Constant,
134                count_less_than!(4303, 0, 0, 0),
135            );
136            check_cast_lossy::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
137                Mode::Public,
138                count_is!(2029, 0, 6745, 6750),
139            );
140            check_cast_lossy::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
141                Mode::Private,
142                count_is!(2029, 0, 6745, 6750),
143            );
144        }
145
146        #[test]
147        fn test_i8_to_boolean() {
148            check_cast_lossy::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
149                Mode::Constant,
150                count_is!(0, 0, 0, 0),
151            );
152            check_cast_lossy::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
153                Mode::Public,
154                count_is!(0, 0, 0, 0),
155            );
156            check_cast_lossy::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
157                Mode::Private,
158                count_is!(0, 0, 0, 0),
159            );
160        }
161
162        #[test]
163        fn test_i8_to_field() {
164            check_cast_lossy::<Field<Circuit>, console_root::types::Field<MainnetV0>>(
165                Mode::Constant,
166                count_is!(0, 0, 0, 0),
167            );
168            check_cast_lossy::<Field<Circuit>, console_root::types::Field<MainnetV0>>(
169                Mode::Public,
170                count_is!(0, 0, 0, 0),
171            );
172            check_cast_lossy::<Field<Circuit>, console_root::types::Field<MainnetV0>>(
173                Mode::Private,
174                count_is!(0, 0, 0, 0),
175            );
176        }
177
178        #[test]
179        fn test_i8_to_group() {
180            check_cast_lossy::<Group<Circuit>, console_root::types::Group<MainnetV0>>(
181                Mode::Constant,
182                count_less_than!(4303, 0, 0, 0),
183            );
184            check_cast_lossy::<Group<Circuit>, console_root::types::Group<MainnetV0>>(
185                Mode::Public,
186                count_is!(2029, 0, 6745, 6750),
187            );
188            check_cast_lossy::<Group<Circuit>, console_root::types::Group<MainnetV0>>(
189                Mode::Private,
190                count_is!(2029, 0, 6745, 6750),
191            );
192        }
193
194        #[test]
195        fn test_i8_to_i8() {
196            check_cast_lossy::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
197            check_cast_lossy::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
198            check_cast_lossy::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
199        }
200
201        #[test]
202        fn test_i8_to_i16() {
203            check_cast_lossy::<I16<Circuit>, console_root::types::I16<MainnetV0>>(
204                Mode::Constant,
205                count_is!(0, 0, 0, 0),
206            );
207            check_cast_lossy::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
208            check_cast_lossy::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
209        }
210
211        #[test]
212        fn test_i8_to_i32() {
213            check_cast_lossy::<I32<Circuit>, console_root::types::I32<MainnetV0>>(
214                Mode::Constant,
215                count_is!(0, 0, 0, 0),
216            );
217            check_cast_lossy::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
218            check_cast_lossy::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
219        }
220
221        #[test]
222        fn test_i8_to_i64() {
223            check_cast_lossy::<I64<Circuit>, console_root::types::I64<MainnetV0>>(
224                Mode::Constant,
225                count_is!(0, 0, 0, 0),
226            );
227            check_cast_lossy::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
228            check_cast_lossy::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
229        }
230
231        #[test]
232        fn test_i8_to_i128() {
233            check_cast_lossy::<I128<Circuit>, console_root::types::I128<MainnetV0>>(
234                Mode::Constant,
235                count_is!(0, 0, 0, 0),
236            );
237            check_cast_lossy::<I128<Circuit>, console_root::types::I128<MainnetV0>>(
238                Mode::Public,
239                count_is!(0, 0, 0, 0),
240            );
241            check_cast_lossy::<I128<Circuit>, console_root::types::I128<MainnetV0>>(
242                Mode::Private,
243                count_is!(0, 0, 0, 0),
244            );
245        }
246
247        #[test]
248        fn test_i8_to_scalar() {
249            check_cast_lossy::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(
250                Mode::Constant,
251                count_is!(0, 0, 0, 0),
252            );
253            check_cast_lossy::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(
254                Mode::Public,
255                count_is!(0, 0, 0, 0),
256            );
257            check_cast_lossy::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(
258                Mode::Private,
259                count_is!(0, 0, 0, 0),
260            );
261        }
262
263        #[test]
264        fn test_i8_to_u8() {
265            check_cast_lossy::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
266            check_cast_lossy::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
267            check_cast_lossy::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
268        }
269
270        #[test]
271        fn test_i8_to_u16() {
272            check_cast_lossy::<U16<Circuit>, console_root::types::U16<MainnetV0>>(
273                Mode::Constant,
274                count_is!(0, 0, 0, 0),
275            );
276            check_cast_lossy::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
277            check_cast_lossy::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
278        }
279
280        #[test]
281        fn test_i8_to_u32() {
282            check_cast_lossy::<U32<Circuit>, console_root::types::U32<MainnetV0>>(
283                Mode::Constant,
284                count_is!(0, 0, 0, 0),
285            );
286            check_cast_lossy::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
287            check_cast_lossy::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
288        }
289
290        #[test]
291        fn test_i8_to_u64() {
292            check_cast_lossy::<U64<Circuit>, console_root::types::U64<MainnetV0>>(
293                Mode::Constant,
294                count_is!(0, 0, 0, 0),
295            );
296            check_cast_lossy::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
297            check_cast_lossy::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
298        }
299
300        #[test]
301        fn test_i8_to_u128() {
302            check_cast_lossy::<U128<Circuit>, console_root::types::U128<MainnetV0>>(
303                Mode::Constant,
304                count_is!(0, 0, 0, 0),
305            );
306            check_cast_lossy::<U128<Circuit>, console_root::types::U128<MainnetV0>>(
307                Mode::Public,
308                count_is!(0, 0, 0, 0),
309            );
310            check_cast_lossy::<U128<Circuit>, console_root::types::U128<MainnetV0>>(
311                Mode::Private,
312                count_is!(0, 0, 0, 0),
313            );
314        }
315    }
316
317    mod i16 {
318        use super::*;
319
320        fn sample_values(
321            i: usize,
322            mode: Mode,
323            rng: &mut TestRng,
324        ) -> (console_root::types::I16<MainnetV0>, I16<Circuit>) {
325            super::sample_values(i, mode, rng)
326        }
327
328        check_cast_lossy!(cast_lossy, I16<Circuit>, console_root::types::I16<MainnetV0>);
329
330        #[test]
331        fn test_i16_to_address() {
332            check_cast_lossy::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
333                Mode::Constant,
334                count_less_than!(4303, 0, 0, 0),
335            );
336            check_cast_lossy::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
337                Mode::Public,
338                count_is!(2029, 0, 6745, 6750),
339            );
340            check_cast_lossy::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
341                Mode::Private,
342                count_is!(2029, 0, 6745, 6750),
343            );
344        }
345
346        #[test]
347        fn test_i16_to_boolean() {
348            check_cast_lossy::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
349                Mode::Constant,
350                count_is!(0, 0, 0, 0),
351            );
352            check_cast_lossy::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
353                Mode::Public,
354                count_is!(0, 0, 0, 0),
355            );
356            check_cast_lossy::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
357                Mode::Private,
358                count_is!(0, 0, 0, 0),
359            );
360        }
361
362        #[test]
363        fn test_i16_to_field() {
364            check_cast_lossy::<Field<Circuit>, console_root::types::Field<MainnetV0>>(
365                Mode::Constant,
366                count_is!(0, 0, 0, 0),
367            );
368            check_cast_lossy::<Field<Circuit>, console_root::types::Field<MainnetV0>>(
369                Mode::Public,
370                count_is!(0, 0, 0, 0),
371            );
372            check_cast_lossy::<Field<Circuit>, console_root::types::Field<MainnetV0>>(
373                Mode::Private,
374                count_is!(0, 0, 0, 0),
375            );
376        }
377
378        #[test]
379        fn test_i16_to_group() {
380            check_cast_lossy::<Group<Circuit>, console_root::types::Group<MainnetV0>>(
381                Mode::Constant,
382                count_less_than!(4303, 0, 0, 0),
383            );
384            check_cast_lossy::<Group<Circuit>, console_root::types::Group<MainnetV0>>(
385                Mode::Public,
386                count_is!(2029, 0, 6745, 6750),
387            );
388            check_cast_lossy::<Group<Circuit>, console_root::types::Group<MainnetV0>>(
389                Mode::Private,
390                count_is!(2029, 0, 6745, 6750),
391            );
392        }
393
394        #[test]
395        fn test_i16_to_i8() {
396            check_cast_lossy::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
397            check_cast_lossy::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
398            check_cast_lossy::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
399        }
400
401        #[test]
402        fn test_i16_to_i16() {
403            check_cast_lossy::<I16<Circuit>, console_root::types::I16<MainnetV0>>(
404                Mode::Constant,
405                count_is!(0, 0, 0, 0),
406            );
407            check_cast_lossy::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
408            check_cast_lossy::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
409        }
410
411        #[test]
412        fn test_i16_to_i32() {
413            check_cast_lossy::<I32<Circuit>, console_root::types::I32<MainnetV0>>(
414                Mode::Constant,
415                count_is!(0, 0, 0, 0),
416            );
417            check_cast_lossy::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
418            check_cast_lossy::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
419        }
420
421        #[test]
422        fn test_i16_to_i64() {
423            check_cast_lossy::<I64<Circuit>, console_root::types::I64<MainnetV0>>(
424                Mode::Constant,
425                count_is!(0, 0, 0, 0),
426            );
427            check_cast_lossy::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
428            check_cast_lossy::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
429        }
430
431        #[test]
432        fn test_i16_to_i128() {
433            check_cast_lossy::<I128<Circuit>, console_root::types::I128<MainnetV0>>(
434                Mode::Constant,
435                count_is!(0, 0, 0, 0),
436            );
437            check_cast_lossy::<I128<Circuit>, console_root::types::I128<MainnetV0>>(
438                Mode::Public,
439                count_is!(0, 0, 0, 0),
440            );
441            check_cast_lossy::<I128<Circuit>, console_root::types::I128<MainnetV0>>(
442                Mode::Private,
443                count_is!(0, 0, 0, 0),
444            );
445        }
446
447        #[test]
448        fn test_i16_to_scalar() {
449            check_cast_lossy::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(
450                Mode::Constant,
451                count_is!(0, 0, 0, 0),
452            );
453            check_cast_lossy::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(
454                Mode::Public,
455                count_is!(0, 0, 0, 0),
456            );
457            check_cast_lossy::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(
458                Mode::Private,
459                count_is!(0, 0, 0, 0),
460            );
461        }
462
463        #[test]
464        fn test_i16_to_u8() {
465            check_cast_lossy::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
466            check_cast_lossy::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
467            check_cast_lossy::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
468        }
469
470        #[test]
471        fn test_i16_to_u16() {
472            check_cast_lossy::<U16<Circuit>, console_root::types::U16<MainnetV0>>(
473                Mode::Constant,
474                count_is!(0, 0, 0, 0),
475            );
476            check_cast_lossy::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
477            check_cast_lossy::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
478        }
479
480        #[test]
481        fn test_i16_to_u32() {
482            check_cast_lossy::<U32<Circuit>, console_root::types::U32<MainnetV0>>(
483                Mode::Constant,
484                count_is!(0, 0, 0, 0),
485            );
486            check_cast_lossy::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
487            check_cast_lossy::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
488        }
489
490        #[test]
491        fn test_i16_to_u64() {
492            check_cast_lossy::<U64<Circuit>, console_root::types::U64<MainnetV0>>(
493                Mode::Constant,
494                count_is!(0, 0, 0, 0),
495            );
496            check_cast_lossy::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
497            check_cast_lossy::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
498        }
499
500        #[test]
501        fn test_i16_to_u128() {
502            check_cast_lossy::<U128<Circuit>, console_root::types::U128<MainnetV0>>(
503                Mode::Constant,
504                count_is!(0, 0, 0, 0),
505            );
506            check_cast_lossy::<U128<Circuit>, console_root::types::U128<MainnetV0>>(
507                Mode::Public,
508                count_is!(0, 0, 0, 0),
509            );
510            check_cast_lossy::<U128<Circuit>, console_root::types::U128<MainnetV0>>(
511                Mode::Private,
512                count_is!(0, 0, 0, 0),
513            );
514        }
515    }
516
517    mod i32 {
518        use super::*;
519
520        fn sample_values(
521            i: usize,
522            mode: Mode,
523            rng: &mut TestRng,
524        ) -> (console_root::types::I32<MainnetV0>, I32<Circuit>) {
525            super::sample_values(i, mode, rng)
526        }
527
528        check_cast_lossy!(cast_lossy, I32<Circuit>, console_root::types::I32<MainnetV0>);
529
530        #[test]
531        fn test_i32_to_address() {
532            check_cast_lossy::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
533                Mode::Constant,
534                count_less_than!(4303, 0, 0, 0),
535            );
536            check_cast_lossy::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
537                Mode::Public,
538                count_is!(2029, 0, 6745, 6750),
539            );
540            check_cast_lossy::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
541                Mode::Private,
542                count_is!(2029, 0, 6745, 6750),
543            );
544        }
545
546        #[test]
547        fn test_i32_to_boolean() {
548            check_cast_lossy::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
549                Mode::Constant,
550                count_is!(0, 0, 0, 0),
551            );
552            check_cast_lossy::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
553                Mode::Public,
554                count_is!(0, 0, 0, 0),
555            );
556            check_cast_lossy::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
557                Mode::Private,
558                count_is!(0, 0, 0, 0),
559            );
560        }
561
562        #[test]
563        fn test_i32_to_field() {
564            check_cast_lossy::<Field<Circuit>, console_root::types::Field<MainnetV0>>(
565                Mode::Constant,
566                count_is!(0, 0, 0, 0),
567            );
568            check_cast_lossy::<Field<Circuit>, console_root::types::Field<MainnetV0>>(
569                Mode::Public,
570                count_is!(0, 0, 0, 0),
571            );
572            check_cast_lossy::<Field<Circuit>, console_root::types::Field<MainnetV0>>(
573                Mode::Private,
574                count_is!(0, 0, 0, 0),
575            );
576        }
577
578        #[test]
579        fn test_i32_to_group() {
580            check_cast_lossy::<Group<Circuit>, console_root::types::Group<MainnetV0>>(
581                Mode::Constant,
582                count_less_than!(4303, 0, 0, 0),
583            );
584            check_cast_lossy::<Group<Circuit>, console_root::types::Group<MainnetV0>>(
585                Mode::Public,
586                count_is!(2029, 0, 6745, 6750),
587            );
588            check_cast_lossy::<Group<Circuit>, console_root::types::Group<MainnetV0>>(
589                Mode::Private,
590                count_is!(2029, 0, 6745, 6750),
591            );
592        }
593
594        #[test]
595        fn test_i32_to_i8() {
596            check_cast_lossy::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
597            check_cast_lossy::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
598            check_cast_lossy::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
599        }
600
601        #[test]
602        fn test_i32_to_i16() {
603            check_cast_lossy::<I16<Circuit>, console_root::types::I16<MainnetV0>>(
604                Mode::Constant,
605                count_is!(0, 0, 0, 0),
606            );
607            check_cast_lossy::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
608            check_cast_lossy::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
609        }
610
611        #[test]
612        fn test_i32_to_i32() {
613            check_cast_lossy::<I32<Circuit>, console_root::types::I32<MainnetV0>>(
614                Mode::Constant,
615                count_is!(0, 0, 0, 0),
616            );
617            check_cast_lossy::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
618            check_cast_lossy::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
619        }
620
621        #[test]
622        fn test_i32_to_i64() {
623            check_cast_lossy::<I64<Circuit>, console_root::types::I64<MainnetV0>>(
624                Mode::Constant,
625                count_is!(0, 0, 0, 0),
626            );
627            check_cast_lossy::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
628            check_cast_lossy::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
629        }
630
631        #[test]
632        fn test_i32_to_i128() {
633            check_cast_lossy::<I128<Circuit>, console_root::types::I128<MainnetV0>>(
634                Mode::Constant,
635                count_is!(0, 0, 0, 0),
636            );
637            check_cast_lossy::<I128<Circuit>, console_root::types::I128<MainnetV0>>(
638                Mode::Public,
639                count_is!(0, 0, 0, 0),
640            );
641            check_cast_lossy::<I128<Circuit>, console_root::types::I128<MainnetV0>>(
642                Mode::Private,
643                count_is!(0, 0, 0, 0),
644            );
645        }
646
647        #[test]
648        fn test_i32_to_scalar() {
649            check_cast_lossy::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(
650                Mode::Constant,
651                count_is!(0, 0, 0, 0),
652            );
653            check_cast_lossy::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(
654                Mode::Public,
655                count_is!(0, 0, 0, 0),
656            );
657            check_cast_lossy::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(
658                Mode::Private,
659                count_is!(0, 0, 0, 0),
660            );
661        }
662
663        #[test]
664        fn test_i32_to_u8() {
665            check_cast_lossy::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
666            check_cast_lossy::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
667            check_cast_lossy::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
668        }
669
670        #[test]
671        fn test_i32_to_u16() {
672            check_cast_lossy::<U16<Circuit>, console_root::types::U16<MainnetV0>>(
673                Mode::Constant,
674                count_is!(0, 0, 0, 0),
675            );
676            check_cast_lossy::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
677            check_cast_lossy::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
678        }
679
680        #[test]
681        fn test_i32_to_u32() {
682            check_cast_lossy::<U32<Circuit>, console_root::types::U32<MainnetV0>>(
683                Mode::Constant,
684                count_is!(0, 0, 0, 0),
685            );
686            check_cast_lossy::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
687            check_cast_lossy::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
688        }
689
690        #[test]
691        fn test_i32_to_u64() {
692            check_cast_lossy::<U64<Circuit>, console_root::types::U64<MainnetV0>>(
693                Mode::Constant,
694                count_is!(0, 0, 0, 0),
695            );
696            check_cast_lossy::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
697            check_cast_lossy::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
698        }
699
700        #[test]
701        fn test_i32_to_u128() {
702            check_cast_lossy::<U128<Circuit>, console_root::types::U128<MainnetV0>>(
703                Mode::Constant,
704                count_is!(0, 0, 0, 0),
705            );
706            check_cast_lossy::<U128<Circuit>, console_root::types::U128<MainnetV0>>(
707                Mode::Public,
708                count_is!(0, 0, 0, 0),
709            );
710            check_cast_lossy::<U128<Circuit>, console_root::types::U128<MainnetV0>>(
711                Mode::Private,
712                count_is!(0, 0, 0, 0),
713            );
714        }
715    }
716
717    mod i64 {
718        use super::*;
719
720        fn sample_values(
721            i: usize,
722            mode: Mode,
723            rng: &mut TestRng,
724        ) -> (console_root::types::I64<MainnetV0>, I64<Circuit>) {
725            super::sample_values(i, mode, rng)
726        }
727
728        check_cast_lossy!(cast_lossy, I64<Circuit>, console_root::types::I64<MainnetV0>);
729
730        #[test]
731        fn test_i64_to_address() {
732            check_cast_lossy::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
733                Mode::Constant,
734                count_less_than!(4303, 0, 0, 0),
735            );
736            check_cast_lossy::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
737                Mode::Public,
738                count_is!(2029, 0, 6745, 6750),
739            );
740            check_cast_lossy::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
741                Mode::Private,
742                count_is!(2029, 0, 6745, 6750),
743            );
744        }
745
746        #[test]
747        fn test_i64_to_boolean() {
748            check_cast_lossy::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
749                Mode::Constant,
750                count_is!(0, 0, 0, 0),
751            );
752            check_cast_lossy::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
753                Mode::Public,
754                count_is!(0, 0, 0, 0),
755            );
756            check_cast_lossy::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
757                Mode::Private,
758                count_is!(0, 0, 0, 0),
759            );
760        }
761
762        #[test]
763        fn test_i64_to_field() {
764            check_cast_lossy::<Field<Circuit>, console_root::types::Field<MainnetV0>>(
765                Mode::Constant,
766                count_is!(0, 0, 0, 0),
767            );
768            check_cast_lossy::<Field<Circuit>, console_root::types::Field<MainnetV0>>(
769                Mode::Public,
770                count_is!(0, 0, 0, 0),
771            );
772            check_cast_lossy::<Field<Circuit>, console_root::types::Field<MainnetV0>>(
773                Mode::Private,
774                count_is!(0, 0, 0, 0),
775            );
776        }
777
778        #[test]
779        fn test_i64_to_group() {
780            check_cast_lossy::<Group<Circuit>, console_root::types::Group<MainnetV0>>(
781                Mode::Constant,
782                count_less_than!(4303, 0, 0, 0),
783            );
784            check_cast_lossy::<Group<Circuit>, console_root::types::Group<MainnetV0>>(
785                Mode::Public,
786                count_is!(2029, 0, 6745, 6750),
787            );
788            check_cast_lossy::<Group<Circuit>, console_root::types::Group<MainnetV0>>(
789                Mode::Private,
790                count_is!(2029, 0, 6745, 6750),
791            );
792        }
793
794        #[test]
795        fn test_i64_to_i8() {
796            check_cast_lossy::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
797            check_cast_lossy::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
798            check_cast_lossy::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
799        }
800
801        #[test]
802        fn test_i64_to_i16() {
803            check_cast_lossy::<I16<Circuit>, console_root::types::I16<MainnetV0>>(
804                Mode::Constant,
805                count_is!(0, 0, 0, 0),
806            );
807            check_cast_lossy::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
808            check_cast_lossy::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
809        }
810
811        #[test]
812        fn test_i64_to_i32() {
813            check_cast_lossy::<I32<Circuit>, console_root::types::I32<MainnetV0>>(
814                Mode::Constant,
815                count_is!(0, 0, 0, 0),
816            );
817            check_cast_lossy::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
818            check_cast_lossy::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
819        }
820
821        #[test]
822        fn test_i64_to_i64() {
823            check_cast_lossy::<I64<Circuit>, console_root::types::I64<MainnetV0>>(
824                Mode::Constant,
825                count_is!(0, 0, 0, 0),
826            );
827            check_cast_lossy::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
828            check_cast_lossy::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
829        }
830
831        #[test]
832        fn test_i64_to_i128() {
833            check_cast_lossy::<I128<Circuit>, console_root::types::I128<MainnetV0>>(
834                Mode::Constant,
835                count_is!(0, 0, 0, 0),
836            );
837            check_cast_lossy::<I128<Circuit>, console_root::types::I128<MainnetV0>>(
838                Mode::Public,
839                count_is!(0, 0, 0, 0),
840            );
841            check_cast_lossy::<I128<Circuit>, console_root::types::I128<MainnetV0>>(
842                Mode::Private,
843                count_is!(0, 0, 0, 0),
844            );
845        }
846
847        #[test]
848        fn test_i64_to_scalar() {
849            check_cast_lossy::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(
850                Mode::Constant,
851                count_is!(0, 0, 0, 0),
852            );
853            check_cast_lossy::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(
854                Mode::Public,
855                count_is!(0, 0, 0, 0),
856            );
857            check_cast_lossy::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(
858                Mode::Private,
859                count_is!(0, 0, 0, 0),
860            );
861        }
862
863        #[test]
864        fn test_i64_to_u8() {
865            check_cast_lossy::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
866            check_cast_lossy::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
867            check_cast_lossy::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
868        }
869
870        #[test]
871        fn test_i64_to_u16() {
872            check_cast_lossy::<U16<Circuit>, console_root::types::U16<MainnetV0>>(
873                Mode::Constant,
874                count_is!(0, 0, 0, 0),
875            );
876            check_cast_lossy::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
877            check_cast_lossy::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
878        }
879
880        #[test]
881        fn test_i64_to_u32() {
882            check_cast_lossy::<U32<Circuit>, console_root::types::U32<MainnetV0>>(
883                Mode::Constant,
884                count_is!(0, 0, 0, 0),
885            );
886            check_cast_lossy::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
887            check_cast_lossy::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
888        }
889
890        #[test]
891        fn test_i64_to_u64() {
892            check_cast_lossy::<U64<Circuit>, console_root::types::U64<MainnetV0>>(
893                Mode::Constant,
894                count_is!(0, 0, 0, 0),
895            );
896            check_cast_lossy::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
897            check_cast_lossy::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
898        }
899
900        #[test]
901        fn test_i64_to_u128() {
902            check_cast_lossy::<U128<Circuit>, console_root::types::U128<MainnetV0>>(
903                Mode::Constant,
904                count_is!(0, 0, 0, 0),
905            );
906            check_cast_lossy::<U128<Circuit>, console_root::types::U128<MainnetV0>>(
907                Mode::Public,
908                count_is!(0, 0, 0, 0),
909            );
910            check_cast_lossy::<U128<Circuit>, console_root::types::U128<MainnetV0>>(
911                Mode::Private,
912                count_is!(0, 0, 0, 0),
913            );
914        }
915    }
916
917    mod i128 {
918        use super::*;
919
920        fn sample_values(
921            i: usize,
922            mode: Mode,
923            rng: &mut TestRng,
924        ) -> (console_root::types::I128<MainnetV0>, I128<Circuit>) {
925            super::sample_values(i, mode, rng)
926        }
927
928        check_cast_lossy!(cast_lossy, I128<Circuit>, console_root::types::I128<MainnetV0>);
929
930        #[test]
931        fn test_i128_to_address() {
932            check_cast_lossy::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
933                Mode::Constant,
934                count_less_than!(4303, 0, 0, 0),
935            );
936            check_cast_lossy::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
937                Mode::Public,
938                count_is!(2029, 0, 6745, 6750),
939            );
940            check_cast_lossy::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
941                Mode::Private,
942                count_is!(2029, 0, 6745, 6750),
943            );
944        }
945
946        #[test]
947        fn test_i128_to_boolean() {
948            check_cast_lossy::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
949                Mode::Constant,
950                count_is!(0, 0, 0, 0),
951            );
952            check_cast_lossy::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
953                Mode::Public,
954                count_is!(0, 0, 0, 0),
955            );
956            check_cast_lossy::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
957                Mode::Private,
958                count_is!(0, 0, 0, 0),
959            );
960        }
961
962        #[test]
963        fn test_i128_to_field() {
964            check_cast_lossy::<Field<Circuit>, console_root::types::Field<MainnetV0>>(
965                Mode::Constant,
966                count_is!(0, 0, 0, 0),
967            );
968            check_cast_lossy::<Field<Circuit>, console_root::types::Field<MainnetV0>>(
969                Mode::Public,
970                count_is!(0, 0, 0, 0),
971            );
972            check_cast_lossy::<Field<Circuit>, console_root::types::Field<MainnetV0>>(
973                Mode::Private,
974                count_is!(0, 0, 0, 0),
975            );
976        }
977
978        #[test]
979        fn test_i128_to_group() {
980            check_cast_lossy::<Group<Circuit>, console_root::types::Group<MainnetV0>>(
981                Mode::Constant,
982                count_less_than!(4303, 0, 0, 0),
983            );
984            check_cast_lossy::<Group<Circuit>, console_root::types::Group<MainnetV0>>(
985                Mode::Public,
986                count_is!(2029, 0, 6745, 6750),
987            );
988            check_cast_lossy::<Group<Circuit>, console_root::types::Group<MainnetV0>>(
989                Mode::Private,
990                count_is!(2029, 0, 6745, 6750),
991            );
992        }
993
994        #[test]
995        fn test_i128_to_i8() {
996            check_cast_lossy::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
997            check_cast_lossy::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
998            check_cast_lossy::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
999        }
1000
1001        #[test]
1002        fn test_i128_to_i16() {
1003            check_cast_lossy::<I16<Circuit>, console_root::types::I16<MainnetV0>>(
1004                Mode::Constant,
1005                count_is!(0, 0, 0, 0),
1006            );
1007            check_cast_lossy::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1008            check_cast_lossy::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1009        }
1010
1011        #[test]
1012        fn test_i128_to_i32() {
1013            check_cast_lossy::<I32<Circuit>, console_root::types::I32<MainnetV0>>(
1014                Mode::Constant,
1015                count_is!(0, 0, 0, 0),
1016            );
1017            check_cast_lossy::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1018            check_cast_lossy::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1019        }
1020
1021        #[test]
1022        fn test_i128_to_i64() {
1023            check_cast_lossy::<I64<Circuit>, console_root::types::I64<MainnetV0>>(
1024                Mode::Constant,
1025                count_is!(0, 0, 0, 0),
1026            );
1027            check_cast_lossy::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1028            check_cast_lossy::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1029        }
1030
1031        #[test]
1032        fn test_i128_to_i128() {
1033            check_cast_lossy::<I128<Circuit>, console_root::types::I128<MainnetV0>>(
1034                Mode::Constant,
1035                count_is!(0, 0, 0, 0),
1036            );
1037            check_cast_lossy::<I128<Circuit>, console_root::types::I128<MainnetV0>>(
1038                Mode::Public,
1039                count_is!(0, 0, 0, 0),
1040            );
1041            check_cast_lossy::<I128<Circuit>, console_root::types::I128<MainnetV0>>(
1042                Mode::Private,
1043                count_is!(0, 0, 0, 0),
1044            );
1045        }
1046
1047        #[test]
1048        fn test_i128_to_scalar() {
1049            check_cast_lossy::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(
1050                Mode::Constant,
1051                count_is!(0, 0, 0, 0),
1052            );
1053            check_cast_lossy::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(
1054                Mode::Public,
1055                count_is!(0, 0, 0, 0),
1056            );
1057            check_cast_lossy::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(
1058                Mode::Private,
1059                count_is!(0, 0, 0, 0),
1060            );
1061        }
1062
1063        #[test]
1064        fn test_i128_to_u8() {
1065            check_cast_lossy::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1066            check_cast_lossy::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1067            check_cast_lossy::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1068        }
1069
1070        #[test]
1071        fn test_i128_to_u16() {
1072            check_cast_lossy::<U16<Circuit>, console_root::types::U16<MainnetV0>>(
1073                Mode::Constant,
1074                count_is!(0, 0, 0, 0),
1075            );
1076            check_cast_lossy::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1077            check_cast_lossy::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1078        }
1079
1080        #[test]
1081        fn test_i128_to_u32() {
1082            check_cast_lossy::<U32<Circuit>, console_root::types::U32<MainnetV0>>(
1083                Mode::Constant,
1084                count_is!(0, 0, 0, 0),
1085            );
1086            check_cast_lossy::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1087            check_cast_lossy::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1088        }
1089
1090        #[test]
1091        fn test_i128_to_u64() {
1092            check_cast_lossy::<U64<Circuit>, console_root::types::U64<MainnetV0>>(
1093                Mode::Constant,
1094                count_is!(0, 0, 0, 0),
1095            );
1096            check_cast_lossy::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1097            check_cast_lossy::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1098        }
1099
1100        #[test]
1101        fn test_i128_to_u128() {
1102            check_cast_lossy::<U128<Circuit>, console_root::types::U128<MainnetV0>>(
1103                Mode::Constant,
1104                count_is!(0, 0, 0, 0),
1105            );
1106            check_cast_lossy::<U128<Circuit>, console_root::types::U128<MainnetV0>>(
1107                Mode::Public,
1108                count_is!(0, 0, 0, 0),
1109            );
1110            check_cast_lossy::<U128<Circuit>, console_root::types::U128<MainnetV0>>(
1111                Mode::Private,
1112                count_is!(0, 0, 0, 0),
1113            );
1114        }
1115    }
1116
1117    mod u8 {
1118        use super::*;
1119
1120        fn sample_values(i: usize, mode: Mode, rng: &mut TestRng) -> (console_root::types::U8<MainnetV0>, U8<Circuit>) {
1121            super::sample_values(i, mode, rng)
1122        }
1123
1124        check_cast_lossy!(cast_lossy, U8<Circuit>, console_root::types::U8<MainnetV0>);
1125
1126        #[test]
1127        fn test_u8_to_address() {
1128            check_cast_lossy::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
1129                Mode::Constant,
1130                count_less_than!(4303, 0, 0, 0),
1131            );
1132            check_cast_lossy::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
1133                Mode::Public,
1134                count_is!(2029, 0, 6745, 6750),
1135            );
1136            check_cast_lossy::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
1137                Mode::Private,
1138                count_is!(2029, 0, 6745, 6750),
1139            );
1140        }
1141
1142        #[test]
1143        fn test_u8_to_boolean() {
1144            check_cast_lossy::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
1145                Mode::Constant,
1146                count_is!(0, 0, 0, 0),
1147            );
1148            check_cast_lossy::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
1149                Mode::Public,
1150                count_is!(0, 0, 0, 0),
1151            );
1152            check_cast_lossy::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
1153                Mode::Private,
1154                count_is!(0, 0, 0, 0),
1155            );
1156        }
1157
1158        #[test]
1159        fn test_u8_to_field() {
1160            check_cast_lossy::<Field<Circuit>, console_root::types::Field<MainnetV0>>(
1161                Mode::Constant,
1162                count_is!(0, 0, 0, 0),
1163            );
1164            check_cast_lossy::<Field<Circuit>, console_root::types::Field<MainnetV0>>(
1165                Mode::Public,
1166                count_is!(0, 0, 0, 0),
1167            );
1168            check_cast_lossy::<Field<Circuit>, console_root::types::Field<MainnetV0>>(
1169                Mode::Private,
1170                count_is!(0, 0, 0, 0),
1171            );
1172        }
1173
1174        #[test]
1175        fn test_u8_to_group() {
1176            check_cast_lossy::<Group<Circuit>, console_root::types::Group<MainnetV0>>(
1177                Mode::Constant,
1178                count_less_than!(4303, 0, 0, 0),
1179            );
1180            check_cast_lossy::<Group<Circuit>, console_root::types::Group<MainnetV0>>(
1181                Mode::Public,
1182                count_is!(2029, 0, 6745, 6750),
1183            );
1184            check_cast_lossy::<Group<Circuit>, console_root::types::Group<MainnetV0>>(
1185                Mode::Private,
1186                count_is!(2029, 0, 6745, 6750),
1187            );
1188        }
1189
1190        #[test]
1191        fn test_u8_to_i8() {
1192            check_cast_lossy::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1193            check_cast_lossy::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1194            check_cast_lossy::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1195        }
1196
1197        #[test]
1198        fn test_u8_to_i16() {
1199            check_cast_lossy::<I16<Circuit>, console_root::types::I16<MainnetV0>>(
1200                Mode::Constant,
1201                count_is!(0, 0, 0, 0),
1202            );
1203            check_cast_lossy::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1204            check_cast_lossy::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1205        }
1206
1207        #[test]
1208        fn test_u8_to_i32() {
1209            check_cast_lossy::<I32<Circuit>, console_root::types::I32<MainnetV0>>(
1210                Mode::Constant,
1211                count_is!(0, 0, 0, 0),
1212            );
1213            check_cast_lossy::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1214            check_cast_lossy::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1215        }
1216
1217        #[test]
1218        fn test_u8_to_i64() {
1219            check_cast_lossy::<I64<Circuit>, console_root::types::I64<MainnetV0>>(
1220                Mode::Constant,
1221                count_is!(0, 0, 0, 0),
1222            );
1223            check_cast_lossy::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1224            check_cast_lossy::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1225        }
1226
1227        #[test]
1228        fn test_u8_to_i128() {
1229            check_cast_lossy::<I128<Circuit>, console_root::types::I128<MainnetV0>>(
1230                Mode::Constant,
1231                count_is!(0, 0, 0, 0),
1232            );
1233            check_cast_lossy::<I128<Circuit>, console_root::types::I128<MainnetV0>>(
1234                Mode::Public,
1235                count_is!(0, 0, 0, 0),
1236            );
1237            check_cast_lossy::<I128<Circuit>, console_root::types::I128<MainnetV0>>(
1238                Mode::Private,
1239                count_is!(0, 0, 0, 0),
1240            );
1241        }
1242
1243        #[test]
1244        fn test_u8_to_scalar() {
1245            check_cast_lossy::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(
1246                Mode::Constant,
1247                count_is!(0, 0, 0, 0),
1248            );
1249            check_cast_lossy::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(
1250                Mode::Public,
1251                count_is!(0, 0, 0, 0),
1252            );
1253            check_cast_lossy::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(
1254                Mode::Private,
1255                count_is!(0, 0, 0, 0),
1256            );
1257        }
1258
1259        #[test]
1260        fn test_u8_to_u8() {
1261            check_cast_lossy::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1262            check_cast_lossy::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1263            check_cast_lossy::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1264        }
1265
1266        #[test]
1267        fn test_u8_to_u16() {
1268            check_cast_lossy::<U16<Circuit>, console_root::types::U16<MainnetV0>>(
1269                Mode::Constant,
1270                count_is!(0, 0, 0, 0),
1271            );
1272            check_cast_lossy::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1273            check_cast_lossy::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1274        }
1275
1276        #[test]
1277        fn test_u8_to_u32() {
1278            check_cast_lossy::<U32<Circuit>, console_root::types::U32<MainnetV0>>(
1279                Mode::Constant,
1280                count_is!(0, 0, 0, 0),
1281            );
1282            check_cast_lossy::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1283            check_cast_lossy::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1284        }
1285
1286        #[test]
1287        fn test_u8_to_u64() {
1288            check_cast_lossy::<U64<Circuit>, console_root::types::U64<MainnetV0>>(
1289                Mode::Constant,
1290                count_is!(0, 0, 0, 0),
1291            );
1292            check_cast_lossy::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1293            check_cast_lossy::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1294        }
1295
1296        #[test]
1297        fn test_u8_to_u128() {
1298            check_cast_lossy::<U128<Circuit>, console_root::types::U128<MainnetV0>>(
1299                Mode::Constant,
1300                count_is!(0, 0, 0, 0),
1301            );
1302            check_cast_lossy::<U128<Circuit>, console_root::types::U128<MainnetV0>>(
1303                Mode::Public,
1304                count_is!(0, 0, 0, 0),
1305            );
1306            check_cast_lossy::<U128<Circuit>, console_root::types::U128<MainnetV0>>(
1307                Mode::Private,
1308                count_is!(0, 0, 0, 0),
1309            );
1310        }
1311    }
1312
1313    mod u16 {
1314        use super::*;
1315
1316        fn sample_values(
1317            i: usize,
1318            mode: Mode,
1319            rng: &mut TestRng,
1320        ) -> (console_root::types::U16<MainnetV0>, U16<Circuit>) {
1321            super::sample_values(i, mode, rng)
1322        }
1323
1324        check_cast_lossy!(cast_lossy, U16<Circuit>, console_root::types::U16<MainnetV0>);
1325
1326        #[test]
1327        fn test_u16_to_address() {
1328            check_cast_lossy::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
1329                Mode::Constant,
1330                count_less_than!(4303, 0, 0, 0),
1331            );
1332            check_cast_lossy::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
1333                Mode::Public,
1334                count_is!(2029, 0, 6745, 6750),
1335            );
1336            check_cast_lossy::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
1337                Mode::Private,
1338                count_is!(2029, 0, 6745, 6750),
1339            );
1340        }
1341
1342        #[test]
1343        fn test_u16_to_boolean() {
1344            check_cast_lossy::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
1345                Mode::Constant,
1346                count_is!(0, 0, 0, 0),
1347            );
1348            check_cast_lossy::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
1349                Mode::Public,
1350                count_is!(0, 0, 0, 0),
1351            );
1352            check_cast_lossy::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
1353                Mode::Private,
1354                count_is!(0, 0, 0, 0),
1355            );
1356        }
1357
1358        #[test]
1359        fn test_u16_to_field() {
1360            check_cast_lossy::<Field<Circuit>, console_root::types::Field<MainnetV0>>(
1361                Mode::Constant,
1362                count_is!(0, 0, 0, 0),
1363            );
1364            check_cast_lossy::<Field<Circuit>, console_root::types::Field<MainnetV0>>(
1365                Mode::Public,
1366                count_is!(0, 0, 0, 0),
1367            );
1368            check_cast_lossy::<Field<Circuit>, console_root::types::Field<MainnetV0>>(
1369                Mode::Private,
1370                count_is!(0, 0, 0, 0),
1371            );
1372        }
1373
1374        #[test]
1375        fn test_u16_to_group() {
1376            check_cast_lossy::<Group<Circuit>, console_root::types::Group<MainnetV0>>(
1377                Mode::Constant,
1378                count_less_than!(4303, 0, 0, 0),
1379            );
1380            check_cast_lossy::<Group<Circuit>, console_root::types::Group<MainnetV0>>(
1381                Mode::Public,
1382                count_is!(2029, 0, 6745, 6750),
1383            );
1384            check_cast_lossy::<Group<Circuit>, console_root::types::Group<MainnetV0>>(
1385                Mode::Private,
1386                count_is!(2029, 0, 6745, 6750),
1387            );
1388        }
1389
1390        #[test]
1391        fn test_u16_to_i8() {
1392            check_cast_lossy::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1393            check_cast_lossy::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1394            check_cast_lossy::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1395        }
1396
1397        #[test]
1398        fn test_u16_to_i16() {
1399            check_cast_lossy::<I16<Circuit>, console_root::types::I16<MainnetV0>>(
1400                Mode::Constant,
1401                count_is!(0, 0, 0, 0),
1402            );
1403            check_cast_lossy::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1404            check_cast_lossy::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1405        }
1406
1407        #[test]
1408        fn test_u16_to_i32() {
1409            check_cast_lossy::<I32<Circuit>, console_root::types::I32<MainnetV0>>(
1410                Mode::Constant,
1411                count_is!(0, 0, 0, 0),
1412            );
1413            check_cast_lossy::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1414            check_cast_lossy::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1415        }
1416
1417        #[test]
1418        fn test_u16_to_i64() {
1419            check_cast_lossy::<I64<Circuit>, console_root::types::I64<MainnetV0>>(
1420                Mode::Constant,
1421                count_is!(0, 0, 0, 0),
1422            );
1423            check_cast_lossy::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1424            check_cast_lossy::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1425        }
1426
1427        #[test]
1428        fn test_u16_to_i128() {
1429            check_cast_lossy::<I128<Circuit>, console_root::types::I128<MainnetV0>>(
1430                Mode::Constant,
1431                count_is!(0, 0, 0, 0),
1432            );
1433            check_cast_lossy::<I128<Circuit>, console_root::types::I128<MainnetV0>>(
1434                Mode::Public,
1435                count_is!(0, 0, 0, 0),
1436            );
1437            check_cast_lossy::<I128<Circuit>, console_root::types::I128<MainnetV0>>(
1438                Mode::Private,
1439                count_is!(0, 0, 0, 0),
1440            );
1441        }
1442
1443        #[test]
1444        fn test_u16_to_scalar() {
1445            check_cast_lossy::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(
1446                Mode::Constant,
1447                count_is!(0, 0, 0, 0),
1448            );
1449            check_cast_lossy::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(
1450                Mode::Public,
1451                count_is!(0, 0, 0, 0),
1452            );
1453            check_cast_lossy::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(
1454                Mode::Private,
1455                count_is!(0, 0, 0, 0),
1456            );
1457        }
1458
1459        #[test]
1460        fn test_u16_to_u8() {
1461            check_cast_lossy::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1462            check_cast_lossy::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1463            check_cast_lossy::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1464        }
1465
1466        #[test]
1467        fn test_u16_to_u16() {
1468            check_cast_lossy::<U16<Circuit>, console_root::types::U16<MainnetV0>>(
1469                Mode::Constant,
1470                count_is!(0, 0, 0, 0),
1471            );
1472            check_cast_lossy::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1473            check_cast_lossy::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1474        }
1475
1476        #[test]
1477        fn test_u16_to_u32() {
1478            check_cast_lossy::<U32<Circuit>, console_root::types::U32<MainnetV0>>(
1479                Mode::Constant,
1480                count_is!(0, 0, 0, 0),
1481            );
1482            check_cast_lossy::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1483            check_cast_lossy::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1484        }
1485
1486        #[test]
1487        fn test_u16_to_u64() {
1488            check_cast_lossy::<U64<Circuit>, console_root::types::U64<MainnetV0>>(
1489                Mode::Constant,
1490                count_is!(0, 0, 0, 0),
1491            );
1492            check_cast_lossy::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1493            check_cast_lossy::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1494        }
1495
1496        #[test]
1497        fn test_u16_to_u128() {
1498            check_cast_lossy::<U128<Circuit>, console_root::types::U128<MainnetV0>>(
1499                Mode::Constant,
1500                count_is!(0, 0, 0, 0),
1501            );
1502            check_cast_lossy::<U128<Circuit>, console_root::types::U128<MainnetV0>>(
1503                Mode::Public,
1504                count_is!(0, 0, 0, 0),
1505            );
1506            check_cast_lossy::<U128<Circuit>, console_root::types::U128<MainnetV0>>(
1507                Mode::Private,
1508                count_is!(0, 0, 0, 0),
1509            );
1510        }
1511    }
1512
1513    mod u32 {
1514        use super::*;
1515
1516        fn sample_values(
1517            i: usize,
1518            mode: Mode,
1519            rng: &mut TestRng,
1520        ) -> (console_root::types::U32<MainnetV0>, U32<Circuit>) {
1521            super::sample_values(i, mode, rng)
1522        }
1523
1524        check_cast_lossy!(cast_lossy, U32<Circuit>, console_root::types::U32<MainnetV0>);
1525
1526        #[test]
1527        fn test_u32_to_address() {
1528            check_cast_lossy::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
1529                Mode::Constant,
1530                count_less_than!(4303, 0, 0, 0),
1531            );
1532            check_cast_lossy::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
1533                Mode::Public,
1534                count_is!(2029, 0, 6745, 6750),
1535            );
1536            check_cast_lossy::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
1537                Mode::Private,
1538                count_is!(2029, 0, 6745, 6750),
1539            );
1540        }
1541
1542        #[test]
1543        fn test_u32_to_boolean() {
1544            check_cast_lossy::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
1545                Mode::Constant,
1546                count_is!(0, 0, 0, 0),
1547            );
1548            check_cast_lossy::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
1549                Mode::Public,
1550                count_is!(0, 0, 0, 0),
1551            );
1552            check_cast_lossy::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
1553                Mode::Private,
1554                count_is!(0, 0, 0, 0),
1555            );
1556        }
1557
1558        #[test]
1559        fn test_u32_to_field() {
1560            check_cast_lossy::<Field<Circuit>, console_root::types::Field<MainnetV0>>(
1561                Mode::Constant,
1562                count_is!(0, 0, 0, 0),
1563            );
1564            check_cast_lossy::<Field<Circuit>, console_root::types::Field<MainnetV0>>(
1565                Mode::Public,
1566                count_is!(0, 0, 0, 0),
1567            );
1568            check_cast_lossy::<Field<Circuit>, console_root::types::Field<MainnetV0>>(
1569                Mode::Private,
1570                count_is!(0, 0, 0, 0),
1571            );
1572        }
1573
1574        #[test]
1575        fn test_u32_to_group() {
1576            check_cast_lossy::<Group<Circuit>, console_root::types::Group<MainnetV0>>(
1577                Mode::Constant,
1578                count_less_than!(4303, 0, 0, 0),
1579            );
1580            check_cast_lossy::<Group<Circuit>, console_root::types::Group<MainnetV0>>(
1581                Mode::Public,
1582                count_is!(2029, 0, 6745, 6750),
1583            );
1584            check_cast_lossy::<Group<Circuit>, console_root::types::Group<MainnetV0>>(
1585                Mode::Private,
1586                count_is!(2029, 0, 6745, 6750),
1587            );
1588        }
1589
1590        #[test]
1591        fn test_u32_to_i8() {
1592            check_cast_lossy::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1593            check_cast_lossy::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1594            check_cast_lossy::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1595        }
1596
1597        #[test]
1598        fn test_u32_to_i16() {
1599            check_cast_lossy::<I16<Circuit>, console_root::types::I16<MainnetV0>>(
1600                Mode::Constant,
1601                count_is!(0, 0, 0, 0),
1602            );
1603            check_cast_lossy::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1604            check_cast_lossy::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1605        }
1606
1607        #[test]
1608        fn test_u32_to_i32() {
1609            check_cast_lossy::<I32<Circuit>, console_root::types::I32<MainnetV0>>(
1610                Mode::Constant,
1611                count_is!(0, 0, 0, 0),
1612            );
1613            check_cast_lossy::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1614            check_cast_lossy::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1615        }
1616
1617        #[test]
1618        fn test_u32_to_i64() {
1619            check_cast_lossy::<I64<Circuit>, console_root::types::I64<MainnetV0>>(
1620                Mode::Constant,
1621                count_is!(0, 0, 0, 0),
1622            );
1623            check_cast_lossy::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1624            check_cast_lossy::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1625        }
1626
1627        #[test]
1628        fn test_u32_to_i128() {
1629            check_cast_lossy::<I128<Circuit>, console_root::types::I128<MainnetV0>>(
1630                Mode::Constant,
1631                count_is!(0, 0, 0, 0),
1632            );
1633            check_cast_lossy::<I128<Circuit>, console_root::types::I128<MainnetV0>>(
1634                Mode::Public,
1635                count_is!(0, 0, 0, 0),
1636            );
1637            check_cast_lossy::<I128<Circuit>, console_root::types::I128<MainnetV0>>(
1638                Mode::Private,
1639                count_is!(0, 0, 0, 0),
1640            );
1641        }
1642
1643        #[test]
1644        fn test_u32_to_scalar() {
1645            check_cast_lossy::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(
1646                Mode::Constant,
1647                count_is!(0, 0, 0, 0),
1648            );
1649            check_cast_lossy::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(
1650                Mode::Public,
1651                count_is!(0, 0, 0, 0),
1652            );
1653            check_cast_lossy::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(
1654                Mode::Private,
1655                count_is!(0, 0, 0, 0),
1656            );
1657        }
1658
1659        #[test]
1660        fn test_u32_to_u8() {
1661            check_cast_lossy::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1662            check_cast_lossy::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1663            check_cast_lossy::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1664        }
1665
1666        #[test]
1667        fn test_u32_to_u16() {
1668            check_cast_lossy::<U16<Circuit>, console_root::types::U16<MainnetV0>>(
1669                Mode::Constant,
1670                count_is!(0, 0, 0, 0),
1671            );
1672            check_cast_lossy::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1673            check_cast_lossy::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1674        }
1675
1676        #[test]
1677        fn test_u32_to_u32() {
1678            check_cast_lossy::<U32<Circuit>, console_root::types::U32<MainnetV0>>(
1679                Mode::Constant,
1680                count_is!(0, 0, 0, 0),
1681            );
1682            check_cast_lossy::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1683            check_cast_lossy::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1684        }
1685
1686        #[test]
1687        fn test_u32_to_u64() {
1688            check_cast_lossy::<U64<Circuit>, console_root::types::U64<MainnetV0>>(
1689                Mode::Constant,
1690                count_is!(0, 0, 0, 0),
1691            );
1692            check_cast_lossy::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1693            check_cast_lossy::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1694        }
1695
1696        #[test]
1697        fn test_u32_to_u128() {
1698            check_cast_lossy::<U128<Circuit>, console_root::types::U128<MainnetV0>>(
1699                Mode::Constant,
1700                count_is!(0, 0, 0, 0),
1701            );
1702            check_cast_lossy::<U128<Circuit>, console_root::types::U128<MainnetV0>>(
1703                Mode::Public,
1704                count_is!(0, 0, 0, 0),
1705            );
1706            check_cast_lossy::<U128<Circuit>, console_root::types::U128<MainnetV0>>(
1707                Mode::Private,
1708                count_is!(0, 0, 0, 0),
1709            );
1710        }
1711    }
1712
1713    mod u64 {
1714        use super::*;
1715
1716        fn sample_values(
1717            i: usize,
1718            mode: Mode,
1719            rng: &mut TestRng,
1720        ) -> (console_root::types::U64<MainnetV0>, U64<Circuit>) {
1721            super::sample_values(i, mode, rng)
1722        }
1723
1724        check_cast_lossy!(cast_lossy, U64<Circuit>, console_root::types::U64<MainnetV0>);
1725
1726        #[test]
1727        fn test_u64_to_address() {
1728            check_cast_lossy::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
1729                Mode::Constant,
1730                count_less_than!(4303, 0, 0, 0),
1731            );
1732            check_cast_lossy::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
1733                Mode::Public,
1734                count_is!(2029, 0, 6745, 6750),
1735            );
1736            check_cast_lossy::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
1737                Mode::Private,
1738                count_is!(2029, 0, 6745, 6750),
1739            );
1740        }
1741
1742        #[test]
1743        fn test_u64_to_boolean() {
1744            check_cast_lossy::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
1745                Mode::Constant,
1746                count_is!(0, 0, 0, 0),
1747            );
1748            check_cast_lossy::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
1749                Mode::Public,
1750                count_is!(0, 0, 0, 0),
1751            );
1752            check_cast_lossy::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
1753                Mode::Private,
1754                count_is!(0, 0, 0, 0),
1755            );
1756        }
1757
1758        #[test]
1759        fn test_u64_to_field() {
1760            check_cast_lossy::<Field<Circuit>, console_root::types::Field<MainnetV0>>(
1761                Mode::Constant,
1762                count_is!(0, 0, 0, 0),
1763            );
1764            check_cast_lossy::<Field<Circuit>, console_root::types::Field<MainnetV0>>(
1765                Mode::Public,
1766                count_is!(0, 0, 0, 0),
1767            );
1768            check_cast_lossy::<Field<Circuit>, console_root::types::Field<MainnetV0>>(
1769                Mode::Private,
1770                count_is!(0, 0, 0, 0),
1771            );
1772        }
1773
1774        #[test]
1775        fn test_u64_to_group() {
1776            check_cast_lossy::<Group<Circuit>, console_root::types::Group<MainnetV0>>(
1777                Mode::Constant,
1778                count_less_than!(4303, 0, 0, 0),
1779            );
1780            check_cast_lossy::<Group<Circuit>, console_root::types::Group<MainnetV0>>(
1781                Mode::Public,
1782                count_is!(2029, 0, 6745, 6750),
1783            );
1784            check_cast_lossy::<Group<Circuit>, console_root::types::Group<MainnetV0>>(
1785                Mode::Private,
1786                count_is!(2029, 0, 6745, 6750),
1787            );
1788        }
1789
1790        #[test]
1791        fn test_u64_to_i8() {
1792            check_cast_lossy::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1793            check_cast_lossy::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1794            check_cast_lossy::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1795        }
1796
1797        #[test]
1798        fn test_u64_to_i16() {
1799            check_cast_lossy::<I16<Circuit>, console_root::types::I16<MainnetV0>>(
1800                Mode::Constant,
1801                count_is!(0, 0, 0, 0),
1802            );
1803            check_cast_lossy::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1804            check_cast_lossy::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1805        }
1806
1807        #[test]
1808        fn test_u64_to_i32() {
1809            check_cast_lossy::<I32<Circuit>, console_root::types::I32<MainnetV0>>(
1810                Mode::Constant,
1811                count_is!(0, 0, 0, 0),
1812            );
1813            check_cast_lossy::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1814            check_cast_lossy::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1815        }
1816
1817        #[test]
1818        fn test_u64_to_i64() {
1819            check_cast_lossy::<I64<Circuit>, console_root::types::I64<MainnetV0>>(
1820                Mode::Constant,
1821                count_is!(0, 0, 0, 0),
1822            );
1823            check_cast_lossy::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1824            check_cast_lossy::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1825        }
1826
1827        #[test]
1828        fn test_u64_to_i128() {
1829            check_cast_lossy::<I128<Circuit>, console_root::types::I128<MainnetV0>>(
1830                Mode::Constant,
1831                count_is!(0, 0, 0, 0),
1832            );
1833            check_cast_lossy::<I128<Circuit>, console_root::types::I128<MainnetV0>>(
1834                Mode::Public,
1835                count_is!(0, 0, 0, 0),
1836            );
1837            check_cast_lossy::<I128<Circuit>, console_root::types::I128<MainnetV0>>(
1838                Mode::Private,
1839                count_is!(0, 0, 0, 0),
1840            );
1841        }
1842
1843        #[test]
1844        fn test_u64_to_scalar() {
1845            check_cast_lossy::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(
1846                Mode::Constant,
1847                count_is!(0, 0, 0, 0),
1848            );
1849            check_cast_lossy::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(
1850                Mode::Public,
1851                count_is!(0, 0, 0, 0),
1852            );
1853            check_cast_lossy::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(
1854                Mode::Private,
1855                count_is!(0, 0, 0, 0),
1856            );
1857        }
1858
1859        #[test]
1860        fn test_u64_to_u8() {
1861            check_cast_lossy::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1862            check_cast_lossy::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1863            check_cast_lossy::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1864        }
1865
1866        #[test]
1867        fn test_u64_to_u16() {
1868            check_cast_lossy::<U16<Circuit>, console_root::types::U16<MainnetV0>>(
1869                Mode::Constant,
1870                count_is!(0, 0, 0, 0),
1871            );
1872            check_cast_lossy::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1873            check_cast_lossy::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1874        }
1875
1876        #[test]
1877        fn test_u64_to_u32() {
1878            check_cast_lossy::<U32<Circuit>, console_root::types::U32<MainnetV0>>(
1879                Mode::Constant,
1880                count_is!(0, 0, 0, 0),
1881            );
1882            check_cast_lossy::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1883            check_cast_lossy::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1884        }
1885
1886        #[test]
1887        fn test_u64_to_u64() {
1888            check_cast_lossy::<U64<Circuit>, console_root::types::U64<MainnetV0>>(
1889                Mode::Constant,
1890                count_is!(0, 0, 0, 0),
1891            );
1892            check_cast_lossy::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1893            check_cast_lossy::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1894        }
1895
1896        #[test]
1897        fn test_u64_to_u128() {
1898            check_cast_lossy::<U128<Circuit>, console_root::types::U128<MainnetV0>>(
1899                Mode::Constant,
1900                count_is!(0, 0, 0, 0),
1901            );
1902            check_cast_lossy::<U128<Circuit>, console_root::types::U128<MainnetV0>>(
1903                Mode::Public,
1904                count_is!(0, 0, 0, 0),
1905            );
1906            check_cast_lossy::<U128<Circuit>, console_root::types::U128<MainnetV0>>(
1907                Mode::Private,
1908                count_is!(0, 0, 0, 0),
1909            );
1910        }
1911    }
1912
1913    mod u128 {
1914        use super::*;
1915
1916        fn sample_values(
1917            i: usize,
1918            mode: Mode,
1919            rng: &mut TestRng,
1920        ) -> (console_root::types::U128<MainnetV0>, U128<Circuit>) {
1921            super::sample_values(i, mode, rng)
1922        }
1923
1924        check_cast_lossy!(cast_lossy, U128<Circuit>, console_root::types::U128<MainnetV0>);
1925
1926        #[test]
1927        fn test_u128_to_address() {
1928            check_cast_lossy::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
1929                Mode::Constant,
1930                count_less_than!(4303, 0, 0, 0),
1931            );
1932            check_cast_lossy::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
1933                Mode::Public,
1934                count_is!(2029, 0, 6745, 6750),
1935            );
1936            check_cast_lossy::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
1937                Mode::Private,
1938                count_is!(2029, 0, 6745, 6750),
1939            );
1940        }
1941
1942        #[test]
1943        fn test_u128_to_boolean() {
1944            check_cast_lossy::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
1945                Mode::Constant,
1946                count_is!(0, 0, 0, 0),
1947            );
1948            check_cast_lossy::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
1949                Mode::Public,
1950                count_is!(0, 0, 0, 0),
1951            );
1952            check_cast_lossy::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
1953                Mode::Private,
1954                count_is!(0, 0, 0, 0),
1955            );
1956        }
1957
1958        #[test]
1959        fn test_u128_to_field() {
1960            check_cast_lossy::<Field<Circuit>, console_root::types::Field<MainnetV0>>(
1961                Mode::Constant,
1962                count_is!(0, 0, 0, 0),
1963            );
1964            check_cast_lossy::<Field<Circuit>, console_root::types::Field<MainnetV0>>(
1965                Mode::Public,
1966                count_is!(0, 0, 0, 0),
1967            );
1968            check_cast_lossy::<Field<Circuit>, console_root::types::Field<MainnetV0>>(
1969                Mode::Private,
1970                count_is!(0, 0, 0, 0),
1971            );
1972        }
1973
1974        #[test]
1975        fn test_u128_to_group() {
1976            check_cast_lossy::<Group<Circuit>, console_root::types::Group<MainnetV0>>(
1977                Mode::Constant,
1978                count_less_than!(4303, 0, 0, 0),
1979            );
1980            check_cast_lossy::<Group<Circuit>, console_root::types::Group<MainnetV0>>(
1981                Mode::Public,
1982                count_is!(2029, 0, 6745, 6750),
1983            );
1984            check_cast_lossy::<Group<Circuit>, console_root::types::Group<MainnetV0>>(
1985                Mode::Private,
1986                count_is!(2029, 0, 6745, 6750),
1987            );
1988        }
1989
1990        #[test]
1991        fn test_u128_to_i8() {
1992            check_cast_lossy::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1993            check_cast_lossy::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1994            check_cast_lossy::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1995        }
1996
1997        #[test]
1998        fn test_u128_to_i16() {
1999            check_cast_lossy::<I16<Circuit>, console_root::types::I16<MainnetV0>>(
2000                Mode::Constant,
2001                count_is!(0, 0, 0, 0),
2002            );
2003            check_cast_lossy::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
2004            check_cast_lossy::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
2005        }
2006
2007        #[test]
2008        fn test_u128_to_i32() {
2009            check_cast_lossy::<I32<Circuit>, console_root::types::I32<MainnetV0>>(
2010                Mode::Constant,
2011                count_is!(0, 0, 0, 0),
2012            );
2013            check_cast_lossy::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
2014            check_cast_lossy::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
2015        }
2016
2017        #[test]
2018        fn test_u128_to_i64() {
2019            check_cast_lossy::<I64<Circuit>, console_root::types::I64<MainnetV0>>(
2020                Mode::Constant,
2021                count_is!(0, 0, 0, 0),
2022            );
2023            check_cast_lossy::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
2024            check_cast_lossy::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
2025        }
2026
2027        #[test]
2028        fn test_u128_to_i128() {
2029            check_cast_lossy::<I128<Circuit>, console_root::types::I128<MainnetV0>>(
2030                Mode::Constant,
2031                count_is!(0, 0, 0, 0),
2032            );
2033            check_cast_lossy::<I128<Circuit>, console_root::types::I128<MainnetV0>>(
2034                Mode::Public,
2035                count_is!(0, 0, 0, 0),
2036            );
2037            check_cast_lossy::<I128<Circuit>, console_root::types::I128<MainnetV0>>(
2038                Mode::Private,
2039                count_is!(0, 0, 0, 0),
2040            );
2041        }
2042
2043        #[test]
2044        fn test_u128_to_scalar() {
2045            check_cast_lossy::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(
2046                Mode::Constant,
2047                count_is!(0, 0, 0, 0),
2048            );
2049            check_cast_lossy::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(
2050                Mode::Public,
2051                count_is!(0, 0, 0, 0),
2052            );
2053            check_cast_lossy::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(
2054                Mode::Private,
2055                count_is!(0, 0, 0, 0),
2056            );
2057        }
2058
2059        #[test]
2060        fn test_u128_to_u8() {
2061            check_cast_lossy::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
2062            check_cast_lossy::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
2063            check_cast_lossy::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
2064        }
2065
2066        #[test]
2067        fn test_u128_to_u16() {
2068            check_cast_lossy::<U16<Circuit>, console_root::types::U16<MainnetV0>>(
2069                Mode::Constant,
2070                count_is!(0, 0, 0, 0),
2071            );
2072            check_cast_lossy::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
2073            check_cast_lossy::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
2074        }
2075
2076        #[test]
2077        fn test_u128_to_u32() {
2078            check_cast_lossy::<U32<Circuit>, console_root::types::U32<MainnetV0>>(
2079                Mode::Constant,
2080                count_is!(0, 0, 0, 0),
2081            );
2082            check_cast_lossy::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
2083            check_cast_lossy::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
2084        }
2085
2086        #[test]
2087        fn test_u128_to_u64() {
2088            check_cast_lossy::<U64<Circuit>, console_root::types::U64<MainnetV0>>(
2089                Mode::Constant,
2090                count_is!(0, 0, 0, 0),
2091            );
2092            check_cast_lossy::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
2093            check_cast_lossy::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
2094        }
2095
2096        #[test]
2097        fn test_u128_to_u128() {
2098            check_cast_lossy::<U128<Circuit>, console_root::types::U128<MainnetV0>>(
2099                Mode::Constant,
2100                count_is!(0, 0, 0, 0),
2101            );
2102            check_cast_lossy::<U128<Circuit>, console_root::types::U128<MainnetV0>>(
2103                Mode::Public,
2104                count_is!(0, 0, 0, 0),
2105            );
2106            check_cast_lossy::<U128<Circuit>, console_root::types::U128<MainnetV0>>(
2107                Mode::Private,
2108                count_is!(0, 0, 0, 0),
2109            );
2110        }
2111    }
2112}