Skip to content

Commit

Permalink
Ivolkg/sparse ccs (#99)
Browse files Browse the repository at this point in the history
Needs [this](NethermindEth/lattirust#66) PR in
lattirust

---------

Co-authored-by: v0-e <xyz.vieira@gmail.com>
  • Loading branch information
ivolkg and v0-e authored Nov 28, 2024
1 parent d8c499f commit c461204
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 17 deletions.
22 changes: 11 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions latticefold/benches/linearization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ fn linearization_benchmarks<
macro_rules! define_params {
($w:expr, $b:expr, $l:expr, $b_small:expr, $k:expr) => {
paste::paste! {

#[derive(Clone)]
struct [<DecompParamsWithB $b W $w b $b_small K $k>];

Expand All @@ -149,21 +150,22 @@ macro_rules! define_params {
}
};
}

#[macro_export]
macro_rules! run_single_goldilocks_benchmark {
( $crit:expr, $io:expr, $cw:expr, $w:expr, $b:expr, $l:expr, $b_small:expr, $k:expr) => {
($crit:expr, $io:expr, $cw:expr, $w:expr, $b:expr, $l:expr, $b_small:expr, $k:expr) => {
define_params!($w, $b, $l, $b_small, $k);
paste::paste! {
linearization_benchmarks::<$io, $cw, $w, {$w * $l}, GoldilocksChallengeSet, GoldilocksRingNTT, [<DecompParamsWithB $b W $w b $b_small K $k>]>($crit);

}
};
}

macro_rules! run_single_starkprime_benchmark {
($crit:expr, $io:expr, $cw:expr, $w:expr, $b:expr, $l:expr, $b_small:expr, $k:expr) => {
define_params!($w, $b, $l, $b_small, $k);
paste::paste! {
linearization_benchmarks::<$io, $cw, $w,{$w * $l}, StarkChallengeSet, StarkRingNTT, [<DecompParamsWithB $b W $w b $b_small K $k>]>($crit);
linearization_benchmarks::<$io, $cw, $w, {$w * $l}, StarkChallengeSet, StarkRingNTT, [<DecompParamsWithB $b W $w b $b_small K $k>]>($crit);
}
};
}
Expand Down
26 changes: 23 additions & 3 deletions latticefold/src/arith/r1cs.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use lattirust_linear_algebra::sparse_matrix::dense_matrix_to_sparse;
use lattirust_linear_algebra::sparse_matrix::dense_matrix_u64_to_sparse;
use lattirust_linear_algebra::SparseMatrix;
use lattirust_ring::Ring;

Expand Down Expand Up @@ -78,7 +78,12 @@ impl<R: Ring> RelaxedR1CS<R> {
}

pub fn to_F_matrix<R: Ring>(M: Vec<Vec<usize>>) -> SparseMatrix<R> {
dense_matrix_to_sparse(to_F_dense_matrix::<R>(M))
// dense_matrix_to_sparse(to_F_dense_matrix::<R>(M))
let M_u64: Vec<Vec<u64>> = M
.iter()
.map(|m| m.iter().map(|r| *r as u64).collect())
.collect();
dense_matrix_u64_to_sparse(M_u64)
}

pub fn to_F_dense_matrix<R: Ring>(M: Vec<Vec<usize>>) -> Vec<Vec<R>> {
Expand Down Expand Up @@ -118,7 +123,7 @@ pub fn get_test_r1cs<R: Ring>() -> R1CS<R> {
pub fn get_test_dummy_r1cs<R: Ring, const X_LEN: usize, const WIT_LEN: usize>(
rows: usize,
) -> R1CS<R> {
let R1CS_A = to_F_matrix::<R>(create_dummy_identity_matrix(rows, X_LEN + WIT_LEN + 1));
let R1CS_A = create_dummy_identity_sparse_matrix(rows, X_LEN + WIT_LEN + 1);
let R1CS_B = R1CS_A.clone();
let R1CS_C = R1CS_A.clone();

Expand All @@ -137,6 +142,21 @@ pub fn create_dummy_identity_matrix(rows: usize, columns: usize) -> Vec<Vec<usiz
matrix
}

pub fn create_dummy_identity_sparse_matrix<R: Ring>(
rows: usize,
columns: usize,
) -> SparseMatrix<R> {
let mut matrix = SparseMatrix {
n_rows: rows,
n_cols: columns,
coeffs: vec![vec![]; rows],
};
for (i, row) in matrix.coeffs.iter_mut().enumerate() {
row.push((R::one(), i));
}
matrix
}

pub fn get_test_z<R: Ring>(input: usize) -> Vec<R> {
// z = (1, io, w)
to_F_vec(vec![
Expand Down

0 comments on commit c461204

Please sign in to comment.