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
use crate::{
templates::{
short_weierstrass_jacobian::{Affine as SWAffine, Projective as SWProjective},
twisted_edwards_extended::{Affine as TEAffine, Projective as TEProjective},
},
traits::{ProjectiveCurve, ShortWeierstrassParameters, TwistedEdwardsParameters},
};
use snarkvm_fields::{ConstraintFieldError, Field, ToConstraintField};
impl<M: TwistedEdwardsParameters, F: Field> ToConstraintField<F> for TEAffine<M>
where
M::BaseField: ToConstraintField<F>,
{
#[inline]
fn to_field_elements(&self) -> Result<Vec<F>, ConstraintFieldError> {
let mut x_fe = self.x.to_field_elements()?;
let y_fe = self.y.to_field_elements()?;
x_fe.extend_from_slice(&y_fe);
Ok(x_fe)
}
}
impl<M: TwistedEdwardsParameters, F: Field> ToConstraintField<F> for TEProjective<M>
where
M::BaseField: ToConstraintField<F>,
{
#[inline]
fn to_field_elements(&self) -> Result<Vec<F>, ConstraintFieldError> {
let affine = self.to_affine();
let mut x_fe = affine.x.to_field_elements()?;
let y_fe = affine.y.to_field_elements()?;
x_fe.extend_from_slice(&y_fe);
Ok(x_fe)
}
}
impl<M: ShortWeierstrassParameters, F: Field> ToConstraintField<F> for SWAffine<M>
where
M::BaseField: ToConstraintField<F>,
{
#[inline]
fn to_field_elements(&self) -> Result<Vec<F>, ConstraintFieldError> {
let mut x_fe = self.x.to_field_elements()?;
let y_fe = self.y.to_field_elements()?;
let infinity_fe = self.infinity.to_field_elements()?;
x_fe.extend_from_slice(&y_fe);
x_fe.extend_from_slice(&infinity_fe);
Ok(x_fe)
}
}
impl<M: ShortWeierstrassParameters, F: Field> ToConstraintField<F> for SWProjective<M>
where
M::BaseField: ToConstraintField<F>,
{
#[inline]
fn to_field_elements(&self) -> Result<Vec<F>, ConstraintFieldError> {
let affine = self.to_affine();
let mut x_fe = affine.x.to_field_elements()?;
let y_fe = affine.y.to_field_elements()?;
x_fe.extend_from_slice(&y_fe);
Ok(x_fe)
}
}