@@ -3,26 +3,27 @@ use std::borrow::Borrow;
3
3
use std:: ops:: { Add , AddAssign , Sub , SubAssign } ;
4
4
5
5
use ark_ec:: { twisted_edwards:: TECurveConfig , AffineRepr } ;
6
- use ark_ed_on_bls12_377:: {
7
- constraints:: { EdwardsVar , FqVar } ,
8
- EdwardsAffine , EdwardsConfig ,
9
- } ;
6
+ use ark_ed_on_bls12_377:: constraints:: FqVar ;
10
7
use ark_r1cs_std:: {
11
8
alloc:: AllocVar , eq:: EqGadget , groups:: curves:: twisted_edwards:: AffineVar , prelude:: * , R1CSVar ,
12
9
} ;
13
10
use ark_relations:: ns;
14
11
use ark_relations:: r1cs:: { ConstraintSystemRef , SynthesisError } ;
15
12
13
+ use crate :: element:: EdwardsAffine ;
14
+ use crate :: Decaf377EdwardsConfig ;
16
15
use crate :: { constants:: ZETA , r1cs:: fqvar_ext:: FqVarExtension , AffineElement , Element , Fq } ;
17
16
17
+ pub ( crate ) type Decaf377EdwardsVar = AffineVar < Decaf377EdwardsConfig , FqVar > ;
18
+
18
19
#[ derive( Clone , Debug ) ]
19
20
/// Represents the R1CS equivalent of a `decaf377::Element`
20
21
///
21
22
/// Generally the suffix -`Var` will indicate that the type or variable
22
23
/// represents in R1CS.
23
24
pub struct ElementVar {
24
25
/// Inner type is an alias for `AffineVar<EdwardsConfig, FqVar>`
25
- pub ( crate ) inner : EdwardsVar ,
26
+ pub ( crate ) inner : Decaf377EdwardsVar ,
26
27
}
27
28
28
29
impl ElementVar {
@@ -38,8 +39,10 @@ impl ElementVar {
38
39
let Z_var = FqVar :: one ( ) ;
39
40
let T_var = X_var * Y_var ;
40
41
41
- let A_MINUS_D_VAR =
42
- FqVar :: new_constant ( self . cs ( ) , EdwardsConfig :: COEFF_A - EdwardsConfig :: COEFF_D ) ?;
42
+ let A_MINUS_D_VAR = FqVar :: new_constant (
43
+ self . cs ( ) ,
44
+ Decaf377EdwardsConfig :: COEFF_A - Decaf377EdwardsConfig :: COEFF_D ,
45
+ ) ?;
43
46
44
47
// 1.
45
48
let u_1_var = ( X_var . clone ( ) + T_var . clone ( ) ) * ( X_var . clone ( ) - T_var . clone ( ) ) ;
@@ -62,7 +65,7 @@ impl ElementVar {
62
65
63
66
/// R1CS equivalent of `Encoding::vartime_decompress`
64
67
pub fn decompress_from_field ( s_var : FqVar ) -> Result < ElementVar , SynthesisError > {
65
- let D4 : Fq = EdwardsConfig :: COEFF_D * Fq :: from ( 4u32 ) ;
68
+ let D4 : Fq = Decaf377EdwardsConfig :: COEFF_D * Fq :: from ( 4u32 ) ;
66
69
let D4_VAR = FqVar :: constant ( D4 ) ;
67
70
68
71
// 1. We do not check if canonically encoded here since we know FqVar is already
@@ -107,8 +110,8 @@ impl ElementVar {
107
110
pub ( crate ) fn elligator_map ( r_0_var : & FqVar ) -> Result < ElementVar , SynthesisError > {
108
111
let cs = r_0_var. cs ( ) ;
109
112
110
- let A_VAR = FqVar :: new_constant ( cs. clone ( ) , EdwardsConfig :: COEFF_A ) ?;
111
- let D_VAR = FqVar :: new_constant ( cs. clone ( ) , EdwardsConfig :: COEFF_D ) ?;
113
+ let A_VAR = FqVar :: new_constant ( cs. clone ( ) , Decaf377EdwardsConfig :: COEFF_A ) ?;
114
+ let D_VAR = FqVar :: new_constant ( cs. clone ( ) , Decaf377EdwardsConfig :: COEFF_D ) ?;
112
115
let ZETA_VAR = FqVar :: new_constant ( cs, * ZETA ) ?;
113
116
114
117
let r_var = ZETA_VAR * r_0_var. square ( ) ?;
@@ -219,7 +222,7 @@ impl CondSelectGadget<Fq> for ElementVar {
219
222
let y = cond. select ( & true_value. inner . y , & false_value. inner . y ) ?;
220
223
221
224
Ok ( ElementVar {
222
- inner : EdwardsVar :: new ( x, y) ,
225
+ inner : Decaf377EdwardsVar :: new ( x, y) ,
223
226
} )
224
227
}
225
228
}
@@ -244,7 +247,7 @@ impl AllocVar<Element, Fq> for ElementVar {
244
247
// where they check that the point is in the right subgroup prior to witnessing.
245
248
match mode {
246
249
AllocationMode :: Constant => Ok ( Self {
247
- inner : EdwardsVar :: new_variable_omit_prime_order_check (
250
+ inner : Decaf377EdwardsVar :: new_variable_omit_prime_order_check (
248
251
cs,
249
252
|| Ok ( group_projective_point. inner ) ,
250
253
mode,
@@ -254,7 +257,6 @@ impl AllocVar<Element, Fq> for ElementVar {
254
257
unreachable ! ( )
255
258
}
256
259
AllocationMode :: Witness => {
257
- //let ge: EdwardsAffine = group_projective_point.inner.into();
258
260
let P_var = AffineVar :: new_variable_omit_prime_order_check (
259
261
ns ! ( cs, "P_affine" ) ,
260
262
|| Ok ( group_projective_point. inner ) ,
@@ -410,13 +412,13 @@ impl<'a> GroupOpsBounds<'a, Element, ElementVar> for ElementVar {}
410
412
impl CurveVar < Element , Fq > for ElementVar {
411
413
fn zero ( ) -> Self {
412
414
Self {
413
- inner : AffineVar :: < EdwardsConfig , FqVar > :: zero ( ) ,
415
+ inner : AffineVar :: < Decaf377EdwardsConfig , FqVar > :: zero ( ) ,
414
416
}
415
417
}
416
418
417
419
fn constant ( other : Element ) -> Self {
418
420
Self {
419
- inner : AffineVar :: < EdwardsConfig , FqVar > :: constant ( other. inner ) ,
421
+ inner : AffineVar :: < Decaf377EdwardsConfig , FqVar > :: constant ( other. inner ) ,
420
422
}
421
423
}
422
424
0 commit comments