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

[DO NOT MERGE] Binius Spartan #428

Draft
wants to merge 2 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
19 changes: 19 additions & 0 deletions jolt-core/src/benches/bench.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::field::binius::BiniusField;
use crate::field::JoltField;
use crate::host;
use crate::jolt::vm::rv32i_vm::{RV32IJoltVM, C, M};
Expand All @@ -6,14 +7,17 @@ use crate::poly::commitment::commitment_scheme::CommitmentScheme;
use crate::poly::commitment::hyperkzg::HyperKZG;
use crate::poly::commitment::hyrax::HyraxScheme;
use crate::poly::commitment::zeromorph::Zeromorph;
use crate::r1cs::spartan;
use ark_bn254::{Bn254, Fr, G1Projective};
use binius_field::BinaryField128bPolyval;
use serde::Serialize;

#[derive(Debug, Copy, Clone, clap::ValueEnum)]
pub enum PCSType {
Hyrax,
Zeromorph,
HyperKZG,
Binius
}

#[derive(Debug, Copy, Clone, clap::ValueEnum)]
Expand All @@ -22,6 +26,7 @@ pub enum BenchType {
Sha2,
Sha3,
Sha2Chain,
Spartan,
}

#[allow(unreachable_patterns)] // good errors on new BenchTypes
Expand All @@ -38,13 +43,15 @@ pub fn benchmarks(
BenchType::Sha3 => sha3::<Fr, HyraxScheme<G1Projective>>(),
BenchType::Sha2Chain => sha2chain::<Fr, HyraxScheme<G1Projective>>(),
BenchType::Fibonacci => fibonacci::<Fr, HyraxScheme<G1Projective>>(),
BenchType::Spartan => spartan::<Fr>(),
_ => panic!("BenchType does not have a mapping"),
},
PCSType::Zeromorph => match bench_type {
BenchType::Sha2 => sha2::<Fr, Zeromorph<Bn254>>(),
BenchType::Sha3 => sha3::<Fr, Zeromorph<Bn254>>(),
BenchType::Sha2Chain => sha2chain::<Fr, Zeromorph<Bn254>>(),
BenchType::Fibonacci => fibonacci::<Fr, Zeromorph<Bn254>>(),
BenchType::Spartan => spartan::<BiniusField<BinaryField128bPolyval>>(),
_ => panic!("BenchType does not have a mapping"),
},
PCSType::HyperKZG => match bench_type {
Expand Down Expand Up @@ -82,6 +89,18 @@ where
prove_example::<Vec<u8>, PCS, F>("sha3-guest", &vec![5u8; 2048])
}

fn spartan<F>() -> Vec<(tracing::Span, Box<dyn FnOnce()>)>
where
F: JoltField,
{
let task = move || {
spartan::bench::bench::<F>();
};

vec![(tracing::info_span!("Spartan"), Box::new(task))]

}

#[allow(dead_code)]
fn serialize_and_print_size(name: &str, item: &impl ark_serialize::CanonicalSerialize) {
use std::fs::File;
Expand Down
2 changes: 1 addition & 1 deletion jolt-core/src/poly/commitment/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ pub mod kzg;
pub mod pedersen;
pub mod zeromorph;

#[cfg(test)]
// #[cfg(test)]
pub mod mock;
1 change: 1 addition & 0 deletions jolt-core/src/poly/dense_mlpoly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ impl<F: JoltField> DensePolynomial<F> {
self.len = n;
}

#[tracing::instrument(skip_all)]
pub fn bound_poly_var_top_par(&mut self, r: &F) {
let n = self.len() / 2;
let (left, right) = self.Z.split_at_mut(n);
Expand Down
31 changes: 17 additions & 14 deletions jolt-core/src/poly/unipoly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ impl<F: JoltField> UniPoly<F> {

fn vandermonde_interpolation(evals: &[F]) -> Vec<F> {
let n = evals.len();
let xs: Vec<F> = (0..n).map(|x| F::from_u64(x as u64).unwrap()).collect();
// TODO(sragss): Prolly broken for Binius.
let xs: Vec<F> = (0..n).map(|x: usize| F::from_u64(x as u64).unwrap()).collect();

let mut vandermonde: Vec<Vec<F>> = Vec::with_capacity(n);
for i in 0..n {
Expand Down Expand Up @@ -127,10 +128,11 @@ impl<F: JoltField> UniPoly<F> {
}

pub fn compress(&self) -> CompressedUniPoly<F> {
let coeffs_except_linear_term = [&self.coeffs[..1], &self.coeffs[2..]].concat();
debug_assert_eq!(coeffs_except_linear_term.len() + 1, self.coeffs.len());
// TODO(sragss): Bring back compression.
// let coeffs_except_linear_term = [&self.coeffs[..1], &self.coeffs[2..]].concat();
// debug_assert_eq!(coeffs_except_linear_term.len() + 1, self.coeffs.len());
CompressedUniPoly {
coeffs_except_linear_term,
coeffs_except_linear_term: self.coeffs.clone(),
}
}

Expand Down Expand Up @@ -211,16 +213,17 @@ impl<F: JoltField> CompressedUniPoly<F> {
// we require eval(0) + eval(1) = hint, so we can solve for the linear term as:
// linear_term = hint - 2 * constant_term - deg2 term - deg3 term
pub fn decompress(&self, hint: &F) -> UniPoly<F> {
let mut linear_term =
*hint - self.coeffs_except_linear_term[0] - self.coeffs_except_linear_term[0];
for i in 1..self.coeffs_except_linear_term.len() {
linear_term -= self.coeffs_except_linear_term[i];
}

let mut coeffs = vec![self.coeffs_except_linear_term[0], linear_term];
coeffs.extend(&self.coeffs_except_linear_term[1..]);
assert_eq!(self.coeffs_except_linear_term.len() + 1, coeffs.len());
UniPoly { coeffs }
// let mut linear_term =
// *hint - self.coeffs_except_linear_term[0] - self.coeffs_except_linear_term[0];
// for i in 1..self.coeffs_except_linear_term.len() {
// linear_term -= self.coeffs_except_linear_term[i];
// }

// let mut coeffs = vec![self.coeffs_except_linear_term[0], linear_term];
// coeffs.extend(&self.coeffs_except_linear_term[1..]);
// assert_eq!(self.coeffs_except_linear_term.len() + 1, coeffs.len());
// UniPoly { coeffs }
UniPoly { coeffs: self.coeffs_except_linear_term.clone() }
}
}

Expand Down
2 changes: 1 addition & 1 deletion jolt-core/src/r1cs/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ impl<I: ConstraintInput> OffsetEqConstraint<I> {
}
}

#[cfg(test)]
// #[cfg(test)]
pub fn empty() -> Self {
Self::new(
(LC::new(vec![]), false),
Expand Down
3 changes: 2 additions & 1 deletion jolt-core/src/r1cs/jolt_constraints.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
assert_static_aux_index, field::JoltField, impl_r1cs_input_lc_conversions, input_range,
jolt::vm::rv32i_vm::C,
jolt::vm::rv32i_vm::C, r1cs::ops::{Term, LC},
};

use super::{
Expand Down Expand Up @@ -229,6 +229,7 @@ impl<F: JoltField> R1CSConstraintBuilder<F> for UniformJoltConstraints {
input_range!(JoltIn::ChunksY_0, JoltIn::ChunksY_3).to_vec(),
OPERAND_SIZE,
);

cs.constrain_eq_conditional(JoltIn::OpFlags_IsConcat, chunked_x, x);
cs.constrain_eq_conditional(JoltIn::OpFlags_IsConcat, chunked_y, y);

Expand Down
Loading