-
Notifications
You must be signed in to change notification settings - Fork 34
Add prover binary #875
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
Closed
Closed
Add prover binary #875
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| use std::{fs, path::PathBuf}; | ||
|
|
||
| use anyhow::{Context, Result}; | ||
| use binius_core::constraint_system::{ConstraintSystem, Proof, ValueVec, ValuesData}; | ||
| use binius_examples::setup; | ||
| use binius_utils::serialization::{DeserializeBytes, SerializeBytes}; | ||
| use binius_verifier::{ | ||
| config::{ChallengerWithName, StdChallenger}, | ||
| transcript::ProverTranscript, | ||
| }; | ||
| use clap::Parser; | ||
|
|
||
| /// Prover CLI: generate a proof from a serialized constraint system and witnesses. | ||
| #[derive(Debug, Parser)] | ||
| #[command( | ||
| name = "prover", | ||
| about = "Generate and save a proof from CS and witnesses" | ||
| )] | ||
| struct Args { | ||
| /// Path to the constraint system binary | ||
| #[arg(long = "cs-path")] | ||
| cs_path: PathBuf, | ||
|
|
||
| /// Path to the public values (ValuesData) binary | ||
| #[arg(long = "pub-witness-path")] | ||
| pub_witness_path: PathBuf, | ||
|
|
||
| /// Path to the non-public values (ValuesData) binary | ||
| #[arg(long = "non-pub-data-path")] | ||
| non_pub_data_path: PathBuf, | ||
|
|
||
| /// Path to write the proof binary | ||
| #[arg(long = "proof-path")] | ||
| proof_path: PathBuf, | ||
|
|
||
| /// Log of the inverse rate for the proof system | ||
| #[arg(short = 'l', long = "log-inv-rate", default_value_t = 1, value_parser = clap::value_parser!(u32).range(1..))] | ||
| log_inv_rate: u32, | ||
| } | ||
|
|
||
| fn main() -> Result<()> { | ||
| let _tracing_guard = tracing_profile::init_tracing().ok(); | ||
| let args = Args::parse(); | ||
|
|
||
| // Read and deserialize constraint system | ||
| let cs_bytes = fs::read(&args.cs_path).with_context(|| { | ||
| format!("Failed to read constraint system from {}", args.cs_path.display()) | ||
| })?; | ||
| let cs = ConstraintSystem::deserialize(&mut cs_bytes.as_slice()) | ||
| .context("Failed to deserialize ConstraintSystem")?; | ||
|
|
||
| // Read and deserialize public values | ||
| let pub_bytes = fs::read(&args.pub_witness_path).with_context(|| { | ||
| format!("Failed to read public values from {}", args.pub_witness_path.display()) | ||
| })?; | ||
| let public = ValuesData::deserialize(&mut pub_bytes.as_slice()) | ||
| .context("Failed to deserialize public ValuesData")?; | ||
|
|
||
| // Read and deserialize non-public values | ||
| let non_pub_bytes = fs::read(&args.non_pub_data_path).with_context(|| { | ||
| format!("Failed to read non-public values from {}", args.non_pub_data_path.display()) | ||
| })?; | ||
| let non_public = ValuesData::deserialize(&mut non_pub_bytes.as_slice()) | ||
| .context("Failed to deserialize non-public ValuesData")?; | ||
|
|
||
| // Reconstruct the full ValueVec | ||
| // Take ownership of the underlying vectors without extra copies | ||
| let public: Vec<_> = public.into(); | ||
| let non_public: Vec<_> = non_public.into(); | ||
| let witness = ValueVec::new_from_data(cs.value_vec_layout.clone(), public, non_public) | ||
| .context("Failed to reconstruct ValueVec from provided values")?; | ||
|
|
||
| // Setup prover (verifier is not used here) | ||
| let (_verifier, prover) = setup(cs, args.log_inv_rate as usize)?; | ||
|
|
||
| // Prove | ||
| let mut prover_transcript = ProverTranscript::new(StdChallenger::default()); | ||
| prover | ||
| .prove(witness, &mut prover_transcript) | ||
| .context("Proving failed")?; | ||
| let transcript = prover_transcript.finalize(); | ||
|
|
||
| // Wrap into serializable Proof with a stable challenger type identifier. | ||
| // NOTE: Avoid std::any::type_name for cross-platform stability; use a constant instead. | ||
| let proof = Proof::owned(transcript, StdChallenger::NAME.to_string()); | ||
|
|
||
| // Serialize and save the proof | ||
| if let Some(parent) = args.proof_path.parent() | ||
| && !parent.as_os_str().is_empty() | ||
| { | ||
| fs::create_dir_all(parent) | ||
| .with_context(|| format!("Failed to create parent directory {}", parent.display()))?; | ||
| } | ||
| let mut buf = Vec::new(); | ||
| proof | ||
| .serialize(&mut buf) | ||
| .context("Failed to serialize proof")?; | ||
| fs::write(&args.proof_path, &buf) | ||
| .with_context(|| format!("Failed to write proof to {}", args.proof_path.display()))?; | ||
|
|
||
| tracing::info!("Saved proof to {} ({} bytes)", args.proof_path.display(), buf.len()); | ||
| Ok(()) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
parent.as_os_str().is_empty()check is unnecessary here. WhenPath::parent()returnsSome(parent), the parent path is never empty - it would returnNonefor a path with no parent component. The condition can be simplified to:This maintains the same behavior while removing the redundant check.
Spotted by Diamond

Is this helpful? React 👍 or 👎 to let us know.