Skip to main content

snarkvm_console_types_address/
to_group.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> Address<E> {
19    /// Returns the address as a group element.
20    pub const fn to_group(&self) -> &Group<E> {
21        &self.address
22    }
23}
24
25#[cfg(test)]
26mod tests {
27    use super::*;
28    use snarkvm_console_network_environment::Console;
29
30    type CurrentEnvironment = Console;
31
32    const ITERATIONS: u64 = 10_000;
33
34    #[test]
35    fn test_to_group() -> Result<()> {
36        let mut rng = TestRng::default();
37
38        for _ in 0..ITERATIONS {
39            // Sample a random value.
40            let address = Address::<CurrentEnvironment>::rand(&mut rng);
41
42            let candidate = address.to_group();
43
44            let expected = address.to_bits_le();
45            for (index, candidate_bit) in candidate.to_bits_le().iter().enumerate() {
46                assert_eq!(expected[index], *candidate_bit);
47            }
48        }
49        Ok(())
50    }
51}