to_bits.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 use super::*; 20 21 impl<N: Network> ToBits for Future<N> { 22 /// Returns the future as a list of **little-endian** bits. 23 #[inline] 24 fn write_bits_le(&self, vec: &mut Vec<bool>) { 25 // Write the bits for the program ID. 26 let program_id_bits = self.program_id.to_bits_le(); 27 u16::try_from(program_id_bits.len()).or_halt_with::<N>("Program ID exceeds u16::MAX bits").write_bits_le(vec); 28 vec.extend_from_slice(&program_id_bits); 29 30 // Write the bits for the function name. 31 let function_name_bits = self.function_name.to_bits_le(); 32 u16::try_from(function_name_bits.len()) 33 .or_halt_with::<N>("Function name exceeds u16::MAX bits") 34 .write_bits_le(vec); 35 vec.extend_from_slice(&function_name_bits); 36 37 // Write the number of arguments. 38 u8::try_from(self.arguments.len()).or_halt_with::<N>("arguments exceed u8::MAX").write_bits_le(vec); 39 40 // Write the arguments. 41 for argument in &self.arguments { 42 let argument_bits = argument.to_bits_le(); 43 44 // Write the size of the argument. 45 u16::try_from(argument_bits.len()).or_halt_with::<N>("argument exceeds u16::MAX bits").write_bits_le(vec); 46 47 // Write the argument. 48 vec.extend_from_slice(&argument_bits); 49 } 50 } 51 52 /// Returns the future as a list of **big-endian** bits. 53 #[inline] 54 fn write_bits_be(&self, vec: &mut Vec<bool>) { 55 // Write the bits for the program ID. 56 let program_id_bits = self.program_id.to_bits_be(); 57 u16::try_from(program_id_bits.len()).or_halt_with::<N>("Program ID exceeds u16::MAX bits").write_bits_be(vec); 58 vec.extend_from_slice(&program_id_bits); 59 60 // Write the bits for the function name. 61 let function_name_bits = self.function_name.to_bits_be(); 62 u16::try_from(function_name_bits.len()) 63 .or_halt_with::<N>("Function name exceeds u16::MAX bits") 64 .write_bits_be(vec); 65 vec.extend_from_slice(&function_name_bits); 66 67 // Write the number of arguments. 68 u8::try_from(self.arguments.len()).or_halt_with::<N>("arguments exceed u8::MAX").write_bits_be(vec); 69 70 // Write the arguments. 71 for argument in &self.arguments { 72 let argument_bits = argument.to_bits_be(); 73 74 // Write the size of the argument. 75 u16::try_from(argument_bits.len()).or_halt_with::<N>("argument exceeds u16::MAX bits").write_bits_be(vec); 76 77 // Write the argument. 78 vec.extend_from_slice(&argument_bits); 79 } 80 } 81 }