diff --git a/Cargo.toml b/Cargo.toml index 8df25a5..d63412e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,4 +2,5 @@ members = [ "tensor_pcs", "shockwave_plus" -] \ No newline at end of file +] +resolver = "2" diff --git a/rust-toolchain b/rust-toolchain new file mode 100644 index 0000000..f474f5a --- /dev/null +++ b/rust-toolchain @@ -0,0 +1 @@ +1.71.0 \ No newline at end of file diff --git a/shockwave_plus/src/lib.rs b/shockwave_plus/src/lib.rs index a0c64c7..b74996b 100644 --- a/shockwave_plus/src/lib.rs +++ b/shockwave_plus/src/lib.rs @@ -2,7 +2,6 @@ mod polynomial; mod r1cs; mod sumcheck; -mod utils; use ark_std::{end_timer, start_timer}; use serde::{Deserialize, Serialize}; diff --git a/shockwave_plus/src/polynomial/ml_poly.rs b/shockwave_plus/src/polynomial/ml_poly.rs index 74d858f..91a941f 100644 --- a/shockwave_plus/src/polynomial/ml_poly.rs +++ b/shockwave_plus/src/polynomial/ml_poly.rs @@ -9,12 +9,14 @@ pub struct MlPoly { } impl MlPoly { + #[allow(dead_code)] pub fn new(evals: Vec) -> Self { assert!(evals.len().is_power_of_two()); let num_vars = (evals.len() as f64).log2() as usize; Self { evals, num_vars } } + #[allow(dead_code)] fn dot_prod(x: &[F], y: &[F]) -> F { assert_eq!(x.len(), y.len()); let mut result = F::ZERO; @@ -27,6 +29,7 @@ impl MlPoly { // Evaluate the multilinear extension of the polynomial `a`, at point `t`. // `a` is in evaluation form. // `t` should be in big-endian form. + #[allow(dead_code)] pub fn eval(&self, t: &[F]) -> F { let n = self.evals.len(); debug_assert_eq!((n as f64).log2() as usize, t.len()); diff --git a/shockwave_plus/src/r1cs/r1cs.rs b/shockwave_plus/src/r1cs/r1cs.rs index ad8836c..50c69b4 100644 --- a/shockwave_plus/src/r1cs/r1cs.rs +++ b/shockwave_plus/src/r1cs/r1cs.rs @@ -256,12 +256,29 @@ mod tests { use halo2curves::ff::Field; - use crate::utils::boolean_hypercube; - use super::*; type F = halo2curves::secp256k1::Fp; use crate::polynomial::ml_poly::MlPoly; + // Returns a vector of vectors of length m, where each vector is a boolean vector (big endian) + fn boolean_hypercube(m: usize) -> Vec> { + let n = 2usize.pow(m as u32); + + let mut boolean_hypercube = Vec::>::with_capacity(n); + + for i in 0..n { + let mut tmp = Vec::with_capacity(m); + for j in 0..m { + let i_b = F::from((i >> j & 1) as u64); + tmp.push(i_b); + } + tmp.reverse(); + boolean_hypercube.push(tmp); + } + + boolean_hypercube + } + #[test] fn test_r1cs() { let num_cons = 10; diff --git a/shockwave_plus/src/utils.rs b/shockwave_plus/src/utils.rs deleted file mode 100644 index 73b7896..0000000 --- a/shockwave_plus/src/utils.rs +++ /dev/null @@ -1,20 +0,0 @@ -use crate::FieldExt; - -// Returns a vector of vectors of length m, where each vector is a boolean vector (big endian) -pub fn boolean_hypercube(m: usize) -> Vec> { - let n = 2usize.pow(m as u32); - - let mut boolean_hypercube = Vec::>::with_capacity(n); - - for i in 0..n { - let mut tmp = Vec::with_capacity(m); - for j in 0..m { - let i_b = F::from((i >> j & 1) as u64); - tmp.push(i_b); - } - tmp.reverse(); - boolean_hypercube.push(tmp); - } - - boolean_hypercube -} diff --git a/tensor_pcs/src/fft.rs b/tensor_pcs/src/fft.rs index c2a4f66..13f9f10 100644 --- a/tensor_pcs/src/fft.rs +++ b/tensor_pcs/src/fft.rs @@ -1,6 +1,4 @@ use crate::FieldExt; -use halo2curves::ff::Field; -use std::vec; pub fn fft(coeffs: &[F], domain: &[F]) -> Vec where @@ -11,7 +9,6 @@ where return coeffs.to_vec(); } - // TODO: Just borrow the values // Split into evens and odds let L = coeffs .iter() @@ -46,24 +43,26 @@ where return evals_L; } -pub fn ifft(domain: &[F], evals: &[F]) -> Vec { - let mut coeffs = vec![]; - let len_mod_inv = F::from(domain.len() as u64).invert().unwrap(); - let vals = fft(&evals, &domain); - - coeffs.push(vals[0] * len_mod_inv); - for val in vals[1..].iter().rev() { - coeffs.push(*val * len_mod_inv); - } - - coeffs -} - #[cfg(test)] mod tests { + use halo2curves::ff::Field; use halo2curves::ff::PrimeField; use halo2curves::pasta::Fp; + // Test the fft function by running the inverse fft + fn ifft(domain: &[F], evals: &[F]) -> Vec { + let mut coeffs = vec![]; + let len_mod_inv = F::from(domain.len() as u64).invert().unwrap(); + let vals = fft(&evals, &domain); + + coeffs.push(vals[0] * len_mod_inv); + for val in vals[1..].iter().rev() { + coeffs.push(*val * len_mod_inv); + } + + coeffs + } + use super::*; #[test] fn test_fft_ifft() { diff --git a/tensor_pcs/src/lib.rs b/tensor_pcs/src/lib.rs index 83b3e6f..3aadc44 100644 --- a/tensor_pcs/src/lib.rs +++ b/tensor_pcs/src/lib.rs @@ -1,3 +1,4 @@ +#![allow(non_snake_case)] mod fft; mod polynomial; pub mod rs_config; diff --git a/tensor_pcs/src/tensor_code.rs b/tensor_pcs/src/tensor_code.rs index 2938b1d..d29cebd 100644 --- a/tensor_pcs/src/tensor_code.rs +++ b/tensor_pcs/src/tensor_code.rs @@ -32,7 +32,7 @@ pub struct CommittedTensorCode { } impl CommittedTensorCode { - pub fn query_column(&self, column: usize, num_cols: usize) -> Vec { + pub fn query_column(&self, column: usize) -> Vec { let num_rows = self.tensor_codeword.0.len(); let leaves = diff --git a/tensor_pcs/src/tensor_pcs.rs b/tensor_pcs/src/tensor_pcs.rs index bb48712..c9dfa51 100644 --- a/tensor_pcs/src/tensor_pcs.rs +++ b/tensor_pcs/src/tensor_pcs.rs @@ -297,14 +297,12 @@ impl TensorMultilinearPCS { } fn test_phase(&self, indices: &[usize], u_hat_comm: &CommittedTensorCode) -> Vec> { - let num_cols = self.config.num_cols() * 2; - // Query the columns of u_hat let num_indices = self.config.l; let u_hat_openings = indices .iter() - .map(|index| u_hat_comm.query_column(*index, num_cols)) + .map(|index| u_hat_comm.query_column(*index)) .collect::>>(); debug_assert_eq!(u_hat_openings.len(), num_indices); diff --git a/tensor_pcs/src/transcript.rs b/tensor_pcs/src/transcript.rs index 83b1800..6e5f018 100644 --- a/tensor_pcs/src/transcript.rs +++ b/tensor_pcs/src/transcript.rs @@ -1,7 +1,6 @@ use crate::FieldExt; -use halo2curves::ff::PrimeField; use merlin::Transcript as MerlinTranscript; -use std::{io::Repeat, marker::PhantomData, panic::UnwindSafe}; +use std::marker::PhantomData; #[derive(Clone)] pub struct Transcript { diff --git a/tensor_pcs/src/tree.rs b/tensor_pcs/src/tree.rs index 3d51e51..ccf889e 100644 --- a/tensor_pcs/src/tree.rs +++ b/tensor_pcs/src/tree.rs @@ -1,7 +1,3 @@ -use core::num; -use std::marker::PhantomData; - -use super::utils::hash_two; use crate::{utils::hash_all, FieldExt}; use serde::{Deserialize, Serialize}; diff --git a/tensor_pcs/src/utils.rs b/tensor_pcs/src/utils.rs index ec33f8d..cf1b86f 100644 --- a/tensor_pcs/src/utils.rs +++ b/tensor_pcs/src/utils.rs @@ -23,15 +23,6 @@ pub fn dot_prod(x: &[F], y: &[F]) -> F { result } -pub fn hash_two(values: &[[u8; 32]; 2]) -> [u8; 32] { - let mut hasher = Keccak::v256(); - hasher.update(&values[0]); - hasher.update(&values[1]); - let mut hash = [0u8; 32]; - hasher.finalize(&mut hash); - hash -} - pub fn hash_all(values: &[[u8; 32]]) -> [u8; 32] { let mut hasher = Keccak::v256(); for value in values {