Skip to content

Commit 62e4047

Browse files
dkaidalovadamsmo
authored andcommitted
Add multiopen KZG from GWC19 paper
1 parent 92d9356 commit 62e4047

File tree

12 files changed

+483
-16
lines changed

12 files changed

+483
-16
lines changed

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ tabbycat = { version = "0.1", features = ["attributes"], optional = true }
6161
halo2_legacy_pdqsort = { version = "0.1.0", optional = true }
6262
num-bigint = "0.4.6"
6363

64+
log = {version = "0.4.27", optional = true}
65+
6466
[dev-dependencies]
6567
assert_matches = "1.5"
6668
criterion = "0.3"
@@ -100,6 +102,10 @@ truncated-challenges = []
100102
# This feature is very powerful for proving statements on committed data.
101103
committed-instances = []
102104

105+
# this is used to add code that displays debug information in format
106+
#that is easy to compar with plutus
107+
plutus_debug = ["dep:log"]
108+
103109
[lib]
104110
bench = false
105111

rust-toolchain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.82.0
1+
1.88.0

src/plonk/lookup/verifier.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,19 @@ use crate::{
1010
};
1111
use ff::{PrimeField, WithSmallOrderMulGroup};
1212

13+
#[cfg_attr(feature = "plutus_debug", derive(Debug))]
1314
pub struct PermutationCommitments<F: PrimeField, CS: PolynomialCommitmentScheme<F>> {
1415
permuted_input_commitment: CS::Commitment,
1516
permuted_table_commitment: CS::Commitment,
1617
}
1718

19+
#[cfg_attr(feature = "plutus_debug", derive(Debug))]
1820
pub struct Committed<F: PrimeField, CS: PolynomialCommitmentScheme<F>> {
1921
permuted: PermutationCommitments<F, CS>,
2022
product_commitment: CS::Commitment,
2123
}
2224

25+
#[cfg_attr(feature = "plutus_debug", derive(Debug))]
2326
pub struct Evaluated<F: PrimeField, CS: PolynomialCommitmentScheme<F>> {
2427
committed: Committed<F, CS>,
2528
product_eval: F,

src/plonk/permutation/verifier.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,20 @@ pub struct Committed<F: PrimeField, CS: PolynomialCommitmentScheme<F>> {
1414
permutation_product_commitments: Vec<CS::Commitment>,
1515
}
1616

17+
#[cfg_attr(feature = "plutus_debug", derive(Debug))]
1718
pub struct EvaluatedSet<F: PrimeField, CS: PolynomialCommitmentScheme<F>> {
1819
permutation_product_commitment: CS::Commitment,
1920
permutation_product_eval: F,
2021
permutation_product_next_eval: F,
2122
permutation_product_last_eval: Option<F>,
2223
}
2324

25+
#[cfg_attr(feature = "plutus_debug", derive(Debug))]
2426
pub struct CommonEvaluated<F: PrimeField> {
2527
permutation_evals: Vec<F>,
2628
}
2729

30+
#[cfg_attr(feature = "plutus_debug", derive(Debug))]
2831
pub struct Evaluated<F: PrimeField, CS: PolynomialCommitmentScheme<F>> {
2932
sets: Vec<EvaluatedSet<F, CS>>,
3033
}

src/plonk/vanishing/verifier.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use std::iter;
22

33
use ff::{PrimeField, WithSmallOrderMulGroup};
4-
4+
#[cfg(feature = "plutus_debug")]
5+
use log::info;
56
use crate::poly::commitment::PolynomialCommitmentScheme;
67
use crate::transcript::{read_n, Hashable, Transcript};
78
use crate::{
@@ -26,6 +27,7 @@ pub struct PartiallyEvaluated<F: PrimeField, CS: PolynomialCommitmentScheme<F>>
2627
random_eval: F,
2728
}
2829

30+
#[cfg_attr(feature = "plutus_debug", derive(Debug))]
2931
pub struct Evaluated<F: PrimeField, CS: PolynomialCommitmentScheme<F>> {
3032
h_commitment: CS::Commitment,
3133
random_poly_commitment: CS::Commitment,
@@ -95,13 +97,19 @@ impl<F: PrimeField, CS: PolynomialCommitmentScheme<F>> PartiallyEvaluated<F, CS>
9597
let expected_h_eval = expressions.fold(F::ZERO, |h_eval, v| h_eval * &y + &v);
9698
let expected_h_eval = expected_h_eval * ((xn - F::ONE).invert().unwrap());
9799

98-
let h_commitment = self
100+
#[cfg(feature = "plutus_debug")]
101+
info!("vanishing_s = {expected_h_eval:?}");
102+
103+
let h_commitment: <CS as PolynomialCommitmentScheme<F>>::Commitment = self
99104
.h_commitments
100105
.into_iter()
101106
.rev()
102107
.reduce(|acc, commitment| commitment + (acc * xn))
103108
.expect("H commitments should not be empty");
104109

110+
#[cfg(feature = "plutus_debug")]
111+
info!("vanishing_g = {h_commitment:?}");
112+
105113
Evaluated {
106114
h_commitment,
107115
random_poly_commitment: self.random_poly_commitment,

src/plonk/verifier.rs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
use ff::{FromUniformBytes, WithSmallOrderMulGroup};
2-
use std::iter;
3-
41
use super::{vanishing, Error, VerifyingKey};
52
use crate::poly::commitment::PolynomialCommitmentScheme;
63
use crate::poly::VerifierQuery;
74
use crate::transcript::{read_n, Hashable, Sampleable, Transcript};
85
use crate::utils::arithmetic::compute_inner_product;
6+
use ff::{FromUniformBytes, WithSmallOrderMulGroup};
7+
#[cfg(feature = "plutus_debug")]
8+
use log::info;
9+
use std::iter;
910

1011
/// Prepares a plonk proof into a PCS instance that can be finalized or batched. It is
1112
/// responsibility of the verifier to check the validity of the instance columns.
@@ -192,21 +193,36 @@ where
192193
})
193194
.collect::<Result<Vec<_>, _>>()?
194195
};
196+
#[cfg(feature = "plutus_debug")]
197+
info!("instance evals {instance_evals:?}");
195198

196199
let advice_evals = (0..num_proofs)
197200
.map(|_| -> Result<Vec<_>, _> { read_n(transcript, vk.cs.advice_queries.len()) })
198201
.collect::<Result<Vec<_>, _>>()?;
199202

203+
#[cfg(feature = "plutus_debug")]
204+
info!("advice evals {advice_evals:?}");
205+
200206
let fixed_evals = read_n(transcript, vk.cs.fixed_queries.len())?;
207+
208+
#[cfg(feature = "plutus_debug")]
209+
info!("fixed evals {fixed_evals:?}");
210+
201211
let vanishing = vanishing.evaluate_after_x(transcript)?;
202212

203213
let permutations_common = vk.permutation.evaluate(transcript)?;
204214

215+
#[cfg(feature = "plutus_debug")]
216+
info!("permutations common {permutations_common:?}");
217+
205218
let permutations_evaluated = permutations_committed
206219
.into_iter()
207220
.map(|permutation| permutation.evaluate(transcript))
208221
.collect::<Result<Vec<_>, _>>()?;
209222

223+
#[cfg(feature = "plutus_debug")]
224+
info!("permutations evaluated {permutations_evaluated:?}");
225+
210226
let lookups_evaluated = lookups_committed
211227
.into_iter()
212228
.map(|lookups| -> Result<Vec<_>, _> {
@@ -217,6 +233,9 @@ where
217233
})
218234
.collect::<Result<Vec<_>, _>>()?;
219235

236+
#[cfg(feature = "plutus_debug")]
237+
info!("lookups evaluated {lookups_evaluated:?}");
238+
220239
// This check ensures the circuit is satisfied so long as the polynomial
221240
// commitments open to the correct values.
222241
let vanishing = {
@@ -355,6 +374,16 @@ where
355374
.chain(permutations_common.queries(&vk.permutation, x))
356375
.chain(vanishing.queries(x));
357376

377+
#[cfg(feature = "plutus_debug")]
378+
{
379+
queries.clone().for_each(|query| {
380+
info!("------query----");
381+
info!("( commitment: ( {:?} ), point: {:?}, evaluation: {:?} )",
382+
CS::display(&query.commitment), query.point, query.eval);
383+
info!("---------------");
384+
});
385+
}
386+
358387
// We are now convinced the circuit is satisfied so long as the
359388
// polynomial commitments open to the correct values.
360389
CS::multi_prepare(queries, transcript).map_err(|_| Error::Opening)

src/poly/commitment.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ pub trait PolynomialCommitmentScheme<F: PrimeField>: Clone + Debug {
3030
/// Verification guard. Allows for batch verification
3131
type VerificationGuard: Guard<F, Self>;
3232

33+
/// this is used only for debug purpose
34+
#[cfg(feature = "plutus_debug")]
35+
fn display(c: &Self::Commitment) -> String;
36+
3337
/// Generates the parameters of the polynomial commitment scheme
3438
fn gen_params(k: u32) -> Self::Parameters;
3539

0 commit comments

Comments
 (0)