diff --git a/common/src/air_instances_repository.rs b/common/src/air_instances_repository.rs index 15e1a616..d8dffd60 100644 --- a/common/src/air_instances_repository.rs +++ b/common/src/air_instances_repository.rs @@ -4,9 +4,15 @@ use p3_field::Field; use crate::AirInstance; +// #[derive(Default)] +// pub struct InstancesInfo { +// pub my_groups: Vec>, +// pub my_air_groups: Vec>, +// } pub struct AirInstancesRepository { pub air_instances: RwLock>>, pub air_instances_counts: RwLock>, + // pub instances_info: RwLock, } impl Default for AirInstancesRepository { @@ -20,6 +26,7 @@ impl AirInstancesRepository { AirInstancesRepository { air_instances: RwLock::new(Vec::new()), air_instances_counts: RwLock::new(HashMap::new()), + // instances_info: RwLock::new(InstancesInfo::default()), } } @@ -64,6 +71,40 @@ impl AirInstancesRepository { indices } + // pub fn calculate_my_groups(&self) { + // let mut group_indices: BTreeMap> = BTreeMap::new(); + + // let air_instances = self.air_instances.read().unwrap(); + + // let mut instances_info = self.instances_info.write().unwrap(); + + // // Populate the HashMap based on group_id and buffer positions + // for (idx, instance) in air_instances.iter().enumerate() { + // #[cfg(feature = "distributed")] + // let pos_buffer = + // self.roots_gatherv_displ[self.instances_owner[idx].0] as usize + self.instances_owner[idx].1 * 4; + // #[cfg(not(feature = "distributed"))] + // let pos_buffer = idx * 4; + // group_indices.entry(instance.airgroup_id).or_default().push(pos_buffer); + // } + + // for (_, indices) in group_indices { + // instances_info.my_groups.push(indices); + // } + + // let mut my_air_groups_indices: HashMap<(usize, usize), Vec> = HashMap::new(); + // for (loc_idx, air_instance) in air_instances.iter().enumerate() { + // my_air_groups_indices.entry((air_instance.airgroup_id, air_instance.air_id)).or_default().push(loc_idx); + // } + + // for (_, indices) in my_air_groups_indices { + // instances_info.my_air_groups.push(indices); + // } + + // println!("// MY AIR GROUPS {:?} // MY GROUPS {:?}", instances_info.my_air_groups, instances_info.my_groups); + + // } + pub fn find_last_segment(&self, airgroup_id: usize, air_id: usize) -> Option { let air_instances = self.air_instances.read().unwrap(); diff --git a/pil2-stark/lib/include/starks_lib.h b/pil2-stark/lib/include/starks_lib.h index f0eee00a..0c24fbf4 100644 --- a/pil2-stark/lib/include/starks_lib.h +++ b/pil2-stark/lib/include/starks_lib.h @@ -14,7 +14,7 @@ void fri_proof_get_tree_root(void *pFriProof, void* root, uint64_t tree_index); void fri_proof_set_airgroupvalues(void *pFriProof, void *airgroupValues); void fri_proof_set_airvalues(void *pFriProof, void *airValues); - void *fri_proof_get_zkinproof(void *pFriProof, void* pPublics, void* pChallenges, void *pStarkInfo, char* proof_name, char* globalInfoFile, char *fileDir); + void *fri_proof_get_zkinproof(void *pFriProof, void* pPublics, void* pChallenges, void *pProofValues, void *pStarkInfo, char* proof_name, char* globalInfoFile, char *fileDir); void fri_proof_free_zkinproof(void *pZkinProof); void fri_proof_free(void *pFriProof); diff --git a/pil2-stark/src/api/starks_api.cpp b/pil2-stark/src/api/starks_api.cpp index 16b2ac61..36697ac6 100644 --- a/pil2-stark/src/api/starks_api.cpp +++ b/pil2-stark/src/api/starks_api.cpp @@ -89,7 +89,7 @@ void fri_proof_set_airvalues(void *pFriProof, void *airValues) FRIProof *friProof = (FRIProof *)pFriProof; friProof->proof.setAirValues((Goldilocks::Element *)airValues); } -void *fri_proof_get_zkinproof(void *pFriProof, void* pPublics, void* pChallenges, void *pStarkInfo, char* proof_name, char* globalInfoFile, char *fileDir) +void *fri_proof_get_zkinproof(void *pFriProof, void* pPublics, void* pChallenges, void *pProofValues, void *pStarkInfo, char* proof_name, char* globalInfoFile, char *fileDir) { json globalInfo; file2json(globalInfoFile, globalInfo); @@ -101,12 +101,20 @@ void *fri_proof_get_zkinproof(void *pFriProof, void* pPublics, void* pChallenges Goldilocks::Element *publics = (Goldilocks::Element *)pPublics; Goldilocks::Element *challenges = (Goldilocks::Element *)pChallenges; + Goldilocks::Element *proofValues = (Goldilocks::Element *)pProofValues; for (uint64_t i = 0; i < starkInfo.nPublics; i++) { zkin["publics"][i] = Goldilocks::toString(publics[i]); } + for (uint64_t i = 0; i < starkInfo.proofValuesMap.size(); i++) + { + zkin["proofValues"][i][0] = Goldilocks::toString(proofValues[i*FIELD_EXTENSION]); + zkin["proofValues"][i][1] = Goldilocks::toString(proofValues[i*FIELD_EXTENSION + 1]); + zkin["proofValues"][i][2] = Goldilocks::toString(proofValues[i*FIELD_EXTENSION + 2]); + } + json challengesJson = challenges2zkin(globalInfo, challenges); zkin["challenges"] = challengesJson["challenges"]; zkin["challengesFRISteps"] = challengesJson["challengesFRISteps"]; diff --git a/pil2-stark/src/api/starks_api.hpp b/pil2-stark/src/api/starks_api.hpp index f0eee00a..0c24fbf4 100644 --- a/pil2-stark/src/api/starks_api.hpp +++ b/pil2-stark/src/api/starks_api.hpp @@ -14,7 +14,7 @@ void fri_proof_get_tree_root(void *pFriProof, void* root, uint64_t tree_index); void fri_proof_set_airgroupvalues(void *pFriProof, void *airgroupValues); void fri_proof_set_airvalues(void *pFriProof, void *airValues); - void *fri_proof_get_zkinproof(void *pFriProof, void* pPublics, void* pChallenges, void *pStarkInfo, char* proof_name, char* globalInfoFile, char *fileDir); + void *fri_proof_get_zkinproof(void *pFriProof, void* pPublics, void* pChallenges, void *pProofValues, void *pStarkInfo, char* proof_name, char* globalInfoFile, char *fileDir); void fri_proof_free_zkinproof(void *pZkinProof); void fri_proof_free(void *pFriProof); diff --git a/provers/stark/src/stark_prover.rs b/provers/stark/src/stark_prover.rs index e4c548ae..970bf174 100644 --- a/provers/stark/src/stark_prover.rs +++ b/provers/stark/src/stark_prover.rs @@ -681,6 +681,9 @@ impl Prover for StarkProver { let challenges_guard = proof_ctx.challenges.challenges.read().unwrap(); let challenges = (*challenges_guard).as_ptr() as *mut c_void; + let proof_values_guard = proof_ctx.proof_values.values.read().unwrap(); + let proof_values = (*proof_values_guard).as_ptr() as *mut c_void; + let global_info_path = proof_ctx.global_info.get_proving_key_path().join("pilout.globalInfo.json"); let global_info_file: &str = global_info_path.to_str().unwrap(); @@ -691,6 +694,7 @@ impl Prover for StarkProver { self.p_proof, public_inputs, challenges, + proof_values, self.p_stark_info, &proof_name, global_info_file, diff --git a/provers/starks-lib-c/bindings_starks.rs b/provers/starks-lib-c/bindings_starks.rs index 438b1a47..d4b385f8 100644 --- a/provers/starks-lib-c/bindings_starks.rs +++ b/provers/starks-lib-c/bindings_starks.rs @@ -49,11 +49,12 @@ extern "C" { ); } extern "C" { - #[link_name = "\u{1}_Z23fri_proof_get_zkinproofPvS_S_S_PcS0_S0_"] + #[link_name = "\u{1}_Z23fri_proof_get_zkinproofPvS_S_S_S_PcS0_S0_"] pub fn fri_proof_get_zkinproof( pFriProof: *mut ::std::os::raw::c_void, pPublics: *mut ::std::os::raw::c_void, pChallenges: *mut ::std::os::raw::c_void, + pProofValues: *mut ::std::os::raw::c_void, pStarkInfo: *mut ::std::os::raw::c_void, proof_name: *mut ::std::os::raw::c_char, globalInfoFile: *mut ::std::os::raw::c_char, diff --git a/provers/starks-lib-c/src/ffi_starks.rs b/provers/starks-lib-c/src/ffi_starks.rs index 94e02880..f2e6159d 100644 --- a/provers/starks-lib-c/src/ffi_starks.rs +++ b/provers/starks-lib-c/src/ffi_starks.rs @@ -75,6 +75,7 @@ pub fn fri_proof_get_zkinproof_c( p_fri_proof: *mut c_void, p_publics: *mut c_void, p_challenges: *mut c_void, + p_proof_values: *mut c_void, p_stark_info: *mut c_void, proof_name: &str, global_info_file: &str, @@ -94,6 +95,7 @@ pub fn fri_proof_get_zkinproof_c( p_fri_proof, p_publics, p_challenges, + p_proof_values, p_stark_info, proof_name_ptr, global_info_file_ptr, @@ -965,6 +967,7 @@ pub fn fri_proof_get_zkinproof_c( _p_fri_proof: *mut c_void, _p_publics: *mut c_void, _p_challenges: *mut c_void, + _p_proof_values: *mut c_void, _p_stark_info: *mut c_void, _proof_name: &str, _global_info_file: &str,