Skip to content

Commit

Permalink
write results too
Browse files Browse the repository at this point in the history
  • Loading branch information
winston-h-zhang committed Apr 18, 2024
1 parent 7110611 commit 233cf2f
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 20 deletions.
16 changes: 16 additions & 0 deletions src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub struct DataConfig {
#[cfg(not(target_arch = "wasm32"))]
section_counters: HashMap<String, usize>,
write_data: bool,
witness_size: usize,
}

#[cfg(not(target_arch = "wasm32"))]
Expand All @@ -47,6 +48,7 @@ pub fn init_config() -> Mutex<DataConfig> {
root_dir,
section_counters: HashMap::new(),
write_data: WRITE,
witness_size: 0,
};

Mutex::new(config)
Expand Down Expand Up @@ -150,3 +152,17 @@ pub fn set_write_data(write_data: bool) {
let mut config = mutex.lock().unwrap();
config.write_data = write_data;
}

/// Are we configured to write data?
pub fn witness_size() -> usize {
let mutex = ARECIBO_CONFIG.get_or_init(init_config);
let config = mutex.lock().unwrap();
config.witness_size
}

/// Set the configuration for writing data.
pub fn set_witness_size(witness_size: usize) {
let mutex = ARECIBO_CONFIG.get_or_init(init_config);
let mut config = mutex.lock().unwrap();
config.witness_size = witness_size;
}
37 changes: 18 additions & 19 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub mod spartan;
pub mod supernova;
pub mod traits;

use crate::data::{write_arecibo_data, write_data};
use crate::data::{set_witness_size, write_arecibo_data, write_data};
use crate::digest::{DigestComputer, SimpleDigestible};
use crate::{
bellpepper::{
Expand Down Expand Up @@ -491,9 +491,23 @@ where
};

if write_data() {
write_arecibo_data(format!("sparse_matrices_{:?}", pp.digest()), "A", &r1cs_primary.A);
write_arecibo_data(format!("sparse_matrices_{:?}", pp.digest()), "B", &r1cs_primary.B);
write_arecibo_data(format!("sparse_matrices_{:?}", pp.digest()), "C", &r1cs_primary.C);
write_arecibo_data(
format!("sparse_matrices_{:?}", pp.digest()),
"A",
&r1cs_primary.A,
);
write_arecibo_data(
format!("sparse_matrices_{:?}", pp.digest()),
"B",
&r1cs_primary.B,
);
write_arecibo_data(
format!("sparse_matrices_{:?}", pp.digest()),
"C",
&r1cs_primary.C,
);

set_witness_size(r1cs_primary.A.num_cols());
}

Ok(Self {
Expand Down Expand Up @@ -601,21 +615,6 @@ where
&mut self.buffer_primary.ABC_Z_2,
)?;

if write_data() {
let W = l_w_primary.W;
write_arecibo_data(
format!("witness_{:?}", pp.digest()),
format!("len_{}", W.len()),
&W,
);
let T = &self.buffer_primary.T;
write_arecibo_data(
format!("cross_term_{:?}", pp.digest()),
format!("len_{}", T.len()),
&T,
);
}

let mut cs_secondary = SatisfyingAssignment::<Dual<E1>>::with_capacity(
pp.circuit_shape_secondary.r1cs_shape.num_io + 1,
pp.circuit_shape_secondary.r1cs_shape.num_vars,
Expand Down
2 changes: 1 addition & 1 deletion src/nifs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl<E: Engine> NIFS<E> {
U2.absorb_in_ro(&mut ro);

// compute a commitment to the cross-term
let comm_T = S.commit_T_into(ck, U1, W1, U2, W2, T, ABC_Z_1, ABC_Z_2)?;
let comm_T = S.commit_T_into(ck, pp_digest, U1, W1, U2, W2, T, ABC_Z_1, ABC_Z_2)?;

// append `comm_T` to the transcript and obtain a challenge
comm_T.absorb_in_ro(&mut ro);
Expand Down
13 changes: 13 additions & 0 deletions src/r1cs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub(crate) mod util;

use crate::{
constants::{BN_LIMB_WIDTH, BN_N_LIMBS},
data::{witness_size, write_arecibo_data, write_data},
digest::{DigestComputer, SimpleDigestible},
errors::NovaError,
gadgets::{f_to_nat, nat_to_limbs, scalar_as_base},
Expand Down Expand Up @@ -465,6 +466,7 @@ impl<E: Engine> R1CSShape<E> {
pub fn commit_T_into(
&self,
ck: &CommitmentKey<E>,
pp_digest: &E::Scalar,
U1: &RelaxedR1CSInstance<E>,
W1: &RelaxedR1CSWitness<E>,
U2: &R1CSInstance<E>,
Expand All @@ -473,6 +475,11 @@ impl<E: Engine> R1CSShape<E> {
ABC_Z_1: &mut R1CSResult<E>,
ABC_Z_2: &mut R1CSResult<E>,
) -> Result<Commitment<E>, NovaError> {
if write_data() && self.A.num_cols() == witness_size() {
let witness = [&W1.W[..], &[U1.u], &U1.X[..]].concat();
write_arecibo_data(format!("witness_{:?}", pp_digest), "", &witness);
}

tracing::info_span!("AZ_1, BZ_1, CZ_1")
.in_scope(|| self.multiply_witness_into(&W1.W, &U1.u, &U1.X, ABC_Z_1))?;

Expand All @@ -482,6 +489,12 @@ impl<E: Engine> R1CSShape<E> {
CZ: CZ_1,
} = ABC_Z_1;

if write_data() && self.A.num_cols() == witness_size() {
write_arecibo_data(format!("result_{:?}", pp_digest), "AZ", &AZ_1);
write_arecibo_data(format!("result_{:?}", pp_digest), "BZ", &BZ_1);
write_arecibo_data(format!("result_{:?}", pp_digest), "CZ", &CZ_1);
}

tracing::info_span!("AZ_2, BZ_2, CZ_2")
.in_scope(|| self.multiply_witness_into(&W2.W, &E::Scalar::ONE, &U2.X, ABC_Z_2))?;

Expand Down

0 comments on commit 233cf2f

Please sign in to comment.