@@ -5,7 +5,7 @@ use ark_std::Zero;
55use std:: ops:: Add ;
66use std:: sync:: Arc ;
77
8- use ark_std:: { rand:: Rng , UniformRand } ;
8+ use ark_std:: rand:: Rng ;
99
1010use super :: utils:: compute_sum_Mz;
1111use crate :: ccs:: CCS ;
@@ -35,13 +35,17 @@ pub struct CCCS<C: CurveGroup> {
3535 pub x : Vec < C :: ScalarField > ,
3636}
3737
38- impl < C : CurveGroup > CCS < C > {
39- pub fn to_cccs < R : Rng > (
38+ impl < F : PrimeField > CCS < F > {
39+ pub fn to_cccs < R : Rng , C : CurveGroup > (
4040 & self ,
4141 rng : & mut R ,
4242 pedersen_params : & PedersenParams < C > ,
4343 z : & [ C :: ScalarField ] ,
44- ) -> Result < ( CCCS < C > , Witness < C :: ScalarField > ) , Error > {
44+ ) -> Result < ( CCCS < C > , Witness < C :: ScalarField > ) , Error >
45+ where
46+ // enforce that CCS's F is the C::ScalarField
47+ C : CurveGroup < ScalarField = F > ,
48+ {
4549 let w: Vec < C :: ScalarField > = z[ ( 1 + self . l ) ..] . to_vec ( ) ;
4650 let r_w = C :: ScalarField :: rand ( rng) ;
4751 let C = Pedersen :: < C , true > :: commit ( pedersen_params, & w, & r_w) ?;
@@ -57,13 +61,12 @@ impl<C: CurveGroup> CCS<C> {
5761
5862 /// Computes q(x) = \sum^q c_i * \prod_{j \in S_i} ( \sum_{y \in {0,1}^s'} M_j(x, y) * z(y) )
5963 /// polynomial over x
60- pub fn compute_q ( & self , z : & Vec < C :: ScalarField > ) -> VirtualPolynomial < C :: ScalarField > {
64+ pub fn compute_q ( & self , z : & Vec < F > ) -> VirtualPolynomial < F > {
6165 let z_mle = vec_to_mle ( self . s_prime , z) ;
62- let mut q = VirtualPolynomial :: < C :: ScalarField > :: new ( self . s ) ;
66+ let mut q = VirtualPolynomial :: < F > :: new ( self . s ) ;
6367
6468 for i in 0 ..self . q {
65- let mut prod: VirtualPolynomial < C :: ScalarField > =
66- VirtualPolynomial :: < C :: ScalarField > :: new ( self . s ) ;
69+ let mut prod: VirtualPolynomial < F > = VirtualPolynomial :: < F > :: new ( self . s ) ;
6770 for j in self . S [ i] . clone ( ) {
6871 let M_j = matrix_to_mle ( self . M [ j] . clone ( ) ) ;
6972
@@ -74,11 +77,9 @@ impl<C: CurveGroup> CCS<C> {
7477 // If this is the first time we are adding something to this virtual polynomial, we need to
7578 // explicitly add the products using add_mle_list()
7679 // XXX is this true? improve API
77- prod. add_mle_list ( [ Arc :: new ( sum_Mz) ] , C :: ScalarField :: one ( ) )
78- . unwrap ( ) ;
80+ prod. add_mle_list ( [ Arc :: new ( sum_Mz) ] , F :: one ( ) ) . unwrap ( ) ;
7981 } else {
80- prod. mul_by_mle ( Arc :: new ( sum_Mz) , C :: ScalarField :: one ( ) )
81- . unwrap ( ) ;
82+ prod. mul_by_mle ( Arc :: new ( sum_Mz) , F :: one ( ) ) . unwrap ( ) ;
8283 }
8384 }
8485 // Multiply by the product by the coefficient c_i
@@ -92,11 +93,7 @@ impl<C: CurveGroup> CCS<C> {
9293 /// Computes Q(x) = eq(beta, x) * q(x)
9394 /// = eq(beta, x) * \sum^q c_i * \prod_{j \in S_i} ( \sum_{y \in {0,1}^s'} M_j(x, y) * z(y) )
9495 /// polynomial over x
95- pub fn compute_Q (
96- & self ,
97- z : & Vec < C :: ScalarField > ,
98- beta : & [ C :: ScalarField ] ,
99- ) -> VirtualPolynomial < C :: ScalarField > {
96+ pub fn compute_Q ( & self , z : & Vec < F > , beta : & [ F ] ) -> VirtualPolynomial < F > {
10097 let q = self . compute_q ( z) ;
10198 q. build_f_hat ( beta) . unwrap ( )
10299 }
@@ -107,7 +104,7 @@ impl<C: CurveGroup> CCCS<C> {
107104 pub fn check_relation (
108105 & self ,
109106 pedersen_params : & PedersenParams < C > ,
110- ccs : & CCS < C > ,
107+ ccs : & CCS < C :: ScalarField > ,
111108 w : & Witness < C :: ScalarField > ,
112109 ) -> Result < ( ) , Error > {
113110 // check that C is the commitment of w. Notice that this is not verifying a Pedersen
@@ -139,15 +136,15 @@ pub mod tests {
139136 use ark_std:: test_rng;
140137 use ark_std:: UniformRand ;
141138
142- use ark_pallas:: { Fr , Projective } ;
139+ use ark_pallas:: Fr ;
143140
144141 /// Do some sanity checks on q(x). It's a multivariable polynomial and it should evaluate to zero inside the
145142 /// hypercube, but to not-zero outside the hypercube.
146143 #[ test]
147144 fn test_compute_q ( ) {
148145 let mut rng = test_rng ( ) ;
149146
150- let ccs = get_test_ccs :: < Projective > ( ) ;
147+ let ccs = get_test_ccs :: < Fr > ( ) ;
151148 let z = get_test_z ( 3 ) ;
152149
153150 let q = ccs. compute_q ( & z) ;
@@ -167,7 +164,7 @@ pub mod tests {
167164 fn test_compute_Q ( ) {
168165 let mut rng = test_rng ( ) ;
169166
170- let ccs: CCS < Projective > = get_test_ccs ( ) ;
167+ let ccs: CCS < Fr > = get_test_ccs ( ) ;
171168 let z = get_test_z ( 3 ) ;
172169 ccs. check_relation ( & z) . unwrap ( ) ;
173170
@@ -201,7 +198,7 @@ pub mod tests {
201198 fn test_Q_against_q ( ) {
202199 let mut rng = test_rng ( ) ;
203200
204- let ccs: CCS < Projective > = get_test_ccs ( ) ;
201+ let ccs: CCS < Fr > = get_test_ccs ( ) ;
205202 let z = get_test_z ( 3 ) ;
206203 ccs. check_relation ( & z) . unwrap ( ) ;
207204
0 commit comments