-
Notifications
You must be signed in to change notification settings - Fork 225
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
zkInterface backend #279
Open
naure
wants to merge
7
commits into
dalek-cryptography:main
Choose a base branch
from
QED-it:zkinterface
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
zkInterface backend #279
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
de058f0
R1CS backend for zkInterface circuits.
naure 0eac777
R1CSProof serialization.
naure 59c2e1b
Update zkinterface
naure 9858515
Use rustfmt-preview
naure a09c92a
zkinterface: upgrade to 1.1.3
naure 9eb67fa
zkinterface: executable prover and verifier
naure c210e4f
Upgrade to zkinterface 1.3.3
naure 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 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 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,73 @@ | ||
extern crate bincode; | ||
extern crate bulletproofs; | ||
extern crate zkinterface; | ||
|
||
use std::env; | ||
use std::io::{stdin, Read, Write}; | ||
use std::fs::{File, create_dir_all}; | ||
use std::path::Path; | ||
use self::zkinterface::{Result, Reader}; | ||
use bulletproofs::r1cs::{zkinterface_backend, R1CSProof}; | ||
|
||
const USAGE: &str = "Bulletproofs proving system. | ||
|
||
zkif_bulletproofs prove [proof_path] | ||
zkif_bulletproofs verify [proof_path] | ||
|
||
"; | ||
|
||
const DEFAULT_PROOF_PATH: &str = "bulletproofs-proof"; | ||
|
||
pub fn main() -> Result<()> { | ||
let args: Vec<String> = env::args().collect(); | ||
let args: Vec<&str> = args.iter().map(|a| &a[..]).collect(); | ||
if args.len() <= 1 { | ||
eprintln!("{}", USAGE); | ||
return Err("Missing command.".into()); | ||
} | ||
|
||
let command = args[1]; | ||
|
||
let proof_path = if args.len() == 2 { DEFAULT_PROOF_PATH } else { args[2] }; | ||
let proof_path = Path::new(proof_path); | ||
if let Some(parent) = proof_path.parent() { | ||
create_dir_all(parent)?; | ||
} | ||
|
||
let read = || -> Result<Reader> { | ||
let mut messages = Reader::new(); | ||
messages.read_from(&mut stdin())?; | ||
Ok(messages) | ||
}; | ||
|
||
match &command[..] { | ||
"prove" => main_prove(read()?, proof_path), | ||
"verify" => main_verify(read()?, proof_path), | ||
_ => { | ||
eprintln!("{}", USAGE); | ||
Err(format!("Unknown command {}", command).into()) | ||
} | ||
} | ||
} | ||
|
||
fn main_prove(messages: Reader, proof_path: &Path) -> Result<()> { | ||
let proof = zkinterface_backend::prove(&messages)?; | ||
|
||
// Save to file. | ||
let proof_ser = bincode::serialize(&proof)?; | ||
File::create(proof_path)?.write_all(&proof_ser)?; | ||
|
||
eprintln!("Saved proof into {}", proof_path.display()); | ||
Ok(()) | ||
} | ||
|
||
fn main_verify(messages: Reader, proof_path: &Path) -> Result<()> { | ||
eprintln!("Verifying proof in {}", proof_path.display()); | ||
|
||
// Load from file. | ||
let mut proof_ser = Vec::new(); | ||
File::open(&proof_path)?.read_to_end(&mut proof_ser)?; | ||
let proof: R1CSProof = bincode::deserialize(&proof_ser)?; | ||
|
||
zkinterface_backend::verify(&messages, &proof) | ||
} |
This file contains 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 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 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.
First thought: can we make zkinterface depend on yoloproofs, not the other way around? Then the user is able to use R1CS w/o zkinterface.