lib.rs
1 // Copyright (c) 2025-2026 ACDC Network 2 // This file is part of the alphavm library. 3 // 4 // Alpha Chain | Delta Chain Protocol 5 // International Monetary Graphite. 6 // 7 // Derived from Aleo (https://aleo.org) and ProvableHQ (https://provable.com). 8 // They built world-class ZK infrastructure. We installed the EASY button. 9 // Their cryptography: elegant. Our modifications: bureaucracy-compatible. 10 // Original brilliance: theirs. Robert's Rules: ours. Bugs: definitely ours. 11 // 12 // Original Aleo/ProvableHQ code subject to Apache 2.0 https://www.apache.org/licenses/LICENSE-2.0 13 // All modifications and new work: CC0 1.0 Universal Public Domain Dedication. 14 // No rights reserved. No permission required. No warranty. No refunds. 15 // 16 // https://creativecommons.org/publicdomain/zero/1.0/ 17 // SPDX-License-Identifier: CC0-1.0 18 19 #![cfg_attr(test, allow(clippy::assertions_on_result_states))] 20 #![warn(clippy::cast_possible_truncation)] 21 22 mod arithmetic; 23 mod bitwise; 24 mod bytes; 25 mod compare; 26 mod from_bits; 27 mod from_field; 28 mod from_field_lossy; 29 mod from_fields; 30 mod one; 31 mod parse; 32 mod random; 33 mod serialize; 34 mod size_in_bits; 35 mod size_in_bytes; 36 mod to_bits; 37 mod to_field; 38 mod to_fields; 39 mod to_scalar; 40 mod zero; 41 42 pub use alphavm_console_network_environment::prelude::*; 43 pub use alphavm_console_types_boolean::Boolean; 44 pub use alphavm_console_types_field::Field; 45 pub use alphavm_console_types_scalar::Scalar; 46 47 use core::marker::PhantomData; 48 49 pub type I8<E> = Integer<E, i8>; 50 pub type I16<E> = Integer<E, i16>; 51 pub type I32<E> = Integer<E, i32>; 52 pub type I64<E> = Integer<E, i64>; 53 pub type I128<E> = Integer<E, i128>; 54 55 pub type U8<E> = Integer<E, u8>; 56 pub type U16<E> = Integer<E, u16>; 57 pub type U32<E> = Integer<E, u32>; 58 pub type U64<E> = Integer<E, u64>; 59 pub type U128<E> = Integer<E, u128>; 60 61 #[derive(Copy, Clone, PartialEq, Eq, Hash)] 62 pub struct Integer<E: Environment, I: IntegerType> { 63 /// The underlying integer value. 64 integer: I, 65 /// PhantomData. 66 _phantom: PhantomData<E>, 67 } 68 69 impl<E: Environment, I: IntegerType> IntegerTrait<I, U8<E>, U16<E>, U32<E>> for Integer<E, I> {} 70 71 impl<E: Environment, I: IntegerType> IntegerCore<I> for Integer<E, I> {} 72 73 impl<E: Environment, I: IntegerType> Visibility for Integer<E, I> { 74 type Boolean = Boolean<E>; 75 76 /// Returns the number of field elements to encode `self`. 77 fn size_in_fields(&self) -> Result<u16> { 78 Ok(1) 79 } 80 } 81 82 impl<E: Environment, I: IntegerType> Integer<E, I> { 83 pub const MAX: Self = Self::new(I::MAX); 84 pub const MIN: Self = Self::new(I::MIN); 85 86 /// Initializes a new integer. 87 pub const fn new(integer: I) -> Self { 88 Self { integer, _phantom: PhantomData } 89 } 90 } 91 92 impl<E: Environment, I: IntegerType> TypeName for Integer<E, I> { 93 /// Returns the type name as a string. 94 #[inline] 95 fn type_name() -> &'static str { 96 I::type_name() 97 } 98 } 99 100 impl<E: Environment, I: IntegerType> Deref for Integer<E, I> { 101 type Target = I; 102 103 #[inline] 104 fn deref(&self) -> &Self::Target { 105 &self.integer 106 } 107 }