11#![ allow( clippy:: too_many_arguments) ]
22use crate :: scalar:: SpartanExtensionField ;
3+ use crate :: dense_mlpoly:: MLE :: Base ;
4+ use crate :: dense_mlpoly:: MLE :: Ext ;
35
46use super :: errors:: ProofVerifyError ;
57use super :: math:: Math ;
@@ -10,15 +12,31 @@ use core::ops::Index;
1012use merlin:: Transcript ;
1113use serde:: { Deserialize , Serialize } ;
1214use std:: collections:: HashMap ;
15+ use ff:: Field ;
1316
1417#[ cfg( feature = "multicore" ) ]
1518use rayon:: prelude:: * ;
1619
20+ #[ derive( Debug , Clone ) ]
21+ pub enum MLE < S : SpartanExtensionField > {
22+ Base ( Vec < S :: BaseField > ) ,
23+ Ext ( Vec < S > ) ,
24+ }
25+
26+ impl < S : SpartanExtensionField > MLE < S > {
27+ pub ( crate ) fn len ( & self ) -> usize {
28+ match self {
29+ Base ( v) => v. len ( ) ,
30+ Ext ( v) => v. len ( ) ,
31+ }
32+ }
33+ }
34+
1735#[ derive( Debug , Clone ) ]
1836pub struct DensePolynomial < S : SpartanExtensionField > {
1937 num_vars : usize , // the number of variables in the multilinear polynomial
2038 len : usize ,
21- Z : Vec < S > , // evaluations of the polynomial in all the 2^num_vars Boolean inputs
39+ Z : MLE < S > , // evaluations of the polynomial in all the 2^num_vars Boolean inputs
2240}
2341
2442pub struct PolyCommitmentBlinds < S : SpartanExtensionField > {
@@ -127,7 +145,18 @@ impl<S: SpartanExtensionField> DensePolynomial<S> {
127145 DensePolynomial {
128146 num_vars : Z . len ( ) . log_2 ( ) ,
129147 len : Z . len ( ) ,
130- Z ,
148+ Z : MLE :: Ext ( Z ) ,
149+ }
150+ }
151+
152+ pub fn new_from_base ( mut Z : Vec < S :: BaseField > ) -> Self {
153+ // If length of Z is not a power of 2, append Z with 0
154+ let zero = S :: BaseField :: ZERO ;
155+ Z . extend ( vec ! [ zero; Z . len( ) . next_power_of_two( ) - Z . len( ) ] ) ;
156+ DensePolynomial {
157+ num_vars : Z . len ( ) . log_2 ( ) ,
158+ len : Z . len ( ) ,
159+ Z : MLE :: Base ( Z ) ,
131160 }
132161 }
133162
@@ -139,10 +168,6 @@ impl<S: SpartanExtensionField> DensePolynomial<S> {
139168 self . len
140169 }
141170
142- pub fn clone ( & self ) -> DensePolynomial < S > {
143- DensePolynomial :: new ( self . Z [ 0 ..self . len ] . to_vec ( ) )
144- }
145-
146171 pub fn split ( & self , idx : usize ) -> ( DensePolynomial < S > , DensePolynomial < S > ) {
147172 assert ! ( idx < self . len( ) ) ;
148173 (
0 commit comments