22
33use super :: * ;
44
5+ /// simple setup to get params.
56#[ allow( dead_code, clippy:: type_complexity) ]
6- fn setup ( ) -> ( Vec < AffinePoint < PlutoCurve < GF101 > > > , Vec < AffinePoint < PlutoCurve < Ext < 2 , GF101 > > > > ) {
7+ pub fn setup ( ) -> ( Vec < AffinePoint < PlutoCurve < GF101 > > > , Vec < AffinePoint < PlutoCurve < Ext < 2 , GF101 > > > > )
8+ {
79 // NOTE: For demonstration purposes only.
810
911 // This is just tau from plonk by hand, it is not actually secure
@@ -33,6 +35,28 @@ fn setup() -> (Vec<AffinePoint<PlutoCurve<GF101>>>, Vec<AffinePoint<PlutoCurve<E
3335 ( srs_g1_points, srs_g2_points)
3436}
3537
38+ /// kzg poly commit
39+ #[ allow( dead_code) ]
40+ fn commit (
41+ coefs : Vec < u32 > ,
42+ g1_srs : Vec < AffinePoint < PlutoCurve < GF101 > > > ,
43+ ) -> AffinePoint < PlutoCurve < GF101 > > {
44+ // commit to a polynomial
45+ // - given a polynomial, commit to it
46+ assert ! ( g1_srs. len( ) >= coefs. len( ) ) ;
47+ // Todo implement multiplication with field elements as scalar mult.
48+ // Maybe having the scalar mult be around the base field like colin suggested is better
49+
50+ let mut commitment = AffinePoint :: Infinity ;
51+ for ( coef, point) in coefs. iter ( ) . zip ( g1_srs) {
52+ let res = point * * coef;
53+ // println!("res {:?}, of multiplying point {:?}, and coef {:?}", res, point, coef);
54+ println ! ( "commitment {:?} before addition with {:?}" , commitment, res) ;
55+ commitment = commitment + res;
56+ }
57+ commitment
58+ }
59+
3660#[ cfg( test) ]
3761mod tests {
3862 use super :: * ;
@@ -51,6 +75,7 @@ mod tests {
5175 AffinePoint :: <PlutoCurve <GF101 >>:: new( GF101 :: new( 68 ) , GF101 :: new( 27 ) ) ,
5276 AffinePoint :: <PlutoCurve <GF101 >>:: new( GF101 :: new( 65 ) , GF101 :: new( 3 ) ) ,
5377 ] ;
78+
5479 assert_eq ! ( g1srs, expected_g1srs) ;
5580
5681 println ! ( "g2srs {:?}" , g2srs) ;
@@ -64,4 +89,33 @@ mod tests {
6489
6590 assert_eq ! ( g2srs, expected_g2srs) ;
6691 }
92+
93+ #[ test]
94+ fn test_commit ( ) {
95+ let ( g1srs, _) = setup ( ) ;
96+ // p(x) = (x-1)(x-2)(x-3)
97+ // p(x) = x^3 - 6x^2 + 11x - 6
98+ // -> -6 mod 17 is 11 so this is [1, 11, 11, 1]
99+ let coefficients = vec ! [ 11 , 11 , 11 , 1 ] ;
100+ // g1srs[0] * 11 + g1srs[1] * 11 + g1srs[2] * 11 + g1srs[3] * 1
101+ let commit_1 = commit ( coefficients, g1srs. clone ( ) ) ;
102+ assert_eq ! ( commit_1, AffinePoint :: <PlutoCurve <GF101 >>:: Infinity ) ;
103+
104+ // p(x) = (x-1)(x-2)(x-3)(x-4)
105+ // p(x) = x^4 - 10x^3 + 35x^2 - 50x + 24
106+ // -> 24 mod 17 is 7
107+ // -> 50 mod 17 is 16
108+ // -> 35 mod 17 is 1
109+ // coefficients = [7, 16, 1, 11, 1]
110+ let coefficients = vec ! [ 7 , 16 , 1 , 11 , 1 ] ;
111+ // g1srs[0] * 7 + g1srs[1] * 16 + g1srs[2] * 1 + g1srs[3] * 11 + g1srs[4] * 1
112+ let commit_2 = commit ( coefficients, g1srs. clone ( ) ) ;
113+ assert_eq ! ( commit_2, AffinePoint :: <PlutoCurve <GF101 >>:: new( GF101 :: new( 32 ) , GF101 :: new( 59 ) ) ) ;
114+
115+ // p(x) = x^2 + 2x + 3
116+ let coefficients = vec ! [ 3 , 2 , 1 ] ;
117+ // g1srs[0] * 3 + g1srs[1] * 2 + g1srs[2] * 1
118+ let commit_3 = commit ( coefficients, g1srs) ;
119+ assert_eq ! ( commit_3, AffinePoint :: <PlutoCurve <GF101 >>:: new( GF101 :: new( 32 ) , GF101 :: new( 59 ) ) ) ;
120+ }
67121}
0 commit comments