Skip to content

Commit 214fe75

Browse files
committed
dense polynomial can be defined over base field
1 parent c1619b7 commit 214fe75

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

spartan_parallel/src/dense_mlpoly.rs

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#![allow(clippy::too_many_arguments)]
22
use crate::scalar::SpartanExtensionField;
3+
use crate::dense_mlpoly::MLE::Base;
4+
use crate::dense_mlpoly::MLE::Ext;
35

46
use super::errors::ProofVerifyError;
57
use super::math::Math;
@@ -10,15 +12,31 @@ use core::ops::Index;
1012
use merlin::Transcript;
1113
use serde::{Deserialize, Serialize};
1214
use std::collections::HashMap;
15+
use ff::Field;
1316

1417
#[cfg(feature = "multicore")]
1518
use 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)]
1836
pub 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

2442
pub 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
(

spartan_parallel/src/scalar/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub trait SpartanExtensionField:
4949
type InnerType: ExtensionField + Field;
5050

5151
/// Basefield for conserving computational resources
52-
type BaseField: SmallField + for<'a> Deserialize<'a>;
52+
type BaseField: SmallField + Field + for<'a> Deserialize<'a>;
5353

5454
/// Return inner Goldilocks field element
5555
fn inner(&self) -> &Self::InnerType;

0 commit comments

Comments
 (0)