diff --git a/proofman/src/proofman.rs b/proofman/src/proofman.rs index 97291829..ac53665b 100644 --- a/proofman/src/proofman.rs +++ b/proofman/src/proofman.rs @@ -331,7 +331,7 @@ impl ProofMan { } } - let buff_helper = create_buffer_fast(3 * buff_helper_size); + let buff_helper = create_buffer_fast(buff_helper_size); *pctx.buff_helper.buff_helper.write().unwrap() = buff_helper; timer_stop_and_log_debug!(INITIALIZE_PROVERS); @@ -512,7 +512,7 @@ impl ProofMan { stage: u32, provers: &mut [Box>], pctx: Arc>, - ectx: Arc, + _ectx: Arc, transcript: &mut FFITranscript, verify_constraints: bool, ) { @@ -523,44 +523,66 @@ impl ProofMan { transcript.add_elements(public_inputs, pctx.global_info.n_publics); } - let dctx = ectx.dctx.read().unwrap(); - - // calculate my roots - let mut roots: Vec = vec![0; 4 * provers.len()]; - for (i, prover) in provers.iter_mut().enumerate() { - // Important we need the roots in u64 in order to distribute them - let values = prover.get_transcript_values_u64(stage as u64, pctx.clone()); - if values.is_empty() { - panic!("No transcript values found for prover {}", i); - } - roots[i * 4..(i + 1) * 4].copy_from_slice(&values) - } - // get all roots - let all_roots = dctx.distribute_roots(roots); - - // add challenges to transcript in order - for group_idxs in dctx.my_groups.iter() { + // TODO: ACTIVATE DCTX BACK + // let dctx = ectx.dctx.read().unwrap(); + + // // calculate my roots + // let mut roots: Vec = vec![0; 4 * provers.len()]; + // for (i, prover) in provers.iter_mut().enumerate() { + // // Important we need the roots in u64 in order to distribute them + // let values = prover.get_transcript_values_u64(stage as u64, pctx.clone()); + // if values.is_empty() { + // panic!("No transcript values found for prover {}", i); + // } + // roots[i * 4..(i + 1) * 4].copy_from_slice(&values) + // } + // // get all roots + // let all_roots = dctx.distribute_roots(roots); + + // // add challenges to transcript in order + // for group_idxs in dctx.my_groups.iter() { + // if verify_constraints { + // let dummy_elements = [F::zero(), F::one(), F::two(), F::neg_one()]; + // transcript.add_elements(dummy_elements.as_ptr() as *mut c_void, 4); + // } else { + // let mut values = Vec::new(); + // for idx in group_idxs.iter() { + // let value = vec![ + // F::from_wrapped_u64(all_roots[*idx]), + // F::from_wrapped_u64(all_roots[*idx + 1]), + // F::from_wrapped_u64(all_roots[*idx + 2]), + // F::from_wrapped_u64(all_roots[*idx + 3]), + // ]; + // values.push(value); + // } + // if !values.is_empty() { + // let value = Self::hash_b_tree(&*provers[0], values); + // transcript.add_elements(value.as_ptr() as *mut c_void, value.len()); + // } + // } + // } + // drop(dctx); + let airgroups = pctx.global_info.air_groups.clone(); + for (airgroup_id, _airgroup) in airgroups.iter().enumerate() { if verify_constraints { let dummy_elements = [F::zero(), F::one(), F::two(), F::neg_one()]; transcript.add_elements(dummy_elements.as_ptr() as *mut c_void, 4); } else { - let mut values = Vec::new(); - for idx in group_idxs.iter() { - let value = vec![ - F::from_wrapped_u64(all_roots[*idx]), - F::from_wrapped_u64(all_roots[*idx + 1]), - F::from_wrapped_u64(all_roots[*idx + 2]), - F::from_wrapped_u64(all_roots[*idx + 3]), - ]; - values.push(value); - } - if !values.is_empty() { - let value = Self::hash_b_tree(&*provers[0], values); - transcript.add_elements(value.as_ptr() as *mut c_void, value.len()); + let airgroup_instances = pctx.air_instance_repo.find_airgroup_instances(airgroup_id); + + if !airgroup_instances.is_empty() { + let mut values = Vec::new(); + for prover_idx in airgroup_instances.iter() { + let value = provers[*prover_idx].get_transcript_values(stage as u64, pctx.clone()); + values.push(value); + } + if !values.is_empty() { + let value = Self::hash_b_tree(&*provers[airgroup_instances[0]], values); + transcript.add_elements(value.as_ptr() as *mut c_void, value.len()); + } } } } - drop(dctx); } fn get_challenges( @@ -584,6 +606,13 @@ impl ProofMan { // Calculate evals timer_start_debug!(CALCULATING_EVALS); Self::get_challenges(pctx.global_info.n_challenges.len() as u32 + 2, provers, pctx.clone(), transcript); + // TODO: ACTIVATE DCTX BACK + // for group_idx in dctx.my_air_groups.iter() { + // provers[group_idx[0]].calculate_lev(pctx.clone()); + // for idx in group_idx.iter() { + // provers[*idx].opening_stage(1, sctx.clone(), pctx.clone()); + // } + // } for airgroup_id in 0..pctx.global_info.air_groups.len() { for air_id in 0..pctx.global_info.airs[airgroup_id].len() { let instances = pctx.air_instance_repo.find_air_instances(airgroup_id, air_id); @@ -601,7 +630,13 @@ impl ProofMan { Self::get_challenges(pctx.global_info.n_challenges.len() as u32 + 3, provers, pctx.clone(), transcript); info!("{}: Calculating FRI Polynomials", Self::MY_NAME); timer_start_debug!(CALCULATING_FRI_POLINOMIAL); - + // TODO: ACTIVATE DCTX BACK + // for group_idx in dctx.my_air_groups.iter() { + // provers[group_idx[0]].calculate_xdivxsub(pctx.clone()); + // for idx in group_idx.iter() { + // provers[*idx].opening_stage(2, sctx.clone(), pctx.clone()); + // } + // } for airgroup_id in 0..pctx.global_info.air_groups.len() { for air_id in 0..pctx.global_info.airs[airgroup_id].len() { let instances = pctx.air_instance_repo.find_air_instances(airgroup_id, air_id); diff --git a/proofman/src/recursion.rs b/proofman/src/recursion.rs index 3871585c..c3977b7a 100644 --- a/proofman/src/recursion.rs +++ b/proofman/src/recursion.rs @@ -166,7 +166,7 @@ pub fn generate_vadcop_recursive1_proof( pub fn generate_vadcop_recursive2_proof( pctx: &ProofCtx, - ectx: &ExecutionCtx, + _ectx: &ExecutionCtx, sctx: Arc, proofs: &[*mut c_void], output_dir_path: PathBuf, @@ -177,43 +177,54 @@ pub fn generate_vadcop_recursive2_proof( let global_info_path = pctx.global_info.get_proving_key_path().join("pilout.globalInfo.json"); let global_info_file: &str = global_info_path.to_str().unwrap(); - let mut dctx = ectx.dctx.write().unwrap(); + // let mut dctx = ectx.dctx.write().unwrap(); let n_airgroups = pctx.global_info.air_groups.len(); let mut alives = Vec::with_capacity(n_airgroups); let mut airgroup_proofs: Vec>> = Vec::with_capacity(n_airgroups); - let mut null_zkin: Option<*mut c_void> = None; - let mut zkin_final = std::ptr::null_mut(); + // TODO: ACTIVATE DCTX BACK + // let mut null_zkin: Option<*mut c_void> = None; + // let mut zkin_final = std::ptr::null_mut(); // Pre-process data before starting recursion loop for airgroup in 0..n_airgroups { - let instances = &dctx.airgroup_instances[airgroup]; + let setup_path = pctx.global_info.get_air_setup_path(airgroup, 0, &ProofType::Recursive2); + // let instances = &dctx.airgroup_instances[airgroup]; + let instances = pctx.air_instance_repo.find_airgroup_instances(airgroup); airgroup_proofs.push(Vec::with_capacity(instances.len().max(1))); - if !instances.is_empty() { - for instance in instances.iter() { - let local_instance = dctx.glob2loc[*instance]; - let proof = local_instance.map(|idx| proofs[idx]); - airgroup_proofs[airgroup].push(proof); - } + if instances.is_empty() { + let zkin_file = setup_path.display().to_string() + ".null_zkin.json"; + airgroup_proofs[airgroup].push(Some(get_zkin_ptr_c(&zkin_file))); } else { - // If there are no instances, we need to add a null proof (only rank 0) - if dctx.rank == 0 { - if null_zkin.is_none() { - let setup_path = pctx.global_info.get_air_setup_path(airgroup, 0, &ProofType::Recursive2); - let zkin_file = setup_path.display().to_string() + ".null_zkin.json"; - null_zkin = Some(get_zkin_ptr_c(&zkin_file)); - } - airgroup_proofs[airgroup].push(Some(null_zkin.unwrap())); - } else { - airgroup_proofs[airgroup].push(None); + for instance in instances.iter() { + airgroup_proofs[airgroup].push(Some(proofs[*instance])); } } + // if !instances.is_empty() { + // for instance in instances.iter() { + // let local_instance = dctx.glob2loc[*instance]; + // let proof = local_instance.map(|idx| proofs[idx]); + // airgroup_proofs[airgroup].push(proof); + // } + // } else { + // If there are no instances, we need to add a null proof (only rank 0) + // if dctx.rank == 0 { + // if null_zkin.is_none() { + // let setup_path = pctx.global_info.get_air_setup_path(airgroup, 0, &ProofType::Recursive2); + // let zkin_file = setup_path.display().to_string() + ".null_zkin.json"; + // null_zkin = Some(get_zkin_ptr_c(&zkin_file)); + // } + // airgroup_proofs[airgroup].push(Some(null_zkin.unwrap())); + // } else { + // airgroup_proofs[airgroup].push(None); + // } + // } alives.push(airgroup_proofs[airgroup].len()); } // agregation loop loop { - dctx.barrier(); - dctx.distribute_recursive2_proofs(&alives, &mut airgroup_proofs); + // dctx.barrier(); + // dctx.distribute_recursive2_proofs(&alives, &mut airgroup_proofs); let mut pending_agregations = false; for airgroup in 0..n_airgroups { //create a vector of sice indices length @@ -322,37 +333,37 @@ pub fn generate_vadcop_recursive2_proof( break; } } - if dctx.rank == 0 { - let mut proofs_recursive2: Vec<*mut c_void> = Vec::with_capacity(n_airgroups); - for proofs in airgroup_proofs { - proofs_recursive2.push(proofs[0].unwrap()); - } - let public_inputs_guard = pctx.public_inputs.inputs.read().unwrap(); - let challenges_guard = pctx.challenges.challenges.read().unwrap(); - let proof_values_guard = pctx.proof_values.values.read().unwrap(); + // if dctx.rank == 0 { + let mut proofs_recursive2: Vec<*mut c_void> = Vec::with_capacity(n_airgroups); + for proofs in airgroup_proofs { + proofs_recursive2.push(proofs[0].unwrap()); + } + let public_inputs_guard = pctx.public_inputs.inputs.read().unwrap(); + let challenges_guard = pctx.challenges.challenges.read().unwrap(); + let proof_values_guard = pctx.proof_values.values.read().unwrap(); - let public_inputs = (*public_inputs_guard).as_ptr() as *mut c_void; - let challenges = (*challenges_guard).as_ptr() as *mut c_void; - let proof_values = (*proof_values_guard).as_ptr() as *mut c_void; + let public_inputs = (*public_inputs_guard).as_ptr() as *mut c_void; + let challenges = (*challenges_guard).as_ptr() as *mut c_void; + let proof_values = (*proof_values_guard).as_ptr() as *mut c_void; - let mut stark_infos_recursive2 = Vec::new(); - for (idx, _) in pctx.global_info.air_groups.iter().enumerate() { - stark_infos_recursive2.push(sctx.get_setup(idx, 0).p_setup.p_stark_info); - } + let mut stark_infos_recursive2 = Vec::new(); + for (idx, _) in pctx.global_info.air_groups.iter().enumerate() { + stark_infos_recursive2.push(sctx.get_setup(idx, 0).p_setup.p_stark_info); + } - let proofs_recursive2_ptr = proofs_recursive2.as_mut_ptr(); + let proofs_recursive2_ptr = proofs_recursive2.as_mut_ptr(); - let stark_infos_recursive2_ptr = stark_infos_recursive2.as_mut_ptr(); + let stark_infos_recursive2_ptr = stark_infos_recursive2.as_mut_ptr(); - zkin_final = join_zkin_final_c( - public_inputs, - proof_values, - challenges, - global_info_file, - proofs_recursive2_ptr, - stark_infos_recursive2_ptr, - ); - } + let zkin_final = join_zkin_final_c( + public_inputs, + proof_values, + challenges, + global_info_file, + proofs_recursive2_ptr, + stark_infos_recursive2_ptr, + ); + // } Ok(zkin_final) }