Skip to content

Commit 04bb044

Browse files
committed
Working recursive test
1 parent 5c412ac commit 04bb044

File tree

14 files changed

+434
-140
lines changed

14 files changed

+434
-140
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ backtrace = { version = "0.3", optional = true }
4343
ff = "0.13"
4444
group = "0.13"
4545
halo2curves = { version = "0.7.0", default-features = false }
46-
blstrs = { git = "https://github.com/davidnevadoc/blstrs", rev = "8ca6da7" }
46+
blstrs = { git = "https://github.com/davidnevadoc/blstrs", rev = "3dfe5bf" }
4747
rand_core = { version = "0.6", default-features = false }
4848
tracing = "0.1"
4949
blake2b_simd = "1" # MSRV 1.66.0
@@ -59,6 +59,7 @@ tabbycat = { version = "0.1", features = ["attributes"], optional = true }
5959

6060
# Legacy circuit compatibility
6161
halo2_legacy_pdqsort = { version = "0.1.0", optional = true }
62+
num-bigint = "0.4.6"
6263

6364
[dev-dependencies]
6465
assert_matches = "1.5"

src/plonk/circuit.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ impl Selector {
481481
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
482482
pub struct FixedQuery {
483483
/// Query index
484-
pub(crate) index: Option<usize>,
484+
pub index: Option<usize>,
485485
/// Column index
486486
pub(crate) column_index: usize,
487487
/// Rotation of this query
@@ -504,7 +504,7 @@ impl FixedQuery {
504504
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
505505
pub struct AdviceQuery {
506506
/// Query index
507-
pub(crate) index: Option<usize>,
507+
pub index: Option<usize>,
508508
/// Column index
509509
pub(crate) column_index: usize,
510510
/// Rotation of this query
@@ -534,7 +534,7 @@ impl AdviceQuery {
534534
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
535535
pub struct InstanceQuery {
536536
/// Query index
537-
pub(crate) index: Option<usize>,
537+
pub index: Option<usize>,
538538
/// Column index
539539
pub(crate) column_index: usize,
540540
/// Rotation of this query
@@ -1338,11 +1338,6 @@ impl<F: Field> Product<Self> for Expression<F> {
13381338
}
13391339
}
13401340

1341-
// /// Represents an index into a vector where each entry corresponds to a distinct
1342-
// /// point that polynomials are queried at.
1343-
// #[derive(Copy, Clone, Debug)]
1344-
// pub(crate) struct PointIndex(pub usize);
1345-
13461341
/// A "virtual cell" is a PLONK cell that has been queried at a particular relative offset
13471342
/// within a custom gate.
13481343
#[derive(Clone, Debug)]
@@ -2140,7 +2135,8 @@ impl<F: Field> ConstraintSystem<F> {
21402135
});
21412136
}
21422137

2143-
pub(crate) fn phases(&self) -> impl Iterator<Item = sealed::Phase> {
2138+
/// Return an iterator over the phases of the constraint system.
2139+
pub fn phases(&self) -> impl Iterator<Item = sealed::Phase> {
21442140
let max_phase = self
21452141
.advice_column_phase
21462142
.iter()

src/plonk/keygen.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,10 @@ fn k_from_circuit<F: Ord + Field + FromUniformBytes<64>, C: Circuit<F>>(circuit:
246246

247247
/// Generate a `VerifyingKey` from an instance of `Circuit`.
248248
/// By default, selector compression is turned **off**.
249+
///
250+
/// This function automatically generates the VK using the smallest
251+
/// value of k required for the ConcreteCircuit.
252+
/// To specify a particular value for k, use keygen_vk_with_k instead.
249253
pub fn keygen_vk<F, CS, ConcreteCircuit>(
250254
params: &CS::Parameters,
251255
circuit: &ConcreteCircuit,
@@ -256,6 +260,22 @@ where
256260
ConcreteCircuit: Circuit<F>,
257261
{
258262
let k = k_from_circuit(circuit);
263+
264+
keygen_vk_with_k(params, circuit, k)
265+
}
266+
267+
/// Generate a `VerifyingKey` from an instance of `Circuit`.
268+
/// By default, selector compression is turned **off**.
269+
pub fn keygen_vk_with_k<F, CS, ConcreteCircuit>(
270+
params: &CS::Parameters,
271+
circuit: &ConcreteCircuit,
272+
k: u32,
273+
) -> Result<VerifyingKey<F, CS>, Error>
274+
where
275+
F: WithSmallOrderMulGroup<3> + FromUniformBytes<64> + Ord,
276+
CS: PolynomialCommitmentScheme<F>,
277+
ConcreteCircuit: Circuit<F>,
278+
{
259279
if params.max_k() < k {
260280
return Err(Error::NotEnoughRowsAvailable {
261281
current_k: params.max_k(),

src/plonk/permutation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use std::io;
2323
#[derive(Debug, Clone)]
2424
pub struct Argument {
2525
/// A sequence of columns involved in the argument.
26-
pub(super) columns: Vec<Column<Any>>,
26+
pub columns: Vec<Column<Any>>,
2727
}
2828

2929
impl Argument {
@@ -88,7 +88,7 @@ pub struct VerifyingKey<F: PrimeField, CS: PolynomialCommitmentScheme<F>> {
8888
}
8989

9090
impl<F: PrimeField, CS: PolynomialCommitmentScheme<F>> VerifyingKey<F, CS> {
91-
/// Returns commitments of sigma polynomials
91+
/// Returns the commitments of the verifying key.
9292
pub fn commitments(&self) -> &Vec<CS::Commitment> {
9393
&self.commitments
9494
}

src/plonk/verifier.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ where
1919
+ Hashable<T::Hash>
2020
+ Sampleable<T::Hash>
2121
+ SerdeObject
22-
+ FromUniformBytes<64>,
22+
+ FromUniformBytes<64>
23+
+ Ord,
2324
CS::Commitment: Hashable<T::Hash> + SerdeObject,
2425
{
2526
// Check that instances matches the expected number of instance columns
@@ -119,6 +120,7 @@ where
119120
// Sample x challenge, which is used to ensure the circuit is
120121
// satisfied with high probability.
121122
let x: F = transcript.squeeze_challenge();
123+
122124
let instance_evals = {
123125
let xn = x.pow([vk.n()]);
124126
let (min_rotation, max_rotation) =
@@ -165,7 +167,6 @@ where
165167
.collect::<Result<Vec<_>, _>>()?;
166168

167169
let fixed_evals = read_n(transcript, vk.cs.fixed_queries.len())?;
168-
169170
let vanishing = vanishing.evaluate_after_x(vk, transcript)?;
170171

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

src/poly/commitment.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub trait PolynomialCommitmentScheme<F: PrimeField>: Clone + Debug {
4343
) -> Result<(), Error>
4444
where
4545
I: IntoIterator<Item = ProverQuery<'com, F>> + Clone,
46-
F: Sampleable<T::Hash>,
46+
F: Sampleable<T::Hash> + Ord + Hashable<<T as Transcript>::Hash>,
4747
Self::Commitment: Hashable<T::Hash>;
4848

4949
/// Verify an opening proof at a given query
@@ -53,7 +53,7 @@ pub trait PolynomialCommitmentScheme<F: PrimeField>: Clone + Debug {
5353
) -> Result<Self::VerificationGuard, Error>
5454
where
5555
I: IntoIterator<Item = VerifierQuery<F, Self>> + Clone,
56-
F: Sampleable<T::Hash>,
56+
F: Sampleable<T::Hash> + Ord + Hashable<T::Hash>,
5757
Self::Commitment: Hashable<T::Hash>;
5858
}
5959

0 commit comments

Comments
 (0)