Skip to main content

snarkvm_console_program/data/dynamic/future/
to_bits.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<N: Network> ToBits for DynamicFuture<N> {
19    /// Returns the dynamic future as a list of **little-endian** bits.
20    #[inline]
21    fn write_bits_le(&self, vec: &mut Vec<bool>) {
22        // Write the bits for the program name.
23        self.program_name.write_bits_le(vec);
24
25        // Write the bits for the program network.
26        self.program_network.write_bits_le(vec);
27
28        // Write the bits for the function name.
29        self.function_name.write_bits_le(vec);
30
31        // Write the bits for the checksum.
32        self.checksum.write_bits_le(vec);
33    }
34
35    /// Returns the dynamic future as a list of **big-endian** bits.
36    #[inline]
37    fn write_bits_be(&self, vec: &mut Vec<bool>) {
38        // Write the bits for the program name.
39        self.program_name.write_bits_be(vec);
40
41        // Write the bits for the program network.
42        self.program_network.write_bits_be(vec);
43
44        // Write the bits for the function name.
45        self.function_name.write_bits_be(vec);
46
47        // Write the bits for the checksum.
48        self.checksum.write_bits_be(vec);
49    }
50}
51
52impl<N: Network> DynamicFuture<N> {
53    /// Returns the number of bits in a dynamic future.
54    #[inline]
55    pub fn size_in_bits() -> Result<usize> {
56        // A dynamic future contains 4 field elements: program_name, program_network, function_name, and checksum.
57        Field::<N>::size_in_bits().checked_mul(4).ok_or_else(|| anyhow!("`size_in_bits` overflowed"))
58    }
59
60    /// Returns the number of raw bits in a dynamic future.
61    #[inline]
62    pub fn size_in_bits_raw() -> Result<usize> {
63        Self::size_in_bits()
64    }
65}