1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#![cfg_attr(test, allow(clippy::assertions_on_result_states))]
#![warn(clippy::cast_possible_truncation)]
mod arithmetic;
mod bitwise;
mod bytes;
mod from_bits;
mod from_field;
mod from_fields;
mod from_x_coordinate;
mod from_xy_coordinates;
mod parse;
mod random;
mod serialize;
mod size_in_bits;
mod size_in_bytes;
mod to_bits;
mod to_field;
mod to_fields;
mod to_x_coordinate;
mod to_xy_coordinates;
mod to_y_coordinate;
mod zero;
pub use snarkvm_console_network_environment::prelude::*;
pub use snarkvm_console_types_boolean::Boolean;
pub use snarkvm_console_types_field::Field;
pub use snarkvm_console_types_scalar::Scalar;
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
pub struct Group<E: Environment> {
group: E::Projective,
}
impl<E: Environment> GroupTrait<Scalar<E>> for Group<E> {}
impl<E: Environment> Visibility for Group<E> {
type Boolean = Boolean<E>;
fn size_in_fields(&self) -> Result<u16> {
Ok(1)
}
}
impl<E: Environment> Group<E> {
pub const EDWARDS_A: Field<E> = Field::<E>::new(E::EDWARDS_A);
pub const EDWARDS_D: Field<E> = Field::<E>::new(E::EDWARDS_D);
pub const MONTGOMERY_A: Field<E> = Field::<E>::new(E::MONTGOMERY_A);
pub const MONTGOMERY_B: Field<E> = Field::<E>::new(E::MONTGOMERY_B);
pub fn new(group: E::Affine) -> Self {
Self { group: group.into() }
}
pub fn generator() -> Self {
Self { group: E::Affine::prime_subgroup_generator().to_projective() }
}
pub fn mul_by_cofactor(&self) -> Self {
debug_assert!(E::Affine::cofactor().len() == 1 && E::Affine::cofactor()[0] == 4);
Self { group: self.group.double().double() }
}
pub fn div_by_cofactor(&self) -> Self {
Self { group: self.group.to_affine().mul_by_cofactor_inv().into() }
}
}
impl<E: Environment> Group<E> {
const fn from_projective(group: E::Projective) -> Self {
Self { group }
}
}
impl<E: Environment> TypeName for Group<E> {
#[inline]
fn type_name() -> &'static str {
"group"
}
}
impl<E: Environment> Deref for Group<E> {
type Target = E::Projective;
#[inline]
fn deref(&self) -> &Self::Target {
&self.group
}
}