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

Refactor constraint system #29

Merged
merged 16 commits into from
Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
24 changes: 1 addition & 23 deletions src/ahp/constraint_systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,29 +111,7 @@ pub(crate) fn num_non_zero<F: Field>(cs: &mut ConstraintSystem<F>) -> usize {
max
}

pub(crate) fn make_matrices_square_for_indexer<F: Field>(cs: &mut ConstraintSystem<F>) {
let num_variables = cs.num_inputs + cs.num_aux;
let nnz = num_non_zero(cs);
let matrix_dim = padded_matrix_dim(num_variables, cs.num_constraints);
make_matrices_square(cs, num_variables);
assert_eq!(
cs.num_inputs + cs.num_aux,
cs.num_constraints,
"padding failed!"
);
assert_eq!(
cs.num_inputs + cs.num_aux,
matrix_dim,
"padding does not result in expected matrix size!"
);
assert_eq!(
num_non_zero(cs),
nnz,
"padding changed matrix density"
);
DanieleDiBenedetto marked this conversation as resolved.
Show resolved Hide resolved
}

pub(crate) fn make_matrices_square_for_prover<F: Field>(cs: &mut ConstraintSystem<F>) {
pub(crate) fn make_matrices_square_for_indexer_and_prover<F: Field>(cs: &mut ConstraintSystem<F>) {
DanieleDiBenedetto marked this conversation as resolved.
Show resolved Hide resolved
let num_variables = cs.num_inputs + cs.num_aux;
make_matrices_square(cs, num_variables);
assert_eq!(
Expand Down
7 changes: 3 additions & 4 deletions src/ahp/indexer.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![allow(non_snake_case)]

use crate::ahp::{
constraint_systems::{MatrixArithmetization, arithmetize_matrix, pad_input, make_matrices_square_for_indexer, process_matrices, num_non_zero},
constraint_systems::{MatrixArithmetization, arithmetize_matrix, pad_input, make_matrices_square_for_indexer_and_prover, process_matrices, num_non_zero},
AHPForR1CS, Error,
};
use crate::Vec;
Expand Down Expand Up @@ -171,15 +171,14 @@ impl<F: PrimeField> AHPForR1CS<F> {
let index_time = start_timer!(|| "AHP::Index");

let constraint_time = start_timer!(|| "Generating constraints");
let mut ics = ConstraintSystem::new();
ics.set_mode(SynthesisMode::Setup);
let mut ics = ConstraintSystem::new(SynthesisMode::Setup);
c.generate_constraints(&mut ics)?;
end_timer!(constraint_time);

let padding_time = start_timer!(|| "Padding matrices to make them square");
let num_inputs = ics.num_inputs;
pad_input(&mut ics, num_inputs);
make_matrices_square_for_indexer(&mut ics);
make_matrices_square_for_indexer_and_prover(&mut ics);
end_timer!(padding_time);
let matrix_processing_time = start_timer!(|| "Processing matrices");
let (mut a, mut b, mut c) = process_matrices(&mut ics).expect("should not be `None`");
Expand Down
8 changes: 4 additions & 4 deletions src/ahp/prover.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![allow(non_snake_case)]

use crate::ahp::constraint_systems::{pad_input, unformat_public_input, make_matrices_square_for_prover};
use crate::ahp::constraint_systems::{pad_input, unformat_public_input, make_matrices_square_for_indexer_and_prover};
use crate::ahp::indexer::*;
use crate::ahp::verifier::*;
use crate::ahp::*;
Expand Down Expand Up @@ -143,15 +143,15 @@ impl<F: PrimeField> AHPForR1CS<F> {
let init_time = start_timer!(|| "AHP::Prover::Init");

let constraint_time = start_timer!(|| "Generating constraints and witnesses");
let mut pcs = ConstraintSystem::new();
pcs.set_mode(SynthesisMode::Prove {construct_matrices: false});
let mode = SynthesisMode::Prove {construct_matrices: false};
let mut pcs = ConstraintSystem::new(mode);
c.generate_constraints(&mut pcs)?;
end_timer!(constraint_time);

let padding_time = start_timer!(|| "Padding matrices to make them square");
let num_inputs = pcs.num_inputs;
pad_input(&mut pcs, num_inputs);
make_matrices_square_for_prover(&mut pcs);
make_matrices_square_for_indexer_and_prover(&mut pcs);
end_timer!(padding_time);

let num_non_zero = index.index_info.num_non_zero;
Expand Down