Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/1d shout #568

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jolt-core/src/jolt/vm/read_write_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::lasso::memory_checking::{
ExogenousOpenings, Initializable, StructuredPolynomialData, VerifierComputedOpening,
};
use crate::poly::compact_polynomial::{CompactPolynomial, SmallScalar};
use crate::poly::multilinear_polynomial::MultilinearPolynomial;
use crate::poly::multilinear_polynomial::{MultilinearPolynomial, PolynomialEvaluation};
use crate::poly::opening_proof::{ProverOpeningAccumulator, VerifierOpeningAccumulator};
use crate::utils::thread::unsafe_allocate_zero_vec;
use rayon::prelude::*;
Expand Down
2 changes: 1 addition & 1 deletion jolt-core/src/lasso/surge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
poly::{
commitment::commitment_scheme::BatchType,
compact_polynomial::{CompactPolynomial, SmallScalar},
multilinear_polynomial::MultilinearPolynomial,
multilinear_polynomial::{MultilinearPolynomial, PolynomialEvaluation},
opening_proof::{ProverOpeningAccumulator, VerifierOpeningAccumulator},
},
};
Expand Down
114 changes: 107 additions & 7 deletions jolt-core/src/poly/identity_poly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,120 @@

use crate::utils::math::Math;

pub struct IdentityPolynomial {
size_point: usize,
use super::multilinear_polynomial::{BindingOrder, PolynomialBinding, PolynomialEvaluation};

pub struct IdentityPolynomial<F: JoltField> {
num_vars: usize,
num_bound_vars: usize,
bound_value: F,
}

impl<F: JoltField> IdentityPolynomial<F> {
pub fn new(num_vars: usize) -> Self {
IdentityPolynomial {
num_vars,
num_bound_vars: 0,
bound_value: F::zero(),
}
}
}

impl IdentityPolynomial {
pub fn new(size_point: usize) -> Self {
IdentityPolynomial { size_point }
impl<F: JoltField> PolynomialBinding<F> for IdentityPolynomial<F> {
fn is_bound(&self) -> bool {
self.num_bound_vars != 0
}

fn bind(&mut self, r: F, order: BindingOrder) {
debug_assert!(self.num_bound_vars < self.num_vars);
debug_assert_eq!(
order,
BindingOrder::LowToHigh,
"IdentityPolynomial only supports low-to-high binding"
);

self.bound_value += F::from_u32(1u32 << self.num_bound_vars) * r;
self.num_bound_vars += 1;
}

fn final_sumcheck_claim(&self) -> F {
debug_assert_eq!(self.num_vars, self.num_bound_vars);
self.bound_value
}
}

pub fn evaluate<F: JoltField>(&self, r: &[F]) -> F {
impl<F: JoltField> PolynomialEvaluation<F> for IdentityPolynomial<F> {
fn evaluate(&self, r: &[F]) -> F {
let len = r.len();
assert_eq!(len, self.size_point);
assert_eq!(len, self.num_vars);
(0..len)
.map(|i| F::from_u64((len - i - 1).pow2() as u64) * r[i])
.sum()
}

fn batch_evaluate(polys: &[&Self], r: &[F]) -> (Vec<F>, Vec<F>) {

Check failure on line 55 in jolt-core/src/poly/identity_poly.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `polys`

Check failure on line 55 in jolt-core/src/poly/identity_poly.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `r`

Check failure on line 55 in jolt-core/src/poly/identity_poly.rs

View workflow job for this annotation

GitHub Actions / Build Wasm

unused variable: `polys`

Check failure on line 55 in jolt-core/src/poly/identity_poly.rs

View workflow job for this annotation

GitHub Actions / Build Wasm

unused variable: `r`

Check failure on line 55 in jolt-core/src/poly/identity_poly.rs

View workflow job for this annotation

GitHub Actions / Onchain Verifier Tests

unused variable: `polys`

Check failure on line 55 in jolt-core/src/poly/identity_poly.rs

View workflow job for this annotation

GitHub Actions / Onchain Verifier Tests

unused variable: `r`

Check failure on line 55 in jolt-core/src/poly/identity_poly.rs

View workflow job for this annotation

GitHub Actions / test

unused variable: `polys`

Check failure on line 55 in jolt-core/src/poly/identity_poly.rs

View workflow job for this annotation

GitHub Actions / test

unused variable: `r`
todo!()
}

fn sumcheck_evals(&self, index: usize, degree: usize, order: BindingOrder) -> Vec<F> {
debug_assert!(degree > 0);
debug_assert!(index < self.num_vars.pow2() / 2);
debug_assert_eq!(
order,
BindingOrder::LowToHigh,
"IdentityPolynomial only supports low-to-high binding"
);

let mut evals = vec![F::zero(); degree];
evals[0] = self.bound_value + F::from_u64((index as u64) << (1 + self.num_bound_vars));
let m = F::from_u32(1 << self.num_bound_vars);
let mut eval = evals[0] + m;
for i in 1..degree {
eval += m;
evals[i] = eval;
}
evals
}
}

#[cfg(test)]
mod tests {
use crate::poly::multilinear_polynomial::MultilinearPolynomial;

use super::*;
use ark_bn254::Fr;
use ark_std::test_rng;

#[test]
fn identity_poly() {
const NUM_VARS: usize = 10;

let mut rng = test_rng();
let mut identity_poly: IdentityPolynomial<Fr> = IdentityPolynomial::new(NUM_VARS);
let mut reference_poly: MultilinearPolynomial<Fr> =
MultilinearPolynomial::from((0..(1 << NUM_VARS)).map(|i| i as u32).collect::<Vec<_>>());

for j in 0..reference_poly.len() / 2 {
let identity_poly_evals = identity_poly.sumcheck_evals(j, 3, BindingOrder::LowToHigh);
let reference_poly_evals = reference_poly.sumcheck_evals(j, 3, BindingOrder::LowToHigh);
assert_eq!(identity_poly_evals, reference_poly_evals);
}

for _ in 0..NUM_VARS {
let r = Fr::random(&mut rng);
identity_poly.bind(r, BindingOrder::LowToHigh);
reference_poly.bind(r, BindingOrder::LowToHigh);
for j in 0..reference_poly.len() / 2 {
let identity_poly_evals =
identity_poly.sumcheck_evals(j, 3, BindingOrder::LowToHigh);
let reference_poly_evals =
reference_poly.sumcheck_evals(j, 3, BindingOrder::LowToHigh);
assert_eq!(identity_poly_evals, reference_poly_evals);
}
}

assert_eq!(
identity_poly.final_sumcheck_claim(),
reference_poly.final_sumcheck_claim()
);
}
}
1 change: 1 addition & 0 deletions jolt-core/src/poly/multilinear_polynomial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub enum MultilinearPolynomial<F: JoltField> {
}

/// The order in which polynomial variables are bound in sumcheck
#[derive(Debug, PartialEq)]
pub enum BindingOrder {
LowToHigh,
HighToLow,
Expand Down
1 change: 1 addition & 0 deletions jolt-core/src/subprotocols/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

pub mod grand_product;
pub mod grand_product_quarks;
pub mod shout;
pub mod sparse_grand_product;
pub mod sumcheck;

Expand Down
Loading
Loading