Skip to content

Commit

Permalink
Fixing proof_values proof
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerTaule committed Dec 12, 2024
1 parent ef788fd commit e12ce1c
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 4 deletions.
41 changes: 41 additions & 0 deletions common/src/air_instances_repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@ use p3_field::Field;

use crate::AirInstance;

// #[derive(Default)]
// pub struct InstancesInfo {
// pub my_groups: Vec<Vec<usize>>,
// pub my_air_groups: Vec<Vec<usize>>,
// }
pub struct AirInstancesRepository<F> {
pub air_instances: RwLock<Vec<AirInstance<F>>>,
pub air_instances_counts: RwLock<HashMap<(usize, usize), usize>>,
// pub instances_info: RwLock<InstancesInfo>,
}

impl<F: Field> Default for AirInstancesRepository<F> {
Expand All @@ -20,6 +26,7 @@ impl<F: Field> AirInstancesRepository<F> {
AirInstancesRepository {
air_instances: RwLock::new(Vec::new()),
air_instances_counts: RwLock::new(HashMap::new()),
// instances_info: RwLock::new(InstancesInfo::default()),
}
}

Expand Down Expand Up @@ -64,6 +71,40 @@ impl<F: Field> AirInstancesRepository<F> {
indices
}

// pub fn calculate_my_groups(&self) {
// let mut group_indices: BTreeMap<usize, Vec<usize>> = 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<usize>> = 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<usize> {
let air_instances = self.air_instances.read().unwrap();

Expand Down
2 changes: 1 addition & 1 deletion pil2-stark/lib/include/starks_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
10 changes: 9 additions & 1 deletion pil2-stark/src/api/starks_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void fri_proof_set_airvalues(void *pFriProof, void *airValues)
FRIProof<Goldilocks::Element> *friProof = (FRIProof<Goldilocks::Element> *)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);
Expand All @@ -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"];
Expand Down
2 changes: 1 addition & 1 deletion pil2-stark/src/api/starks_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 4 additions & 0 deletions provers/stark/src/stark_prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,9 @@ impl<F: Field> Prover<F> for StarkProver<F> {
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();

Expand All @@ -691,6 +694,7 @@ impl<F: Field> Prover<F> for StarkProver<F> {
self.p_proof,
public_inputs,
challenges,
proof_values,
self.p_stark_info,
&proof_name,
global_info_file,
Expand Down
3 changes: 2 additions & 1 deletion provers/starks-lib-c/bindings_starks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions provers/starks-lib-c/src/ffi_starks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit e12ce1c

Please sign in to comment.