Skip to content

Commit

Permalink
Working recursive test
Browse files Browse the repository at this point in the history
  • Loading branch information
iquerejeta committed Jan 15, 2025
1 parent 5c412ac commit a808223
Show file tree
Hide file tree
Showing 13 changed files with 405 additions and 123 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ backtrace = { version = "0.3", optional = true }
ff = "0.13"
group = "0.13"
halo2curves = { version = "0.7.0", default-features = false }
blstrs = { git = "https://github.com/davidnevadoc/blstrs", rev = "8ca6da7" }
blstrs = { git = "https://github.com/davidnevadoc/blstrs", rev = "3dfe5bf" }
rand_core = { version = "0.6", default-features = false }
tracing = "0.1"
blake2b_simd = "1" # MSRV 1.66.0
Expand All @@ -59,6 +59,7 @@ tabbycat = { version = "0.1", features = ["attributes"], optional = true }

# Legacy circuit compatibility
halo2_legacy_pdqsort = { version = "0.1.0", optional = true }
num-bigint = "0.4.6"

[dev-dependencies]
assert_matches = "1.5"
Expand Down
14 changes: 5 additions & 9 deletions src/plonk/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ impl Selector {
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct FixedQuery {
/// Query index
pub(crate) index: Option<usize>,
pub index: Option<usize>,
/// Column index
pub(crate) column_index: usize,
/// Rotation of this query
Expand All @@ -504,7 +504,7 @@ impl FixedQuery {
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct AdviceQuery {
/// Query index
pub(crate) index: Option<usize>,
pub index: Option<usize>,
/// Column index
pub(crate) column_index: usize,
/// Rotation of this query
Expand Down Expand Up @@ -534,7 +534,7 @@ impl AdviceQuery {
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct InstanceQuery {
/// Query index
pub(crate) index: Option<usize>,
pub index: Option<usize>,
/// Column index
pub(crate) column_index: usize,
/// Rotation of this query
Expand Down Expand Up @@ -1338,11 +1338,6 @@ impl<F: Field> Product<Self> for Expression<F> {
}
}

// /// Represents an index into a vector where each entry corresponds to a distinct
// /// point that polynomials are queried at.
// #[derive(Copy, Clone, Debug)]
// pub(crate) struct PointIndex(pub usize);

/// A "virtual cell" is a PLONK cell that has been queried at a particular relative offset
/// within a custom gate.
#[derive(Clone, Debug)]
Expand Down Expand Up @@ -2140,7 +2135,8 @@ impl<F: Field> ConstraintSystem<F> {
});
}

pub(crate) fn phases(&self) -> impl Iterator<Item = sealed::Phase> {
/// Return an iterator over the phases of the constraint system.
pub fn phases(&self) -> impl Iterator<Item = sealed::Phase> {
let max_phase = self
.advice_column_phase
.iter()
Expand Down
20 changes: 20 additions & 0 deletions src/plonk/keygen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ fn k_from_circuit<F: Ord + Field + FromUniformBytes<64>, C: Circuit<F>>(circuit:

/// Generate a `VerifyingKey` from an instance of `Circuit`.
/// By default, selector compression is turned **off**.
///
/// This function automatically generates the VK using the smallest
/// value of k required for the ConcreteCircuit.
/// To specify a particular value for k, use keygen_vk_with_k instead.
pub fn keygen_vk<F, CS, ConcreteCircuit>(
params: &CS::Parameters,
circuit: &ConcreteCircuit,
Expand All @@ -256,6 +260,22 @@ where
ConcreteCircuit: Circuit<F>,
{
let k = k_from_circuit(circuit);

keygen_vk_with_k(params, circuit, k)
}

/// Generate a `VerifyingKey` from an instance of `Circuit`.
/// By default, selector compression is turned **off**.
pub fn keygen_vk_with_k<F, CS, ConcreteCircuit>(
params: &CS::Parameters,
circuit: &ConcreteCircuit,
k: u32,
) -> Result<VerifyingKey<F, CS>, Error>
where
F: WithSmallOrderMulGroup<3> + FromUniformBytes<64> + Ord,
CS: PolynomialCommitmentScheme<F>,
ConcreteCircuit: Circuit<F>,
{
if params.max_k() < k {
return Err(Error::NotEnoughRowsAvailable {
current_k: params.max_k(),
Expand Down
4 changes: 2 additions & 2 deletions src/plonk/permutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use std::io;
#[derive(Debug, Clone)]
pub struct Argument {
/// A sequence of columns involved in the argument.
pub(super) columns: Vec<Column<Any>>,
pub columns: Vec<Column<Any>>,
}

impl Argument {
Expand Down Expand Up @@ -88,7 +88,7 @@ pub struct VerifyingKey<F: PrimeField, CS: PolynomialCommitmentScheme<F>> {
}

impl<F: PrimeField, CS: PolynomialCommitmentScheme<F>> VerifyingKey<F, CS> {
/// Returns commitments of sigma polynomials
/// Returns the commitments of the verifying key.
pub fn commitments(&self) -> &Vec<CS::Commitment> {
&self.commitments
}
Expand Down
5 changes: 3 additions & 2 deletions src/plonk/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ where
+ Hashable<T::Hash>
+ Sampleable<T::Hash>
+ SerdeObject
+ FromUniformBytes<64>,
+ FromUniformBytes<64>
+ Ord,
CS::Commitment: Hashable<T::Hash> + SerdeObject,
{
// Check that instances matches the expected number of instance columns
Expand Down Expand Up @@ -119,6 +120,7 @@ where
// Sample x challenge, which is used to ensure the circuit is
// satisfied with high probability.
let x: F = transcript.squeeze_challenge();

let instance_evals = {
let xn = x.pow([vk.n()]);
let (min_rotation, max_rotation) =
Expand Down Expand Up @@ -165,7 +167,6 @@ where
.collect::<Result<Vec<_>, _>>()?;

let fixed_evals = read_n(transcript, vk.cs.fixed_queries.len())?;

let vanishing = vanishing.evaluate_after_x(vk, transcript)?;

let permutations_common = vk.permutation.evaluate(transcript)?;
Expand Down
4 changes: 2 additions & 2 deletions src/poly/commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub trait PolynomialCommitmentScheme<F: PrimeField>: Clone + Debug {
) -> Result<(), Error>
where
I: IntoIterator<Item = ProverQuery<'com, F>> + Clone,
F: Sampleable<T::Hash>,
F: Sampleable<T::Hash> + Ord + Hashable<<T as Transcript>::Hash>,
Self::Commitment: Hashable<T::Hash>;

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

Expand Down
Loading

0 comments on commit a808223

Please sign in to comment.