Skip to content

Commit 67b3ea4

Browse files
committed
Initial time recording
1 parent 5f17d48 commit 67b3ea4

File tree

4 files changed

+67
-12
lines changed

4 files changed

+67
-12
lines changed

circ_blocks/examples/zxc.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,7 @@ fn get_run_time_knowledge<const VERBOSE: bool, S: SpartanExtensionField + Send +
897897
)
898898
};
899899

900+
let gen_start = Instant::now();
900901
// Meta info
901902
// The most time any block is executed
902903
let mut block_max_num_proofs = 0;
@@ -936,7 +937,7 @@ fn get_run_time_knowledge<const VERBOSE: bool, S: SpartanExtensionField + Send +
936937
let zero = Integer::from(0);
937938
let one = Integer::from(1);
938939
// Start from entry block, compute value of witnesses
939-
// Note: block_vars_matrix are sorted by block_num_proofs, tie-breaked by block id
940+
// Note: block_vars_matrix are sorted by block_num_proofs, tie-breaked by block id
940941
// Thus, block_vars_matrix[0] might NOT store the executions of block 0!
941942
let mut block_vars_matrix = vec![Vec::new(); num_blocks_live];
942943
let mut exec_inputs = Vec::new();
@@ -1038,14 +1039,14 @@ fn get_run_time_knowledge<const VERBOSE: bool, S: SpartanExtensionField + Send +
10381039
.concat();
10391040
let inputs_assignment = Assignment::new(
10401041
&inputs
1041-
.iter()
1042+
.into_iter()
10421043
.map(|i| integer_to_bytes(i.clone()))
10431044
.collect::<Vec<[u8; 32]>>(),
10441045
)
10451046
.unwrap();
10461047
let vars_assignment = Assignment::new(
10471048
&vars
1048-
.iter()
1049+
.into_iter()
10491050
.map(|i| integer_to_bytes(i.clone()))
10501051
.collect::<Vec<[u8; 32]>>(),
10511052
)
@@ -1055,7 +1056,10 @@ fn get_run_time_knowledge<const VERBOSE: bool, S: SpartanExtensionField + Send +
10551056
exec_inputs.push(inputs_assignment.clone());
10561057
block_vars_matrix[slot].push(vars_assignment);
10571058
}
1059+
let gen_time = gen_start.elapsed();
1060+
println!("\n--\nGen time: {}ms", gen_time.as_millis());
10581061

1062+
let record_start = Instant::now();
10591063
// Initial Physical & Virtual Memory: valid, _, addr, data (ts and ls are both 0 and are not recorded)
10601064
let mut init_phy_mems_list = Vec::new();
10611065
for i in 0..init_phy_mem_list.len() {
@@ -1088,7 +1092,7 @@ fn get_run_time_knowledge<const VERBOSE: bool, S: SpartanExtensionField + Send +
10881092

10891093
init_vir_mems_list.push(
10901094
Assignment::new(
1091-
&mem.iter()
1095+
&mem.into_iter()
10921096
.map(|i| integer_to_bytes(i.clone()))
10931097
.collect::<Vec<[u8; 32]>>(),
10941098
)
@@ -1122,7 +1126,7 @@ fn get_run_time_knowledge<const VERBOSE: bool, S: SpartanExtensionField + Send +
11221126
if i == phy_mem_list.len() - 1 {
11231127
addr_phy_mems_list.push(
11241128
Assignment::new(
1125-
&mem.iter()
1129+
&mem.into_iter()
11261130
.map(|i| integer_to_bytes(i.clone()))
11271131
.collect::<Vec<[u8; 32]>>(),
11281132
)
@@ -1191,7 +1195,7 @@ fn get_run_time_knowledge<const VERBOSE: bool, S: SpartanExtensionField + Send +
11911195
if i == vir_mem_list.len() - 1 {
11921196
addr_vir_mems_list.push(
11931197
Assignment::new(
1194-
&mem.iter()
1198+
&mem.into_iter()
11951199
.map(|i| integer_to_bytes(i.clone()))
11961200
.collect::<Vec<[u8; 32]>>(),
11971201
)
@@ -1200,7 +1204,7 @@ fn get_run_time_knowledge<const VERBOSE: bool, S: SpartanExtensionField + Send +
12001204
addr_ts_bits_list.push(
12011205
Assignment::new(
12021206
&ts_bits
1203-
.iter()
1207+
.into_iter()
12041208
.map(|i| integer_to_bytes(i.clone()))
12051209
.collect::<Vec<[u8; 32]>>(),
12061210
)
@@ -1247,18 +1251,20 @@ fn get_run_time_knowledge<const VERBOSE: bool, S: SpartanExtensionField + Send +
12471251
println!("{:3} ", func_outputs);
12481252

12491253
let func_inputs = entry_regs
1250-
.iter()
1254+
.into_iter()
12511255
.map(|i| integer_to_bytes(i.clone()))
12521256
.collect();
12531257
let input_stack = entry_stacks
1254-
.iter()
1258+
.into_iter()
12551259
.map(|i| integer_to_bytes(i.clone()))
12561260
.collect();
12571261
let input_mem = entry_arrays
1258-
.iter()
1262+
.into_iter()
12591263
.map(|i| integer_to_bytes(i.clone()))
12601264
.collect();
12611265
let func_outputs = integer_to_bytes(func_outputs);
1266+
let record_time = record_start.elapsed();
1267+
println!("\n--\nRecord time: {}ms", record_time.as_millis());
12621268

12631269
RunTimeKnowledge {
12641270
block_max_num_proofs,
@@ -1513,6 +1519,7 @@ fn main() {
15131519
// Obtain Inputs
15141520
// --
15151521
let witness_start = Instant::now();
1522+
let read_input_start = Instant::now();
15161523
// Assume inputs are listed in the order of the parameters
15171524
let mut entry_regs: Vec<Integer> = Vec::new();
15181525
// Keep track of %SP and %AS and record initial memory state
@@ -1594,6 +1601,8 @@ fn main() {
15941601
reader.read_line(&mut buffer).unwrap();
15951602
}
15961603
}
1604+
let read_input_time = read_input_start.elapsed();
1605+
println!("\n--\nRead input time: {}ms", read_input_time.as_millis());
15971606

15981607
println!("INPUT: {:?}", entry_regs);
15991608

circ_blocks/src/front/zsharp/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use std::fmt::Display;
2626
use std::hash::BuildHasherDefault;
2727
use std::path::PathBuf;
2828
use std::str::FromStr;
29+
use std::time::Instant;
2930
use zokrates_pest_ast as ast;
3031

3132
use term::*;
@@ -130,12 +131,16 @@ impl ZSharpFE {
130131
g.file_stack_push(i.file);
131132
g.generics_stack_push(HashMap::new());
132133

134+
let block_start = Instant::now();
133135
let (blks, entry_bl, inputs) = g.bl_gen_entry_fn("main");
134136
let (blks, entry_bl, input_liveness) =
135137
g.optimize_block::<INTERPRET_VERBOSE>(blks, entry_bl, inputs.clone(), i.no_opt);
136138
let (blks, entry_bl, io_size, _, _, _, _) =
137139
g.process_block::<INTERPRET_VERBOSE, 1>(blks, entry_bl);
140+
let block_time = block_start.elapsed();
141+
println!("\n--\nBlock time: {}ms", block_time.as_millis());
138142

143+
let interpret_start = Instant::now();
139144
println!("\n\n--\nInterpretation:");
140145
let (
141146
ret,
@@ -162,7 +167,10 @@ impl ZSharpFE {
162167
// prover::print_state_list(&bl_exec_state);
163168
// let _ = prover::sort_by_block(&bl_exec_state);
164169
// let _ = prover::sort_by_mem(&bl_exec_state);
170+
let interpret_time = interpret_start.elapsed();
171+
println!("\n--\nInterpret time: {}ms", interpret_time.as_millis());
165172

173+
let convert_start = Instant::now();
166174
// A vector of all the blocks executed
167175
let mut block_id_list = Vec::new();
168176
// Convert bl_exec_state to list of String -> Value hashmaps
@@ -389,6 +397,9 @@ impl ZSharpFE {
389397
.concat()
390398
})
391399
.collect();
400+
let convert_time = convert_start.elapsed();
401+
println!("\n--\nConvert time: {}ms", convert_time.as_millis());
402+
392403
return (
393404
ret,
394405
block_id_list,

spartan_parallel/src/custom_dense_mlpoly.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#![allow(clippy::too_many_arguments)]
22
use std::cmp::min;
33

4+
use rayon::iter::{IntoParallelIterator, ParallelIterator};
5+
46
use crate::dense_mlpoly::DensePolynomial;
57
use crate::scalar::SpartanExtensionField;
68

@@ -244,6 +246,33 @@ impl<S: SpartanExtensionField> DensePolynomialPqx<S> {
244246
}
245247
}
246248

249+
// Bound the first variable of "q" section to r
250+
pub fn bound_poly_q_parallel(&mut self, r: &S) {
251+
self.max_num_proofs /= 2;
252+
253+
for p in 0..min(self.num_instances, self.Z.len()) {
254+
if self.num_proofs[p] == 1 {
255+
for w in 0..min(self.num_witness_secs, self.Z[p][0].len()) {
256+
for x in 0..self.num_inputs[p] {
257+
self.Z[p][0][w][x] = (S::field_one() - *r) * self.Z[p][0][w][x];
258+
}
259+
}
260+
} else {
261+
self.num_proofs[p] /= 2;
262+
let num_proofs = self.num_proofs[p];
263+
self.Z[p] = self.Z[p][..].split_at_mut(num_proofs).into_par_iter().map(|(left, right)| {
264+
for w in 0..min(self.num_witness_secs, left.len()) {
265+
for x in 0..self.num_inputs[p] {
266+
left[w][x] = left[w][x] + *r * (right[w][x] - left[w][x]);
267+
}
268+
}
269+
left.clone()
270+
}
271+
).collect();
272+
}
273+
}
274+
}
275+
247276
// Bound the first variable of "w" section to r
248277
pub fn bound_poly_w(&mut self, r: &S) {
249278
self.num_witness_secs /= 2;
@@ -304,6 +333,13 @@ impl<S: SpartanExtensionField> DensePolynomialPqx<S> {
304333
}
305334
}
306335

336+
// Bound the entire "q_rev" section to r_q
337+
pub fn bound_poly_vars_rq_parallel(&mut self, r_q: &Vec<S>) {
338+
for r in r_q {
339+
self.bound_poly_q_parallel(r);
340+
}
341+
}
342+
307343
// Bound the entire "w" section to r_w
308344
pub fn bound_poly_vars_rw(&mut self, r_w: &Vec<S>) {
309345
for r in r_w {

spartan_parallel/src/r1csproof.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ impl<S: SpartanExtensionField + Send + Sync> R1CSProof<S> {
339339
);
340340
timer_tmp.stop();
341341
let timer_tmp = Timer::new("prove_z_bind");
342-
Z_poly.bound_poly_vars_rq(&rq_rev.to_vec());
342+
Z_poly.bound_poly_vars_rq_parallel(&rq_rev.to_vec());
343343
timer_tmp.stop();
344344

345345
// An Eq function to match p with rp
@@ -595,7 +595,6 @@ impl<S: SpartanExtensionField + Send + Sync> R1CSProof<S> {
595595
S::append_field_to_transcript(b"Bz_claim", transcript, Bz_claim);
596596
S::append_field_to_transcript(b"Cz_claim", transcript, Cz_claim);
597597

598-
// debug_zk
599598
assert_eq!(taus_bound_rx * (Az_claim * Bz_claim - Cz_claim), claim_post_phase_1);
600599

601600
// derive three public challenges and then derive a joint claim

0 commit comments

Comments
 (0)