Update test to pass multiple ConcreteCircuits

This commit is contained in:
therealyingtong 2021-01-20 21:48:51 +08:00
parent def65609b1
commit de86391f0e
4 changed files with 38 additions and 9 deletions

View File

@ -20,6 +20,7 @@ fn bench_with_k(name: &str, k: u32, c: &mut Criterion) {
// Initialize the polynomial commitment parameters
let params: Params<EqAffine> = Params::new(k);
#[derive(Copy, Clone)]
struct PLONKConfig {
a: Column<Advice>,
b: Column<Advice>,
@ -43,6 +44,7 @@ fn bench_with_k(name: &str, k: u32, c: &mut Criterion) {
fn copy(&mut self, a: Variable, b: Variable) -> Result<(), Error>;
}
#[derive(Clone)]
struct MyCircuit<F: FieldExt> {
a: Option<F>,
k: u32,
@ -241,7 +243,7 @@ fn bench_with_k(name: &str, k: u32, c: &mut Criterion) {
// Create a proof
let mut transcript = DummyHashWrite::init(vec![], Fq::one());
create_proof(&params, &pk, &circuit, &[], &mut transcript)
create_proof(&params, &pk, &[circuit], &[], &mut transcript)
.expect("proof generation should not fail")
});
});
@ -253,7 +255,7 @@ fn bench_with_k(name: &str, k: u32, c: &mut Criterion) {
// Create a proof
let mut transcript = DummyHashWrite::init(vec![], Fq::one());
create_proof(&params, &pk, &circuit, &[], &mut transcript)
create_proof(&params, &pk, &[circuit], &[], &mut transcript)
.expect("proof generation should not fail");
let proof = transcript.finalize();

View File

@ -16,6 +16,7 @@ use std::marker::PhantomData;
#[derive(Copy, Clone, Debug)]
pub struct Variable(Column<Advice>, usize);
#[derive(Copy, Clone)]
struct PLONKConfig {
a: Column<Advice>,
b: Column<Advice>,
@ -43,6 +44,7 @@ trait StandardCS<FF: FieldExt> {
F: FnOnce() -> Result<FF, Error>;
}
#[derive(Clone)]
struct MyCircuit<F: FieldExt> {
a: Option<F>,
k: u32,
@ -278,7 +280,7 @@ fn main() {
// Create a proof
let mut transcript = DummyHashWrite::init(vec![], Fq::one());
create_proof(&params, &pk, &circuit, &[pubinputs], &mut transcript)
create_proof(&params, &pk, &[circuit], &[&[pubinputs]], &mut transcript)
.expect("proof generation should not fail");
let proof: Vec<u8> = transcript.finalize();
@ -288,7 +290,14 @@ fn main() {
let pubinput_slice = &[pubinput];
let msm = params.empty_msm();
let mut transcript = DummyHashRead::init(&proof[..], Fq::one());
let guard = verify_proof(&params, pk.get_vk(), msm, pubinput_slice, &mut transcript).unwrap();
let guard = verify_proof(
&params,
pk.get_vk(),
msm,
&[pubinput_slice],
&mut transcript,
)
.unwrap();
let msm = guard.clone().use_challenges();
assert!(msm.eval());

View File

@ -62,12 +62,14 @@ pub enum VerifyFailure {
/// };
/// const K: u32 = 5;
///
/// #[derive(Copy, Clone)]
/// struct MyConfig {
/// a: Column<Advice>,
/// b: Column<Advice>,
/// c: Column<Advice>,
/// }
///
/// #[derive(Clone)]
/// struct MyCircuit {
/// a: Option<u64>,
/// b: Option<u64>,

View File

@ -164,6 +164,7 @@ fn test_proving() {
// Initialize the polynomial commitment parameters
let params: Params<EqAffine> = Params::new(K);
#[derive(Copy, Clone)]
struct PLONKConfig {
a: Column<Advice>,
b: Column<Advice>,
@ -197,6 +198,7 @@ fn test_proving() {
fn lookup_table(&mut self, values: &[Vec<FF>]) -> Result<(), Error>;
}
#[derive(Clone)]
struct MyCircuit<F: FieldExt> {
a: Option<F>,
lookup_tables: Vec<Vec<F>>,
@ -507,18 +509,25 @@ fn test_proving() {
create_proof(
&params,
&pk,
&circuit,
&[pubinputs.clone()],
&[circuit.clone(), circuit.clone()],
&[&[pubinputs.clone()], &[pubinputs.clone()]],
&mut transcript,
)
.expect("proof generation should not fail");
let proof: Vec<u8> = transcript.finalize();
let pubinput_slice = &[pubinput];
let pubinput_slice_copy = &[pubinput];
let msm = params.empty_msm();
let mut transcript = DummyHashRead::init(&proof[..], Fq::one());
let guard =
verify_proof(&params, pk.get_vk(), msm, pubinput_slice, &mut transcript).unwrap();
let guard = verify_proof(
&params,
pk.get_vk(),
msm,
&[pubinput_slice, pubinput_slice_copy],
&mut transcript,
)
.unwrap();
{
let msm = guard.clone().use_challenges();
assert!(msm.eval());
@ -535,7 +544,14 @@ fn test_proving() {
pk.get_vk().write(&mut vk_buffer).unwrap();
let vk = VerifyingKey::<EqAffine>::read::<_, MyCircuit<Fp>>(&mut &vk_buffer[..], &params)
.unwrap();
let guard = verify_proof(&params, &vk, msm, pubinput_slice, &mut transcript).unwrap();
let guard = verify_proof(
&params,
&vk,
msm,
&[pubinput_slice, pubinput_slice_copy],
&mut transcript,
)
.unwrap();
{
let msm = guard.clone().use_challenges();
assert!(msm.eval());