Skip to content

Commit

Permalink
Implement Sangria backend based on HyperPlonk (#22)
Browse files Browse the repository at this point in the history
* feat: implement sangria with hyperplonk

* feat: refactor evaluators

* refactor: for future changes
  • Loading branch information
han0110 committed Jun 12, 2023
1 parent 95c9eda commit 415f976
Show file tree
Hide file tree
Showing 20 changed files with 2,177 additions and 474 deletions.
2 changes: 1 addition & 1 deletion benchmark/benches/proof_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ fn bench_hyperplonk<C: CircuitExt<Fr>>(k: usize) {
let _timer = start_timer(|| format!("hyperplonk_verify-{k}"));
let accept = {
let mut transcript = Keccak256Transcript::from_proof(proof.as_slice());
HyperPlonk::verify(&vp, &instances, &mut transcript, std_rng()).is_ok()
HyperPlonk::verify(&vp, (), &instances, &mut transcript, std_rng()).is_ok()
};
assert!(accept);
}
Expand Down
11 changes: 5 additions & 6 deletions benchmark/src/bin/plotter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,9 @@ fn main() {
}

fn parse_args() -> (bool, Vec<String>) {
let (verbose, logs) = args()
.into_iter()
.chain(Some("".to_string()))
.tuple_windows()
.fold((false, None), |(mut verbose, mut logs), (key, value)| {
let (verbose, logs) = args().chain(Some("".to_string())).tuple_windows().fold(
(false, None),
|(mut verbose, mut logs), (key, value)| {
match key.as_str() {
"-" => {
logs = Some(
Expand All @@ -85,7 +83,8 @@ fn parse_args() -> (bool, Vec<String>) {
_ => {}
};
(verbose, logs)
});
},
);
(
verbose,
logs.expect("Either \"--log <LOG>\" or \"-\" specified"),
Expand Down
2 changes: 1 addition & 1 deletion plonkish_backend/benches/zero_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn run(num_vars: usize, virtual_poly: VirtualPolynomial<Fr>) {

fn zero_check(c: &mut Criterion) {
let setup = |num_vars: usize| {
let expression = vanilla_plonk_expression();
let expression = vanilla_plonk_expression(num_vars);
let (polys, challenges) =
rand_vanilla_plonk_assignment::<Fr>(num_vars, seeded_std_rng(), seeded_std_rng());
let ys = [rand_vec(num_vars, seeded_std_rng())];
Expand Down
2 changes: 2 additions & 0 deletions plonkish_backend/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ where
type ProverParam: Debug;
type VerifierParam: Debug;
type ProverState: Debug;
type VerifierState: Debug;

fn setup(circuit_info: &PlonkishCircuitInfo<F>, rng: impl RngCore)
-> Result<Pcs::Param, Error>;
Expand All @@ -41,6 +42,7 @@ where

fn verify(
vp: &Self::VerifierParam,
state: impl BorrowMut<Self::VerifierState>,
instances: &[&[F]],
transcript: &mut impl TranscriptRead<Pcs::CommitmentChunk, F>,
rng: impl RngCore,
Expand Down
6 changes: 5 additions & 1 deletion plonkish_backend/src/backend/hyperplonk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ mod preprocessor;
mod prover;
mod verifier;

pub mod folding;

#[cfg(any(test, feature = "benchmark"))]
pub mod util;

Expand Down Expand Up @@ -81,6 +83,7 @@ where
type ProverParam = HyperPlonkProverParam<F, Pcs>;
type VerifierParam = HyperPlonkVerifierParam<F, Pcs>;
type ProverState = ();
type VerifierState = ();

fn setup(
circuit_info: &PlonkishCircuitInfo<F>,
Expand Down Expand Up @@ -291,6 +294,7 @@ where

fn verify(
vp: &Self::VerifierParam,
_: impl BorrowMut<Self::VerifierState>,
instances: &[&[F]],
transcript: &mut impl TranscriptRead<Pcs::CommitmentChunk, F>,
_: impl RngCore,
Expand Down Expand Up @@ -447,7 +451,7 @@ pub(crate) mod test {
let timer = start_timer(|| format!("verify-{num_vars}"));
let result = {
let mut transcript = T::from_proof(proof.as_slice());
HyperPlonk::<Pcs>::verify(&vp, &instances, &mut transcript, seeded_std_rng())
HyperPlonk::<Pcs>::verify(&vp, (), &instances, &mut transcript, seeded_std_rng())
};
assert_eq!(result, Ok(()));
end_timer(timer);
Expand Down
3 changes: 3 additions & 0 deletions plonkish_backend/src/backend/hyperplonk/folding.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod sangria;

pub use sangria::{Sangria, SangriaProverParam, SangriaProverState, SangriaVerifierParam};
Loading

0 comments on commit 415f976

Please sign in to comment.