Skip to content

Commit

Permalink
dense polynomial can be defined over base field
Browse files Browse the repository at this point in the history
  • Loading branch information
kunxian-xia committed Dec 4, 2024
1 parent c1619b7 commit 214fe75
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
37 changes: 31 additions & 6 deletions spartan_parallel/src/dense_mlpoly.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![allow(clippy::too_many_arguments)]
use crate::scalar::SpartanExtensionField;
use crate::dense_mlpoly::MLE::Base;
use crate::dense_mlpoly::MLE::Ext;

use super::errors::ProofVerifyError;
use super::math::Math;
Expand All @@ -10,15 +12,31 @@ use core::ops::Index;
use merlin::Transcript;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use ff::Field;

#[cfg(feature = "multicore")]
use rayon::prelude::*;

#[derive(Debug, Clone)]
pub enum MLE<S: SpartanExtensionField> {
Base(Vec<S::BaseField>),
Ext(Vec<S>),
}

impl<S: SpartanExtensionField> MLE<S> {
pub(crate) fn len(&self) -> usize {
match self {
Base(v) => v.len(),
Ext(v) => v.len(),
}
}
}

#[derive(Debug, Clone)]
pub struct DensePolynomial<S: SpartanExtensionField> {
num_vars: usize, // the number of variables in the multilinear polynomial
len: usize,
Z: Vec<S>, // evaluations of the polynomial in all the 2^num_vars Boolean inputs
Z: MLE<S>, // evaluations of the polynomial in all the 2^num_vars Boolean inputs
}

pub struct PolyCommitmentBlinds<S: SpartanExtensionField> {
Expand Down Expand Up @@ -127,7 +145,18 @@ impl<S: SpartanExtensionField> DensePolynomial<S> {
DensePolynomial {
num_vars: Z.len().log_2(),
len: Z.len(),
Z,
Z: MLE::Ext(Z),
}
}

pub fn new_from_base(mut Z: Vec<S::BaseField>) -> Self {
// If length of Z is not a power of 2, append Z with 0
let zero = S::BaseField::ZERO;
Z.extend(vec![zero; Z.len().next_power_of_two() - Z.len()]);
DensePolynomial {
num_vars: Z.len().log_2(),
len: Z.len(),
Z: MLE::Base(Z),
}
}

Expand All @@ -139,10 +168,6 @@ impl<S: SpartanExtensionField> DensePolynomial<S> {
self.len
}

pub fn clone(&self) -> DensePolynomial<S> {
DensePolynomial::new(self.Z[0..self.len].to_vec())
}

pub fn split(&self, idx: usize) -> (DensePolynomial<S>, DensePolynomial<S>) {
assert!(idx < self.len());
(
Expand Down
2 changes: 1 addition & 1 deletion spartan_parallel/src/scalar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub trait SpartanExtensionField:
type InnerType: ExtensionField + Field;

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

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

0 comments on commit 214fe75

Please sign in to comment.