Skip to main content

snarkvm_circuit_program/data/literal/cast/
integer.rs

1// Copyright (c) 2019-2026 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> Cast<Address<E>> for Integer<E, I> {
19    /// Casts an `Integer` to an `Address`.
20    ///
21    /// This operation converts the integer to a field element, and then attempts to recover
22    /// the group element by treating the field element as an x-coordinate. The group element
23    /// is then converted to an address.
24    ///
25    /// To cast arbitrary integers to addresses, use `Integer::cast_lossy`.
26    #[inline]
27    fn cast(&self) -> Address<E> {
28        let field: Field<E> = self.cast();
29        field.cast()
30    }
31}
32
33impl<E: Environment, I: IntegerType> Cast<Boolean<E>> for Integer<E, I> {
34    /// Casts an `Integer` to a `Boolean`, if the integer is zero or one.
35    ///
36    /// To cast arbitrary integers to booleans, use `Integer::cast_lossy`.
37    #[inline]
38    fn cast(&self) -> Boolean<E> {
39        let is_one = self.is_one();
40        E::assert(self.is_zero().bitor(&is_one)).expect("Integer must be zero or one to cast to Boolean");
41        is_one
42    }
43}
44
45impl<E: Environment, I: IntegerType> Cast<Field<E>> for Integer<E, I> {
46    /// Casts an `Integer` to a `Field`.
47    #[inline]
48    fn cast(&self) -> Field<E> {
49        self.to_field()
50    }
51}
52
53impl<E: Environment, I: IntegerType> Cast<Group<E>> for Integer<E, I> {
54    /// Casts an `Integer` to a `Group`.
55    ///
56    /// This operation converts the integer to a field element, and then attempts to recover
57    /// the group element by treating the field element as an x-coordinate.
58    ///
59    /// To cast arbitrary integers to groups, use `Integer::cast_lossy`.
60    #[inline]
61    fn cast(&self) -> Group<E> {
62        let field: Field<E> = self.cast();
63        field.cast()
64    }
65}
66
67impl<E: Environment, I0: IntegerType, I1: IntegerType> Cast<Integer<E, I1>> for Integer<E, I0> {
68    /// Casts an `Integer` to another `Integer`, if the conversion is lossless.
69    #[inline]
70    fn cast(&self) -> Integer<E, I1> {
71        let mut bits_le = self.to_bits_le();
72        match (I0::is_signed(), I1::is_signed()) {
73            // If the two types are both unsigned, instantiate the new integer from the bits.
74            (false, false) => Integer::<E, I1>::from_bits_le(&bits_le),
75            // If the source type is unsigned and the destination type is signed, perform the required checks.
76            (false, true) => match I0::BITS < I1::BITS {
77                // If the source type is smaller than the destination type, instantiate the new integer from the bits.
78                true => Integer::<E, I1>::from_bits_le(&bits_le),
79                // If the source type is the same size or larger than the destination type, check that the most significant bits are zero.
80                // Then instantiate the new integer from the lower bits.
81                false => {
82                    Boolean::assert_bits_are_zero(&bits_le[(I1::BITS.saturating_sub(1) as usize)..]);
83                    Integer::<E, I1>::from_bits_le(&bits_le[..(I1::BITS as usize)])
84                }
85            },
86            // If the source type is signed and the destination type is unsigned, perform the required checks.
87            (true, false) => match I0::BITS <= I1::BITS {
88                // If the source type is smaller than or equal to the destination type, check that the most significant bit is zero.
89                // Then instantiate the new integer from the lower bits.
90                true => {
91                    E::assert(!&bits_le[I0::BITS.saturating_sub(1) as usize])
92                        .expect("Signed integer MSB must be zero to cast to unsigned");
93                    Integer::<E, I1>::from_bits_le(&bits_le)
94                }
95                // If the source type is larger than the destination type, check that the upper bits are zero.
96                // Then instantiate the new integer from the lower bits.
97                false => {
98                    Boolean::assert_bits_are_zero(&bits_le[(I1::BITS as usize)..]);
99                    Integer::<E, I1>::from_bits_le(&bits_le[..(I1::BITS as usize)])
100                }
101            },
102            // If the two types are both signed, perform the required checks.
103            (true, true) => match I0::BITS <= I1::BITS {
104                // If the source type is smaller than or equal to the destination type, sign extend the source integer.
105                // Then instantiate the new integer from the bits.
106                true => {
107                    bits_le.resize(I1::BITS as usize, self.msb().clone());
108                    Integer::<E, I1>::from_bits_le(&bits_le)
109                }
110                // If the source type is larger than the destination type, check that the upper bits match the most significant bit.
111                // Then instantiate the new integer from the appropriate lower bits.
112                false => {
113                    // Get the most significant bit.
114                    let msb = match bits_le.pop() {
115                        Some(bit) => bit,
116                        None => E::halt("Failed to extract the MSB from the integer."),
117                    };
118                    // Check that the upper bits match the most significant bit.
119                    let upper_bits = bits_le.iter().skip(I1::BITS.saturating_sub(1) as usize);
120                    for bit in upper_bits {
121                        E::assert_eq(&msb, bit).expect("Signed integer upper bits must match MSB for cast");
122                    }
123                    // Instantiate the new integer from the lower bits and the most significant bit.
124                    let mut lower_bits: Vec<_> =
125                        bits_le.into_iter().take(I1::BITS.saturating_sub(1) as usize).collect();
126                    lower_bits.push(msb);
127                    Integer::<E, I1>::from_bits_le(&lower_bits)
128                }
129            },
130        }
131    }
132}
133
134impl<E: Environment, I: IntegerType> Cast<Scalar<E>> for Integer<E, I> {
135    /// Casts an `Integer` to a `Scalar`.
136    #[inline]
137    fn cast(&self) -> Scalar<E> {
138        let bits_le = self.to_bits_le();
139        Scalar::<E>::from_bits_le(&bits_le)
140    }
141}
142
143impl<E: Environment, I: IntegerType> Cast<IdentifierLiteral<E>> for Integer<E, I> {
144    /// Casts an `Integer` to an `IdentifierLiteral`.
145    #[inline]
146    fn cast(&self) -> IdentifierLiteral<E> {
147        let field: Field<E> = self.cast();
148        field.cast()
149    }
150}
151
152#[cfg(test)]
153mod tests {
154    use super::*;
155    use console::Cast as _;
156    use console_root::{
157        network::MainnetV0,
158        prelude::{One, TestRng, Uniform, Zero},
159    };
160    use snarkvm_circuit_types::environment::{Circuit, Eject, Inject, Mode, UpdatableCount, count_is, count_less_than};
161
162    use std::fmt::Debug;
163
164    const ITERATIONS: usize = 10;
165
166    fn sample_values<I: IntegerType>(
167        i: usize,
168        mode: Mode,
169        rng: &mut TestRng,
170    ) -> (console_root::types::integers::Integer<MainnetV0, I>, Integer<Circuit, I>) {
171        let console_value = match i {
172            0 => console_root::types::integers::Integer::<MainnetV0, I>::zero(),
173            1 => console_root::types::integers::Integer::<MainnetV0, I>::one(),
174            2 => console_root::types::integers::Integer::<MainnetV0, I>::new(I::MAX),
175            3 => console_root::types::integers::Integer::<MainnetV0, I>::new(I::MIN),
176            4 if I::is_signed() => -console_root::types::integers::Integer::<MainnetV0, I>::one(),
177            _ => Uniform::rand(rng),
178        };
179        let circuit_value = Integer::<Circuit, I>::new(mode, console_value);
180        (console_value, circuit_value)
181    }
182
183    mod i8 {
184        use super::*;
185
186        fn sample_values(i: usize, mode: Mode, rng: &mut TestRng) -> (console_root::types::I8<MainnetV0>, I8<Circuit>) {
187            super::sample_values(i, mode, rng)
188        }
189
190        impl_check_cast!(cast, I8<Circuit>, console_root::types::I8<MainnetV0>);
191
192        #[test]
193        fn test_i8_to_address() {
194            check_cast::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
195                Mode::Constant,
196                count_less_than!(11, 0, 0, 0),
197            );
198            check_cast::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
199                Mode::Public,
200                count_is!(4, 0, 13, 13),
201            );
202            check_cast::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
203                Mode::Private,
204                count_is!(4, 0, 13, 13),
205            );
206        }
207
208        #[test]
209        fn test_i8_to_boolean() {
210            check_cast::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
211                Mode::Constant,
212                count_is!(16, 0, 0, 0),
213            );
214            check_cast::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
215                Mode::Public,
216                count_is!(16, 0, 5, 6),
217            );
218            check_cast::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
219                Mode::Private,
220                count_is!(16, 0, 5, 6),
221            );
222        }
223
224        #[test]
225        fn test_i8_to_field() {
226            check_cast::<Field<Circuit>, console_root::types::Field<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
227            check_cast::<Field<Circuit>, console_root::types::Field<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
228            check_cast::<Field<Circuit>, console_root::types::Field<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
229        }
230
231        #[test]
232        fn test_i8_to_group() {
233            check_cast::<Group<Circuit>, console_root::types::Group<MainnetV0>>(
234                Mode::Constant,
235                count_less_than!(11, 0, 0, 0),
236            );
237            check_cast::<Group<Circuit>, console_root::types::Group<MainnetV0>>(Mode::Public, count_is!(4, 0, 13, 13));
238            check_cast::<Group<Circuit>, console_root::types::Group<MainnetV0>>(Mode::Private, count_is!(4, 0, 13, 13));
239        }
240
241        #[test]
242        fn test_i8_to_i8() {
243            check_cast::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
244            check_cast::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
245            check_cast::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
246        }
247
248        #[test]
249        fn test_i8_to_i16() {
250            check_cast::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
251            check_cast::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
252            check_cast::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
253        }
254
255        #[test]
256        fn test_i8_to_i32() {
257            check_cast::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
258            check_cast::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
259            check_cast::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
260        }
261
262        #[test]
263        fn test_i8_to_i64() {
264            check_cast::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
265            check_cast::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
266            check_cast::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
267        }
268
269        #[test]
270        fn test_i8_to_i128() {
271            check_cast::<I128<Circuit>, console_root::types::I128<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
272            check_cast::<I128<Circuit>, console_root::types::I128<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
273            check_cast::<I128<Circuit>, console_root::types::I128<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
274        }
275
276        #[test]
277        fn test_i8_to_scalar() {
278            check_cast::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(
279                Mode::Constant,
280                count_is!(0, 0, 0, 0),
281            );
282            check_cast::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
283            check_cast::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
284        }
285
286        #[test]
287        fn test_i8_to_u8() {
288            check_cast::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
289            check_cast::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
290            check_cast::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
291        }
292
293        #[test]
294        fn test_i8_to_u16() {
295            check_cast::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
296            check_cast::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
297            check_cast::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
298        }
299
300        #[test]
301        fn test_i8_to_u32() {
302            check_cast::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
303            check_cast::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
304            check_cast::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
305        }
306
307        #[test]
308        fn test_i8_to_u64() {
309            check_cast::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
310            check_cast::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
311            check_cast::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
312        }
313
314        #[test]
315        fn test_i8_to_u128() {
316            check_cast::<U128<Circuit>, console_root::types::U128<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
317            check_cast::<U128<Circuit>, console_root::types::U128<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
318            check_cast::<U128<Circuit>, console_root::types::U128<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
319        }
320    }
321
322    mod i16 {
323        use super::*;
324
325        fn sample_values(
326            i: usize,
327            mode: Mode,
328            rng: &mut TestRng,
329        ) -> (console_root::types::I16<MainnetV0>, I16<Circuit>) {
330            super::sample_values(i, mode, rng)
331        }
332
333        impl_check_cast!(cast, I16<Circuit>, console_root::types::I16<MainnetV0>);
334
335        #[test]
336        fn test_i16_to_address() {
337            check_cast::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
338                Mode::Constant,
339                count_less_than!(11, 0, 0, 0),
340            );
341            check_cast::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
342                Mode::Public,
343                count_is!(4, 0, 13, 13),
344            );
345            check_cast::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
346                Mode::Private,
347                count_is!(4, 0, 13, 13),
348            );
349        }
350
351        #[test]
352        fn test_i16_to_boolean() {
353            check_cast::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
354                Mode::Constant,
355                count_is!(32, 0, 0, 0),
356            );
357            check_cast::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
358                Mode::Public,
359                count_is!(32, 0, 5, 6),
360            );
361            check_cast::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
362                Mode::Private,
363                count_is!(32, 0, 5, 6),
364            );
365        }
366
367        #[test]
368        fn test_i16_to_field() {
369            check_cast::<Field<Circuit>, console_root::types::Field<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
370            check_cast::<Field<Circuit>, console_root::types::Field<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
371            check_cast::<Field<Circuit>, console_root::types::Field<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
372        }
373
374        #[test]
375        fn test_i16_to_group() {
376            check_cast::<Group<Circuit>, console_root::types::Group<MainnetV0>>(
377                Mode::Constant,
378                count_less_than!(11, 0, 0, 0),
379            );
380            check_cast::<Group<Circuit>, console_root::types::Group<MainnetV0>>(Mode::Public, count_is!(4, 0, 13, 13));
381            check_cast::<Group<Circuit>, console_root::types::Group<MainnetV0>>(Mode::Private, count_is!(4, 0, 13, 13));
382        }
383
384        #[test]
385        fn test_i16_to_i8() {
386            check_cast::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
387            check_cast::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 8));
388            check_cast::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 8));
389        }
390
391        #[test]
392        fn test_i16_to_i16() {
393            check_cast::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
394            check_cast::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
395            check_cast::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
396        }
397
398        #[test]
399        fn test_i16_to_i32() {
400            check_cast::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
401            check_cast::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
402            check_cast::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
403        }
404
405        #[test]
406        fn test_i16_to_i64() {
407            check_cast::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
408            check_cast::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
409            check_cast::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
410        }
411
412        #[test]
413        fn test_i16_to_i128() {
414            check_cast::<I128<Circuit>, console_root::types::I128<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
415            check_cast::<I128<Circuit>, console_root::types::I128<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
416            check_cast::<I128<Circuit>, console_root::types::I128<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
417        }
418
419        #[test]
420        fn test_i16_to_scalar() {
421            check_cast::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(
422                Mode::Constant,
423                count_is!(0, 0, 0, 0),
424            );
425            check_cast::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
426            check_cast::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
427        }
428
429        #[test]
430        fn test_i16_to_u8() {
431            check_cast::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
432            check_cast::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
433            check_cast::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
434        }
435
436        #[test]
437        fn test_i16_to_u16() {
438            check_cast::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
439            check_cast::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
440            check_cast::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
441        }
442
443        #[test]
444        fn test_i16_to_u32() {
445            check_cast::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
446            check_cast::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
447            check_cast::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
448        }
449
450        #[test]
451        fn test_i16_to_u64() {
452            check_cast::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
453            check_cast::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
454            check_cast::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
455        }
456
457        #[test]
458        fn test_i16_to_u128() {
459            check_cast::<U128<Circuit>, console_root::types::U128<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
460            check_cast::<U128<Circuit>, console_root::types::U128<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
461            check_cast::<U128<Circuit>, console_root::types::U128<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
462        }
463    }
464
465    mod i32 {
466        use super::*;
467
468        fn sample_values(
469            i: usize,
470            mode: Mode,
471            rng: &mut TestRng,
472        ) -> (console_root::types::I32<MainnetV0>, I32<Circuit>) {
473            super::sample_values(i, mode, rng)
474        }
475
476        impl_check_cast!(cast, I32<Circuit>, console_root::types::I32<MainnetV0>);
477
478        #[test]
479        fn test_i32_to_address() {
480            check_cast::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
481                Mode::Constant,
482                count_less_than!(11, 0, 0, 0),
483            );
484            check_cast::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
485                Mode::Public,
486                count_is!(4, 0, 13, 13),
487            );
488            check_cast::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
489                Mode::Private,
490                count_is!(4, 0, 13, 13),
491            );
492        }
493
494        #[test]
495        fn test_i32_to_boolean() {
496            check_cast::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
497                Mode::Constant,
498                count_is!(64, 0, 0, 0),
499            );
500            check_cast::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
501                Mode::Public,
502                count_is!(64, 0, 5, 6),
503            );
504            check_cast::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
505                Mode::Private,
506                count_is!(64, 0, 5, 6),
507            );
508        }
509
510        #[test]
511        fn test_i32_to_field() {
512            check_cast::<Field<Circuit>, console_root::types::Field<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
513            check_cast::<Field<Circuit>, console_root::types::Field<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
514            check_cast::<Field<Circuit>, console_root::types::Field<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
515        }
516
517        #[test]
518        fn test_i32_to_group() {
519            check_cast::<Group<Circuit>, console_root::types::Group<MainnetV0>>(
520                Mode::Constant,
521                count_less_than!(11, 0, 0, 0),
522            );
523            check_cast::<Group<Circuit>, console_root::types::Group<MainnetV0>>(Mode::Public, count_is!(4, 0, 13, 13));
524            check_cast::<Group<Circuit>, console_root::types::Group<MainnetV0>>(Mode::Private, count_is!(4, 0, 13, 13));
525        }
526
527        #[test]
528        fn test_i32_to_i8() {
529            check_cast::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
530            check_cast::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 24));
531            check_cast::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 24));
532        }
533
534        #[test]
535        fn test_i32_to_i16() {
536            check_cast::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
537            check_cast::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 16));
538            check_cast::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 16));
539        }
540
541        #[test]
542        fn test_i32_to_i32() {
543            check_cast::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
544            check_cast::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
545            check_cast::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
546        }
547
548        #[test]
549        fn test_i32_to_i64() {
550            check_cast::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
551            check_cast::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
552            check_cast::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
553        }
554
555        #[test]
556        fn test_i32_to_i128() {
557            check_cast::<I128<Circuit>, console_root::types::I128<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
558            check_cast::<I128<Circuit>, console_root::types::I128<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
559            check_cast::<I128<Circuit>, console_root::types::I128<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
560        }
561
562        #[test]
563        fn test_i32_to_scalar() {
564            check_cast::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(
565                Mode::Constant,
566                count_is!(0, 0, 0, 0),
567            );
568            check_cast::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
569            check_cast::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
570        }
571
572        #[test]
573        fn test_i32_to_u8() {
574            check_cast::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
575            check_cast::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
576            check_cast::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
577        }
578
579        #[test]
580        fn test_i32_to_u16() {
581            check_cast::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
582            check_cast::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
583            check_cast::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
584        }
585
586        #[test]
587        fn test_i32_to_u32() {
588            check_cast::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
589            check_cast::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
590            check_cast::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
591        }
592
593        #[test]
594        fn test_i32_to_u64() {
595            check_cast::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
596            check_cast::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
597            check_cast::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
598        }
599
600        #[test]
601        fn test_i32_to_u128() {
602            check_cast::<U128<Circuit>, console_root::types::U128<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
603            check_cast::<U128<Circuit>, console_root::types::U128<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
604            check_cast::<U128<Circuit>, console_root::types::U128<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
605        }
606    }
607
608    mod i64 {
609        use super::*;
610
611        fn sample_values(
612            i: usize,
613            mode: Mode,
614            rng: &mut TestRng,
615        ) -> (console_root::types::I64<MainnetV0>, I64<Circuit>) {
616            super::sample_values(i, mode, rng)
617        }
618
619        impl_check_cast!(cast, I64<Circuit>, console_root::types::I64<MainnetV0>);
620
621        #[test]
622        fn test_i64_to_address() {
623            check_cast::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
624                Mode::Constant,
625                count_less_than!(11, 0, 0, 0),
626            );
627            check_cast::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
628                Mode::Public,
629                count_is!(4, 0, 13, 13),
630            );
631            check_cast::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
632                Mode::Private,
633                count_is!(4, 0, 13, 13),
634            );
635        }
636
637        #[test]
638        fn test_i64_to_boolean() {
639            check_cast::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
640                Mode::Constant,
641                count_is!(128, 0, 0, 0),
642            );
643            check_cast::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
644                Mode::Public,
645                count_is!(128, 0, 5, 6),
646            );
647            check_cast::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
648                Mode::Private,
649                count_is!(128, 0, 5, 6),
650            );
651        }
652
653        #[test]
654        fn test_i64_to_field() {
655            check_cast::<Field<Circuit>, console_root::types::Field<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
656            check_cast::<Field<Circuit>, console_root::types::Field<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
657            check_cast::<Field<Circuit>, console_root::types::Field<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
658        }
659
660        #[test]
661        fn test_i64_to_group() {
662            check_cast::<Group<Circuit>, console_root::types::Group<MainnetV0>>(
663                Mode::Constant,
664                count_less_than!(11, 0, 0, 0),
665            );
666            check_cast::<Group<Circuit>, console_root::types::Group<MainnetV0>>(Mode::Public, count_is!(4, 0, 13, 13));
667            check_cast::<Group<Circuit>, console_root::types::Group<MainnetV0>>(Mode::Private, count_is!(4, 0, 13, 13));
668        }
669
670        #[test]
671        fn test_i64_to_i8() {
672            check_cast::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
673            check_cast::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 56));
674            check_cast::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 56));
675        }
676
677        #[test]
678        fn test_i64_to_i16() {
679            check_cast::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
680            check_cast::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 48));
681            check_cast::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 48));
682        }
683
684        #[test]
685        fn test_i64_to_i32() {
686            check_cast::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
687            check_cast::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 32));
688            check_cast::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 32));
689        }
690
691        #[test]
692        fn test_i64_to_i64() {
693            check_cast::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
694            check_cast::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
695            check_cast::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
696        }
697
698        #[test]
699        fn test_i64_to_i128() {
700            check_cast::<I128<Circuit>, console_root::types::I128<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
701            check_cast::<I128<Circuit>, console_root::types::I128<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
702            check_cast::<I128<Circuit>, console_root::types::I128<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
703        }
704
705        #[test]
706        fn test_i64_to_scalar() {
707            check_cast::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(
708                Mode::Constant,
709                count_is!(0, 0, 0, 0),
710            );
711            check_cast::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
712            check_cast::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
713        }
714
715        #[test]
716        fn test_i64_to_u8() {
717            check_cast::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
718            check_cast::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
719            check_cast::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
720        }
721
722        #[test]
723        fn test_i64_to_u16() {
724            check_cast::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
725            check_cast::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
726            check_cast::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
727        }
728
729        #[test]
730        fn test_i64_to_u32() {
731            check_cast::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
732            check_cast::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
733            check_cast::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
734        }
735
736        #[test]
737        fn test_i64_to_u64() {
738            check_cast::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
739            check_cast::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
740            check_cast::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
741        }
742
743        #[test]
744        fn test_i64_to_u128() {
745            check_cast::<U128<Circuit>, console_root::types::U128<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
746            check_cast::<U128<Circuit>, console_root::types::U128<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
747            check_cast::<U128<Circuit>, console_root::types::U128<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
748        }
749    }
750
751    mod i128 {
752        use super::*;
753
754        fn sample_values(
755            i: usize,
756            mode: Mode,
757            rng: &mut TestRng,
758        ) -> (console_root::types::I128<MainnetV0>, I128<Circuit>) {
759            super::sample_values(i, mode, rng)
760        }
761
762        impl_check_cast!(cast, I128<Circuit>, console_root::types::I128<MainnetV0>);
763
764        #[test]
765        fn test_i128_to_address() {
766            check_cast::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
767                Mode::Constant,
768                count_less_than!(11, 0, 0, 0),
769            );
770            check_cast::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
771                Mode::Public,
772                count_is!(4, 0, 13, 13),
773            );
774            check_cast::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
775                Mode::Private,
776                count_is!(4, 0, 13, 13),
777            );
778        }
779
780        #[test]
781        fn test_i128_to_boolean() {
782            check_cast::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
783                Mode::Constant,
784                count_is!(256, 0, 0, 0),
785            );
786            check_cast::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
787                Mode::Public,
788                count_is!(256, 0, 5, 6),
789            );
790            check_cast::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
791                Mode::Private,
792                count_is!(256, 0, 5, 6),
793            );
794        }
795
796        #[test]
797        fn test_i128_to_field() {
798            check_cast::<Field<Circuit>, console_root::types::Field<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
799            check_cast::<Field<Circuit>, console_root::types::Field<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
800            check_cast::<Field<Circuit>, console_root::types::Field<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
801        }
802
803        #[test]
804        fn test_i128_to_group() {
805            check_cast::<Group<Circuit>, console_root::types::Group<MainnetV0>>(
806                Mode::Constant,
807                count_less_than!(11, 0, 0, 0),
808            );
809            check_cast::<Group<Circuit>, console_root::types::Group<MainnetV0>>(Mode::Public, count_is!(4, 0, 13, 13));
810            check_cast::<Group<Circuit>, console_root::types::Group<MainnetV0>>(Mode::Private, count_is!(4, 0, 13, 13));
811        }
812
813        #[test]
814        fn test_i128_to_i8() {
815            check_cast::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
816            check_cast::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 120));
817            check_cast::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 120));
818        }
819
820        #[test]
821        fn test_i128_to_i16() {
822            check_cast::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
823            check_cast::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 112));
824            check_cast::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 112));
825        }
826
827        #[test]
828        fn test_i128_to_i32() {
829            check_cast::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
830            check_cast::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 96));
831            check_cast::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 96));
832        }
833
834        #[test]
835        fn test_i128_to_i64() {
836            check_cast::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
837            check_cast::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 64));
838            check_cast::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 64));
839        }
840
841        #[test]
842        fn test_i128_to_i128() {
843            check_cast::<I128<Circuit>, console_root::types::I128<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
844            check_cast::<I128<Circuit>, console_root::types::I128<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
845            check_cast::<I128<Circuit>, console_root::types::I128<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
846        }
847
848        #[test]
849        fn test_i128_to_scalar() {
850            check_cast::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(
851                Mode::Constant,
852                count_is!(0, 0, 0, 0),
853            );
854            check_cast::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
855            check_cast::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
856        }
857
858        #[test]
859        fn test_i128_to_u8() {
860            check_cast::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
861            check_cast::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
862            check_cast::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
863        }
864
865        #[test]
866        fn test_i128_to_u16() {
867            check_cast::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
868            check_cast::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
869            check_cast::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
870        }
871
872        #[test]
873        fn test_i128_to_u32() {
874            check_cast::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
875            check_cast::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
876            check_cast::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
877        }
878
879        #[test]
880        fn test_i128_to_u64() {
881            check_cast::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
882            check_cast::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
883            check_cast::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
884        }
885
886        #[test]
887        fn test_i128_to_u128() {
888            check_cast::<U128<Circuit>, console_root::types::U128<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
889            check_cast::<U128<Circuit>, console_root::types::U128<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
890            check_cast::<U128<Circuit>, console_root::types::U128<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
891        }
892    }
893
894    mod u8 {
895        use super::*;
896
897        fn sample_values(i: usize, mode: Mode, rng: &mut TestRng) -> (console_root::types::U8<MainnetV0>, U8<Circuit>) {
898            super::sample_values(i, mode, rng)
899        }
900
901        impl_check_cast!(cast, U8<Circuit>, console_root::types::U8<MainnetV0>);
902
903        #[test]
904        fn test_u8_to_address() {
905            check_cast::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
906                Mode::Constant,
907                count_less_than!(11, 0, 0, 0),
908            );
909            check_cast::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
910                Mode::Public,
911                count_is!(4, 0, 13, 13),
912            );
913            check_cast::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
914                Mode::Private,
915                count_is!(4, 0, 13, 13),
916            );
917        }
918
919        #[test]
920        fn test_u8_to_boolean() {
921            check_cast::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
922                Mode::Constant,
923                count_is!(16, 0, 0, 0),
924            );
925            check_cast::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
926                Mode::Public,
927                count_is!(16, 0, 5, 6),
928            );
929            check_cast::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
930                Mode::Private,
931                count_is!(16, 0, 5, 6),
932            );
933        }
934
935        #[test]
936        fn test_u8_to_field() {
937            check_cast::<Field<Circuit>, console_root::types::Field<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
938            check_cast::<Field<Circuit>, console_root::types::Field<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
939            check_cast::<Field<Circuit>, console_root::types::Field<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
940        }
941
942        #[test]
943        fn test_u8_to_group() {
944            check_cast::<Group<Circuit>, console_root::types::Group<MainnetV0>>(
945                Mode::Constant,
946                count_less_than!(11, 0, 0, 0),
947            );
948            check_cast::<Group<Circuit>, console_root::types::Group<MainnetV0>>(Mode::Public, count_is!(4, 0, 13, 13));
949            check_cast::<Group<Circuit>, console_root::types::Group<MainnetV0>>(Mode::Private, count_is!(4, 0, 13, 13));
950        }
951
952        #[test]
953        fn test_u8_to_i8() {
954            check_cast::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
955            check_cast::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
956            check_cast::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
957        }
958
959        #[test]
960        fn test_u8_to_i16() {
961            check_cast::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
962            check_cast::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
963            check_cast::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
964        }
965
966        #[test]
967        fn test_u8_to_i32() {
968            check_cast::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
969            check_cast::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
970            check_cast::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
971        }
972
973        #[test]
974        fn test_u8_to_i64() {
975            check_cast::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
976            check_cast::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
977            check_cast::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
978        }
979
980        #[test]
981        fn test_u8_to_i128() {
982            check_cast::<I128<Circuit>, console_root::types::I128<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
983            check_cast::<I128<Circuit>, console_root::types::I128<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
984            check_cast::<I128<Circuit>, console_root::types::I128<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
985        }
986
987        #[test]
988        fn test_u8_to_scalar() {
989            check_cast::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(
990                Mode::Constant,
991                count_is!(0, 0, 0, 0),
992            );
993            check_cast::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
994            check_cast::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
995        }
996
997        #[test]
998        fn test_u8_to_u8() {
999            check_cast::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1000            check_cast::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1001            check_cast::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1002        }
1003
1004        #[test]
1005        fn test_u8_to_u16() {
1006            check_cast::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1007            check_cast::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1008            check_cast::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1009        }
1010
1011        #[test]
1012        fn test_u8_to_u32() {
1013            check_cast::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1014            check_cast::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1015            check_cast::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1016        }
1017
1018        #[test]
1019        fn test_u8_to_u64() {
1020            check_cast::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1021            check_cast::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1022            check_cast::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1023        }
1024
1025        #[test]
1026        fn test_u8_to_u128() {
1027            check_cast::<U128<Circuit>, console_root::types::U128<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1028            check_cast::<U128<Circuit>, console_root::types::U128<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1029            check_cast::<U128<Circuit>, console_root::types::U128<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1030        }
1031    }
1032
1033    mod u16 {
1034        use super::*;
1035
1036        fn sample_values(
1037            i: usize,
1038            mode: Mode,
1039            rng: &mut TestRng,
1040        ) -> (console_root::types::U16<MainnetV0>, U16<Circuit>) {
1041            super::sample_values(i, mode, rng)
1042        }
1043
1044        impl_check_cast!(cast, U16<Circuit>, console_root::types::U16<MainnetV0>);
1045
1046        #[test]
1047        fn test_u16_to_address() {
1048            check_cast::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
1049                Mode::Constant,
1050                count_less_than!(11, 0, 0, 0),
1051            );
1052            check_cast::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
1053                Mode::Public,
1054                count_is!(4, 0, 13, 13),
1055            );
1056            check_cast::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
1057                Mode::Private,
1058                count_is!(4, 0, 13, 13),
1059            );
1060        }
1061
1062        #[test]
1063        fn test_u16_to_boolean() {
1064            check_cast::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
1065                Mode::Constant,
1066                count_is!(32, 0, 0, 0),
1067            );
1068            check_cast::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
1069                Mode::Public,
1070                count_is!(32, 0, 5, 6),
1071            );
1072            check_cast::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
1073                Mode::Private,
1074                count_is!(32, 0, 5, 6),
1075            );
1076        }
1077
1078        #[test]
1079        fn test_u16_to_field() {
1080            check_cast::<Field<Circuit>, console_root::types::Field<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1081            check_cast::<Field<Circuit>, console_root::types::Field<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1082            check_cast::<Field<Circuit>, console_root::types::Field<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1083        }
1084
1085        #[test]
1086        fn test_u16_to_group() {
1087            check_cast::<Group<Circuit>, console_root::types::Group<MainnetV0>>(
1088                Mode::Constant,
1089                count_less_than!(11, 0, 0, 0),
1090            );
1091            check_cast::<Group<Circuit>, console_root::types::Group<MainnetV0>>(Mode::Public, count_is!(4, 0, 13, 13));
1092            check_cast::<Group<Circuit>, console_root::types::Group<MainnetV0>>(Mode::Private, count_is!(4, 0, 13, 13));
1093        }
1094
1095        #[test]
1096        fn test_u16_to_i8() {
1097            check_cast::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1098            check_cast::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
1099            check_cast::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
1100        }
1101
1102        #[test]
1103        fn test_u16_to_i16() {
1104            check_cast::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1105            check_cast::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
1106            check_cast::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
1107        }
1108
1109        #[test]
1110        fn test_u16_to_i32() {
1111            check_cast::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1112            check_cast::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1113            check_cast::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1114        }
1115
1116        #[test]
1117        fn test_u16_to_i64() {
1118            check_cast::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1119            check_cast::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1120            check_cast::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1121        }
1122
1123        #[test]
1124        fn test_u16_to_i128() {
1125            check_cast::<I128<Circuit>, console_root::types::I128<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1126            check_cast::<I128<Circuit>, console_root::types::I128<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1127            check_cast::<I128<Circuit>, console_root::types::I128<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1128        }
1129
1130        #[test]
1131        fn test_u16_to_scalar() {
1132            check_cast::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(
1133                Mode::Constant,
1134                count_is!(0, 0, 0, 0),
1135            );
1136            check_cast::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1137            check_cast::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1138        }
1139
1140        #[test]
1141        fn test_u16_to_u8() {
1142            check_cast::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1143            check_cast::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
1144            check_cast::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
1145        }
1146
1147        #[test]
1148        fn test_u16_to_u16() {
1149            check_cast::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1150            check_cast::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1151            check_cast::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1152        }
1153
1154        #[test]
1155        fn test_u16_to_u32() {
1156            check_cast::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1157            check_cast::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1158            check_cast::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1159        }
1160
1161        #[test]
1162        fn test_u16_to_u64() {
1163            check_cast::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1164            check_cast::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1165            check_cast::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1166        }
1167
1168        #[test]
1169        fn test_u16_to_u128() {
1170            check_cast::<U128<Circuit>, console_root::types::U128<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1171            check_cast::<U128<Circuit>, console_root::types::U128<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1172            check_cast::<U128<Circuit>, console_root::types::U128<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1173        }
1174    }
1175
1176    mod u32 {
1177        use super::*;
1178
1179        fn sample_values(
1180            i: usize,
1181            mode: Mode,
1182            rng: &mut TestRng,
1183        ) -> (console_root::types::U32<MainnetV0>, U32<Circuit>) {
1184            super::sample_values(i, mode, rng)
1185        }
1186
1187        impl_check_cast!(cast, U32<Circuit>, console_root::types::U32<MainnetV0>);
1188
1189        #[test]
1190        fn test_u32_to_address() {
1191            check_cast::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
1192                Mode::Constant,
1193                count_less_than!(11, 0, 0, 0),
1194            );
1195            check_cast::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
1196                Mode::Public,
1197                count_is!(4, 0, 13, 13),
1198            );
1199            check_cast::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
1200                Mode::Private,
1201                count_is!(4, 0, 13, 13),
1202            );
1203        }
1204
1205        #[test]
1206        fn test_u32_to_boolean() {
1207            check_cast::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
1208                Mode::Constant,
1209                count_is!(64, 0, 0, 0),
1210            );
1211            check_cast::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
1212                Mode::Public,
1213                count_is!(64, 0, 5, 6),
1214            );
1215            check_cast::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
1216                Mode::Private,
1217                count_is!(64, 0, 5, 6),
1218            );
1219        }
1220
1221        #[test]
1222        fn test_u32_to_field() {
1223            check_cast::<Field<Circuit>, console_root::types::Field<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1224            check_cast::<Field<Circuit>, console_root::types::Field<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1225            check_cast::<Field<Circuit>, console_root::types::Field<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1226        }
1227
1228        #[test]
1229        fn test_u32_to_group() {
1230            check_cast::<Group<Circuit>, console_root::types::Group<MainnetV0>>(
1231                Mode::Constant,
1232                count_less_than!(11, 0, 0, 0),
1233            );
1234            check_cast::<Group<Circuit>, console_root::types::Group<MainnetV0>>(Mode::Public, count_is!(4, 0, 13, 13));
1235            check_cast::<Group<Circuit>, console_root::types::Group<MainnetV0>>(Mode::Private, count_is!(4, 0, 13, 13));
1236        }
1237
1238        #[test]
1239        fn test_u32_to_i8() {
1240            check_cast::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1241            check_cast::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
1242            check_cast::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
1243        }
1244
1245        #[test]
1246        fn test_u32_to_i16() {
1247            check_cast::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1248            check_cast::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
1249            check_cast::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
1250        }
1251
1252        #[test]
1253        fn test_u32_to_i32() {
1254            check_cast::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1255            check_cast::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
1256            check_cast::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
1257        }
1258
1259        #[test]
1260        fn test_u32_to_i64() {
1261            check_cast::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1262            check_cast::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1263            check_cast::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1264        }
1265
1266        #[test]
1267        fn test_u32_to_i128() {
1268            check_cast::<I128<Circuit>, console_root::types::I128<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1269            check_cast::<I128<Circuit>, console_root::types::I128<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1270            check_cast::<I128<Circuit>, console_root::types::I128<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1271        }
1272
1273        #[test]
1274        fn test_u32_to_scalar() {
1275            check_cast::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(
1276                Mode::Constant,
1277                count_is!(0, 0, 0, 0),
1278            );
1279            check_cast::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1280            check_cast::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1281        }
1282
1283        #[test]
1284        fn test_u32_to_u8() {
1285            check_cast::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1286            check_cast::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
1287            check_cast::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
1288        }
1289
1290        #[test]
1291        fn test_u32_to_u16() {
1292            check_cast::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1293            check_cast::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
1294            check_cast::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
1295        }
1296
1297        #[test]
1298        fn test_u32_to_u32() {
1299            check_cast::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1300            check_cast::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1301            check_cast::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1302        }
1303
1304        #[test]
1305        fn test_u32_to_u64() {
1306            check_cast::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1307            check_cast::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1308            check_cast::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1309        }
1310
1311        #[test]
1312        fn test_u32_to_u128() {
1313            check_cast::<U128<Circuit>, console_root::types::U128<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1314            check_cast::<U128<Circuit>, console_root::types::U128<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1315            check_cast::<U128<Circuit>, console_root::types::U128<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1316        }
1317    }
1318
1319    mod u64 {
1320        use super::*;
1321
1322        fn sample_values(
1323            i: usize,
1324            mode: Mode,
1325            rng: &mut TestRng,
1326        ) -> (console_root::types::U64<MainnetV0>, U64<Circuit>) {
1327            super::sample_values(i, mode, rng)
1328        }
1329
1330        impl_check_cast!(cast, U64<Circuit>, console_root::types::U64<MainnetV0>);
1331
1332        #[test]
1333        fn test_u64_to_address() {
1334            check_cast::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
1335                Mode::Constant,
1336                count_less_than!(11, 0, 0, 0),
1337            );
1338            check_cast::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
1339                Mode::Public,
1340                count_is!(4, 0, 13, 13),
1341            );
1342            check_cast::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
1343                Mode::Private,
1344                count_is!(4, 0, 13, 13),
1345            );
1346        }
1347
1348        #[test]
1349        fn test_u64_to_boolean() {
1350            check_cast::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
1351                Mode::Constant,
1352                count_is!(128, 0, 0, 0),
1353            );
1354            check_cast::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
1355                Mode::Public,
1356                count_is!(128, 0, 5, 6),
1357            );
1358            check_cast::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
1359                Mode::Private,
1360                count_is!(128, 0, 5, 6),
1361            );
1362        }
1363
1364        #[test]
1365        fn test_u64_to_field() {
1366            check_cast::<Field<Circuit>, console_root::types::Field<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1367            check_cast::<Field<Circuit>, console_root::types::Field<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1368            check_cast::<Field<Circuit>, console_root::types::Field<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1369        }
1370
1371        #[test]
1372        fn test_u64_to_group() {
1373            check_cast::<Group<Circuit>, console_root::types::Group<MainnetV0>>(
1374                Mode::Constant,
1375                count_less_than!(11, 0, 0, 0),
1376            );
1377            check_cast::<Group<Circuit>, console_root::types::Group<MainnetV0>>(Mode::Public, count_is!(4, 0, 13, 13));
1378            check_cast::<Group<Circuit>, console_root::types::Group<MainnetV0>>(Mode::Private, count_is!(4, 0, 13, 13));
1379        }
1380
1381        #[test]
1382        fn test_u64_to_i8() {
1383            check_cast::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1384            check_cast::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
1385            check_cast::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
1386        }
1387
1388        #[test]
1389        fn test_u64_to_i16() {
1390            check_cast::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1391            check_cast::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
1392            check_cast::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
1393        }
1394
1395        #[test]
1396        fn test_u64_to_i32() {
1397            check_cast::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1398            check_cast::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
1399            check_cast::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
1400        }
1401
1402        #[test]
1403        fn test_u64_to_i64() {
1404            check_cast::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1405            check_cast::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
1406            check_cast::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
1407        }
1408
1409        #[test]
1410        fn test_u64_to_i128() {
1411            check_cast::<I128<Circuit>, console_root::types::I128<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1412            check_cast::<I128<Circuit>, console_root::types::I128<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1413            check_cast::<I128<Circuit>, console_root::types::I128<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1414        }
1415
1416        #[test]
1417        fn test_u64_to_scalar() {
1418            check_cast::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(
1419                Mode::Constant,
1420                count_is!(0, 0, 0, 0),
1421            );
1422            check_cast::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1423            check_cast::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1424        }
1425
1426        #[test]
1427        fn test_u64_to_u8() {
1428            check_cast::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1429            check_cast::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
1430            check_cast::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
1431        }
1432
1433        #[test]
1434        fn test_u64_to_u16() {
1435            check_cast::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1436            check_cast::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
1437            check_cast::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
1438        }
1439
1440        #[test]
1441        fn test_u64_to_u32() {
1442            check_cast::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1443            check_cast::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
1444            check_cast::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
1445        }
1446
1447        #[test]
1448        fn test_u64_to_u64() {
1449            check_cast::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1450            check_cast::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1451            check_cast::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1452        }
1453
1454        #[test]
1455        fn test_u64_to_u128() {
1456            check_cast::<U128<Circuit>, console_root::types::U128<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1457            check_cast::<U128<Circuit>, console_root::types::U128<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1458            check_cast::<U128<Circuit>, console_root::types::U128<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1459        }
1460    }
1461
1462    mod u128 {
1463        use super::*;
1464
1465        fn sample_values(
1466            i: usize,
1467            mode: Mode,
1468            rng: &mut TestRng,
1469        ) -> (console_root::types::U128<MainnetV0>, U128<Circuit>) {
1470            super::sample_values(i, mode, rng)
1471        }
1472
1473        impl_check_cast!(cast, U128<Circuit>, console_root::types::U128<MainnetV0>);
1474
1475        #[test]
1476        fn test_u128_to_address() {
1477            check_cast::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
1478                Mode::Constant,
1479                count_less_than!(11, 0, 0, 0),
1480            );
1481            check_cast::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
1482                Mode::Public,
1483                count_is!(4, 0, 13, 13),
1484            );
1485            check_cast::<Address<Circuit>, console_root::types::Address<MainnetV0>>(
1486                Mode::Private,
1487                count_is!(4, 0, 13, 13),
1488            );
1489        }
1490
1491        #[test]
1492        fn test_u128_to_boolean() {
1493            check_cast::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
1494                Mode::Constant,
1495                count_is!(256, 0, 0, 0),
1496            );
1497            check_cast::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
1498                Mode::Public,
1499                count_is!(256, 0, 5, 6),
1500            );
1501            check_cast::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(
1502                Mode::Private,
1503                count_is!(256, 0, 5, 6),
1504            );
1505        }
1506
1507        #[test]
1508        fn test_u128_to_field() {
1509            check_cast::<Field<Circuit>, console_root::types::Field<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1510            check_cast::<Field<Circuit>, console_root::types::Field<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1511            check_cast::<Field<Circuit>, console_root::types::Field<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1512        }
1513
1514        #[test]
1515        fn test_u128_to_group() {
1516            check_cast::<Group<Circuit>, console_root::types::Group<MainnetV0>>(
1517                Mode::Constant,
1518                count_less_than!(11, 0, 0, 0),
1519            );
1520            check_cast::<Group<Circuit>, console_root::types::Group<MainnetV0>>(Mode::Public, count_is!(4, 0, 13, 13));
1521            check_cast::<Group<Circuit>, console_root::types::Group<MainnetV0>>(Mode::Private, count_is!(4, 0, 13, 13));
1522        }
1523
1524        #[test]
1525        fn test_u128_to_i8() {
1526            check_cast::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1527            check_cast::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
1528            check_cast::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
1529        }
1530
1531        #[test]
1532        fn test_u128_to_i16() {
1533            check_cast::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1534            check_cast::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
1535            check_cast::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
1536        }
1537
1538        #[test]
1539        fn test_u128_to_i32() {
1540            check_cast::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1541            check_cast::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
1542            check_cast::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
1543        }
1544
1545        #[test]
1546        fn test_u128_to_i64() {
1547            check_cast::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1548            check_cast::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
1549            check_cast::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
1550        }
1551
1552        #[test]
1553        fn test_u128_to_i128() {
1554            check_cast::<I128<Circuit>, console_root::types::I128<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1555            check_cast::<I128<Circuit>, console_root::types::I128<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
1556            check_cast::<I128<Circuit>, console_root::types::I128<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
1557        }
1558
1559        #[test]
1560        fn test_u128_to_scalar() {
1561            check_cast::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(
1562                Mode::Constant,
1563                count_is!(0, 0, 0, 0),
1564            );
1565            check_cast::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1566            check_cast::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1567        }
1568
1569        #[test]
1570        fn test_u128_to_u8() {
1571            check_cast::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1572            check_cast::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
1573            check_cast::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
1574        }
1575
1576        #[test]
1577        fn test_u128_to_u16() {
1578            check_cast::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1579            check_cast::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
1580            check_cast::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
1581        }
1582
1583        #[test]
1584        fn test_u128_to_u32() {
1585            check_cast::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1586            check_cast::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
1587            check_cast::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
1588        }
1589
1590        #[test]
1591        fn test_u128_to_u64() {
1592            check_cast::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1593            check_cast::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 1));
1594            check_cast::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 1));
1595        }
1596
1597        #[test]
1598        fn test_u128_to_u128() {
1599            check_cast::<U128<Circuit>, console_root::types::U128<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
1600            check_cast::<U128<Circuit>, console_root::types::U128<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
1601            check_cast::<U128<Circuit>, console_root::types::U128<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
1602        }
1603    }
1604}