Skip to content

Commit

Permalink
fix tests and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenfeizhang committed Dec 15, 2023
1 parent 26186de commit a166dae
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 38 deletions.
1 change: 0 additions & 1 deletion snark-verifier-sdk/benches/standard_plonk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use halo2_proofs::{
};
use pprof::criterion::{Output, PProfProfiler};
use rand::rngs::OsRng;
use rand::thread_rng;
use snark_verifier_sdk::evm::{evm_verify, gen_evm_proof_shplonk, gen_evm_verifier_shplonk};
use snark_verifier_sdk::halo2::aggregation::{AggregationConfigParams, VerifierUniversality};
use snark_verifier_sdk::{
Expand Down
18 changes: 8 additions & 10 deletions snark-verifier-sdk/examples/k_as_witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ use halo2_base::halo2_proofs::poly::commitment::Params;
use halo2_base::utils::fs::gen_srs;
use halo2_proofs::halo2curves as halo2_curves;

use rand::rngs::StdRng;
use rand::SeedableRng;
use snark_verifier_sdk::halo2::aggregation::{AggregationConfigParams, VerifierUniversality};
use snark_verifier_sdk::SHPLONK;
use snark_verifier_sdk::{
Expand Down Expand Up @@ -107,9 +105,9 @@ mod application {
layouter.assign_region(
|| "",
|mut region| {
region.assign_advice(|| "", config.a, 0, || Value::known(self.0));
region.assign_fixed(|| "", config.q_a, 0, || Value::known(-Fr::one()));
region.assign_advice(|| "", config.a, 1, || Value::known(-Fr::from(5u64)));
region.assign_advice(|| "", config.a, 0, || Value::known(self.0))?;
region.assign_fixed(|| "", config.q_a, 0, || Value::known(-Fr::one()))?;
region.assign_advice(|| "", config.a, 1, || Value::known(-Fr::from(5u64)))?;
for (idx, column) in (1..).zip([
config.q_a,
config.q_b,
Expand All @@ -122,11 +120,11 @@ mod application {
column,
1,
|| Value::known(Fr::from(idx as u64)),
);
)?;
}
let a = region.assign_advice(|| "", config.a, 2, || Value::known(Fr::one()))?;
a.copy_advice(|| "", &mut region, config.b, 3);
a.copy_advice(|| "", &mut region, config.c, 4);
a.copy_advice(|| "", &mut region, config.b, 3)?;
a.copy_advice(|| "", &mut region, config.c, 4)?;

// assuming <= 10 blinding factors
// fill in most of circuit with a computation
Expand All @@ -137,7 +135,7 @@ mod application {
config.a,
offset,
|| Value::known(-Fr::from(5u64)),
);
)?;
for (idx, column) in (1..).zip([
config.q_a,
config.q_b,
Expand All @@ -150,7 +148,7 @@ mod application {
column,
offset,
|| Value::known(Fr::from(idx as u64)),
);
)?;
}
}

Expand Down
12 changes: 6 additions & 6 deletions snark-verifier-sdk/examples/vkey_as_witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ mod application {
layouter.assign_region(
|| "",
|mut region| {
region.assign_advice(|| "", config.a, 0, || Value::known(self.0));
region.assign_fixed(|| "", config.q_a, 0, || Value::known(-Fr::one()));
region.assign_advice(|| "", config.a, 1, || Value::known(-Fr::from(5u64)));
region.assign_advice(|| "", config.a, 0, || Value::known(self.0))?;
region.assign_fixed(|| "", config.q_a, 0, || Value::known(-Fr::one()))?;
region.assign_advice(|| "", config.a, 1, || Value::known(-Fr::from(5u64)))?;
if self.1 != ComputeFlag::SkipFixed {
for (idx, column) in (1..).zip([
config.q_a,
Expand All @@ -131,13 +131,13 @@ mod application {
column,
1,
|| Value::known(Fr::from(idx as u64)),
);
)?;
}
}
let a = region.assign_advice(|| "", config.a, 2, || Value::known(Fr::one()))?;
if self.1 != ComputeFlag::SkipCopy {
a.copy_advice(|| "", &mut region, config.b, 3);
a.copy_advice(|| "", &mut region, config.c, 4);
a.copy_advice(|| "", &mut region, config.b, 3)?;
a.copy_advice(|| "", &mut region, config.c, 4)?;
}

Ok(())
Expand Down
13 changes: 6 additions & 7 deletions snark-verifier/examples/evm-verifier-with-accumulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use halo2_proofs::{
commitment::ParamsProver,
kzg::{
commitment::{KZGCommitmentScheme, ParamsKZG},
multiopen::{ProverGWC, VerifierGWC},
multiopen::{ProverSHPLONK, VerifierSHPLONK},
strategy::AccumulatorStrategy,
},
VerificationStrategy,
Expand All @@ -26,7 +26,7 @@ use snark_verifier::{
evm::{self, deploy_and_call, encode_calldata, EvmLoader},
native::NativeLoader,
},
pcs::kzg::{Gwc19, KzgAs, LimbsEncoding},
pcs::kzg::{Bdfg21, KzgAs, LimbsEncoding},
system::halo2::{compile, transcript::evm::EvmTranscript, Config},
verifier::{self, SnarkVerifier},
};
Expand All @@ -35,7 +35,7 @@ use std::{fs::File, io::Cursor, rc::Rc};
const LIMBS: usize = 3;
const BITS: usize = 88;

type As = KzgAs<Bn256, Gwc19>;
type As = KzgAs<Bn256, Bdfg21>;
type PlonkSuccinctVerifier = verifier::plonk::PlonkSuccinctVerifier<As, LimbsEncoding<LIMBS, BITS>>;
type PlonkVerifier = verifier::plonk::PlonkVerifier<As, LimbsEncoding<LIMBS, BITS>>;

Expand All @@ -46,7 +46,6 @@ mod application {
poly::Rotation,
};
use super::Fr;
use halo2_base::halo2_proofs::plonk::Assigned;
use rand::RngCore;

#[derive(Clone, Copy)]
Expand Down Expand Up @@ -430,7 +429,7 @@ fn gen_proof<
let instances = instances.iter().map(|instances| instances.as_slice()).collect_vec();
let proof = {
let mut transcript = TW::init(Vec::new());
create_proof::<KZGCommitmentScheme<Bn256>, ProverGWC<_>, _, _, TW, _>(
create_proof::<KZGCommitmentScheme<Bn256>, ProverSHPLONK<_>, _, _, TW, _>(
params,
pk,
&[circuit],
Expand All @@ -444,8 +443,8 @@ fn gen_proof<

let accept = {
let mut transcript = TR::init(Cursor::new(proof.clone()));
VerificationStrategy::<_, VerifierGWC<_>>::finalize(
verify_proof::<_, VerifierGWC<_>, _, TR, _>(
VerificationStrategy::<_, VerifierSHPLONK<_>>::finalize(
verify_proof::<_, VerifierSHPLONK<_>, _, TR, _>(
params.verifier_params(),
pk.get_vk(),
AccumulatorStrategy::new(params.verifier_params()),
Expand Down
28 changes: 14 additions & 14 deletions snark-verifier/examples/evm-verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use halo2_proofs::{
dev::MockProver,
halo2curves::bn256::{Bn256, Fq, Fr, G1Affine},
plonk::{
create_proof, keygen_pk, keygen_vk, verify_proof, Advice, Assigned, Circuit, Column,
create_proof, keygen_pk, keygen_vk, verify_proof, Advice, Circuit, Column,
ConstraintSystem, Error, Fixed, Instance, ProvingKey, VerifyingKey,
},
poly::{
commitment::{Params, ParamsProver},
kzg::{
commitment::{KZGCommitmentScheme, ParamsKZG},
multiopen::{ProverGWC, VerifierGWC},
multiopen::{ProverSHPLONK, VerifierSHPLONK},
strategy::AccumulatorStrategy,
},
Rotation, VerificationStrategy,
Expand All @@ -22,13 +22,13 @@ use itertools::Itertools;
use rand::{rngs::OsRng, RngCore};
use snark_verifier::{
loader::evm::{self, deploy_and_call, encode_calldata, EvmLoader},
pcs::kzg::{Gwc19, KzgAs},
pcs::kzg::{Bdfg21, KzgAs},
system::halo2::{compile, transcript::evm::EvmTranscript, Config},
verifier::{self, SnarkVerifier},
};
use std::rc::Rc;

type PlonkVerifier = verifier::plonk::PlonkVerifier<KzgAs<Bn256, Gwc19>>;
type PlonkVerifier = verifier::plonk::PlonkVerifier<KzgAs<Bn256, Bdfg21>>;

#[derive(Clone, Copy)]
struct StandardPlonkConfig {
Expand Down Expand Up @@ -192,22 +192,22 @@ fn gen_proof<C: Circuit<Fr>>(
let instances = instances.iter().map(|instances| instances.as_slice()).collect_vec();
let proof = {
let mut transcript = TranscriptWriterBuffer::<_, G1Affine, _>::init(Vec::new());
create_proof::<KZGCommitmentScheme<Bn256>, ProverGWC<_>, _, _, EvmTranscript<_, _, _, _>, _>(
params,
pk,
&[circuit],
&[instances.as_slice()],
OsRng,
&mut transcript,
)
create_proof::<
KZGCommitmentScheme<Bn256>,
ProverSHPLONK<_>,
_,
_,
EvmTranscript<_, _, _, _>,
_,
>(params, pk, &[circuit], &[instances.as_slice()], OsRng, &mut transcript)
.unwrap();
transcript.finalize()
};

let accept = {
let mut transcript = TranscriptReadBuffer::<_, G1Affine, _>::init(proof.as_slice());
VerificationStrategy::<_, VerifierGWC<_>>::finalize(
verify_proof::<_, VerifierGWC<_>, _, EvmTranscript<_, _, _, _>, _>(
VerificationStrategy::<_, VerifierSHPLONK<_>>::finalize(
verify_proof::<_, VerifierSHPLONK<_>, _, EvmTranscript<_, _, _, _>, _>(
params.verifier_params(),
pk.get_vk(),
AccumulatorStrategy::new(params.verifier_params()),
Expand Down

0 comments on commit a166dae

Please sign in to comment.