-
Notifications
You must be signed in to change notification settings - Fork 52
Add Circuit and Witness serialization for GPU prover #299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
7b575f1
f8355d6
1ca865d
09c2f09
6f4aef2
3e416fb
31b7294
45ab662
a17c824
8c76e7e
d554633
b8abe7a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,8 @@ pub fn gkr_prove<F: FieldEngine>( | |
| sp: &mut ProverScratchPad<F>, | ||
| transcript: &mut impl Transcript, | ||
| mpi_config: &MPIConfig, | ||
| ) -> (F::ChallengeField, ExpanderDualVarChallenge<F>) { | ||
| ) -> (F::ChallengeField, ExpanderDualVarChallenge<F>) | ||
| where F::CircuitField: std::fmt::Debug, F::SimdCircuitField: std::fmt::Debug { | ||
| let layer_num = circuit.layers.len(); | ||
|
|
||
| let mut challenge: ExpanderDualVarChallenge<F> = | ||
|
|
@@ -36,6 +37,16 @@ pub fn gkr_prove<F: FieldEngine>( | |
| mpi_config, | ||
| ); | ||
|
|
||
| // Serialize circuit to file if EXPANDER_GPU environment variable is set to 1 | ||
| if std::env::var("EXPANDER_GPU").map_or(false, |v| v == "1") { | ||
|
||
| if let Err(e) = gpu::serdes::serial_circuit_witness_as_plaintext(circuit, transcript, &challenge) { | ||
| println!("Failed to serialize circuit: {}", e); | ||
|
||
| } | ||
| } | ||
|
|
||
| let mut final_vx_claim = None; | ||
| let mut final_vy_claim = None; | ||
|
|
||
| for i in (0..layer_num).rev() { | ||
| let timer = Timer::new( | ||
| &format!( | ||
|
|
@@ -47,7 +58,7 @@ pub fn gkr_prove<F: FieldEngine>( | |
| mpi_config.is_root(), | ||
| ); | ||
|
|
||
| (_, _) = sumcheck_prove_gkr_layer( | ||
| let (vx_claim, vy_claim) = sumcheck_prove_gkr_layer( | ||
| &circuit.layers[i], | ||
| &mut challenge, | ||
| alpha, | ||
|
|
@@ -57,6 +68,12 @@ pub fn gkr_prove<F: FieldEngine>( | |
| i == layer_num - 1, | ||
| ); | ||
|
|
||
| // Store the final layer claims for later use | ||
| if i == 0 { | ||
| final_vx_claim = Some(vx_claim); | ||
| final_vy_claim = vy_claim; | ||
| } | ||
|
|
||
| if challenge.rz_1.is_some() { | ||
| // TODO: try broadcast beta.unwrap directly | ||
| let mut tmp = transcript.generate_field_element::<F::ChallengeField>(); | ||
|
|
@@ -68,5 +85,14 @@ pub fn gkr_prove<F: FieldEngine>( | |
| timer.stop(); | ||
| } | ||
|
|
||
| // Print final claims if EXPANDER_GPU environment variable is set to 1 | ||
| if std::env::var("EXPANDER_GPU").map_or(false, |v| v == "1") { | ||
| if let Some(vx) = final_vx_claim { | ||
| gpu::serdes::print_final_claims::<F>(&vx, &final_vy_claim); | ||
| println!("GKR final proof claims as shown above."); | ||
| std::process::exit(0); | ||
| } | ||
| } | ||
|
||
|
|
||
| (claimed_v, challenge) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| [package] | ||
| name = "gpu" | ||
| version = "0.1.0" | ||
| edition = "2021" | ||
|
|
||
| [dependencies] | ||
| circuit = { path = "../circuit" } | ||
| gkr_engine = { path = "../gkr_engine" } | ||
| gkr_hashers = { path = "../hasher" } | ||
| transcript = { path = "../transcript" } | ||
| thiserror.workspace = true |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| pub mod serdes; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The check for the
EXPANDER_GPUenvironment variable and its value ("1") is duplicated across multiplematcharms (e.g., here and on lines 122-126). This introduces redundancy and makes the code less maintainable. Consider extracting this check into a boolean variable at the start ofmainand using constants for the environment variable name and value. This improves readability and reduces repetition.Example: