Skip to content

Commit

Permalink
Merge branch 'main' of github.com:privacy-scaling-explorations/halo2 …
Browse files Browse the repository at this point in the history
…into feat/deterministic1
  • Loading branch information
adria0 committed Jun 11, 2024
2 parents b245fba + 32599e8 commit f81fa63
Show file tree
Hide file tree
Showing 21 changed files with 564 additions and 134 deletions.
41 changes: 10 additions & 31 deletions halo2_backend/src/plonk/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ pub enum VarBack {
Challenge(ChallengeMid),
}

impl std::fmt::Display for VarBack {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self)
}
}

impl Variable for VarBack {
fn degree(&self) -> usize {
match self {
Expand All @@ -40,8 +46,8 @@ impl Variable for VarBack {
}
}

fn write_identifier<W: std::io::Write>(&self, _writer: &mut W) -> std::io::Result<()> {
unimplemented!("unused method")
fn write_identifier<W: std::io::Write>(&self, writer: &mut W) -> std::io::Result<()> {
write!(writer, "{}", self)
}
}

Expand Down Expand Up @@ -238,6 +244,8 @@ impl<'a, F: Field> std::fmt::Debug for PinnedGates<'a, F> {
}

/// Represents the minimal parameters that determine a `ConstraintSystem`.
#[allow(dead_code)]
#[derive(Debug)]
pub(crate) struct PinnedConstraintSystem<'a, F: Field> {
num_fixed_columns: &'a usize,
num_advice_columns: &'a usize,
Expand All @@ -255,35 +263,6 @@ pub(crate) struct PinnedConstraintSystem<'a, F: Field> {
minimum_degree: &'a Option<usize>,
}

impl<'a, F: Field> std::fmt::Debug for PinnedConstraintSystem<'a, F> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut debug_struct = f.debug_struct("PinnedConstraintSystem");
debug_struct
.field("num_fixed_columns", self.num_fixed_columns)
.field("num_advice_columns", self.num_advice_columns)
.field("num_instance_columns", self.num_instance_columns);
// Only show multi-phase related fields if it's used.
if *self.num_challenges > 0 {
debug_struct
.field("num_challenges", self.num_challenges)
.field("advice_column_phase", self.advice_column_phase)
.field("challenge_phase", self.challenge_phase);
}
debug_struct
.field("gates", &self.gates)
.field("advice_queries", self.advice_queries)
.field("instance_queries", self.instance_queries)
.field("fixed_queries", self.fixed_queries)
.field("permutation", self.permutation)
.field("lookups", self.lookups);
if !self.shuffles.is_empty() {
debug_struct.field("shuffles", self.shuffles);
}
debug_struct.field("minimum_degree", self.minimum_degree);
debug_struct.finish()
}
}

// Cost functions: arguments required degree

/// Returns the minimum circuit degree required by the permutation argument.
Expand Down
18 changes: 5 additions & 13 deletions halo2_backend/src/plonk/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ impl<
engine: PlonkEngine<Scheme::Curve, M>,
params: &'params Scheme::ParamsProver,
pk: &'a ProvingKey<Scheme::Curve>,
// TODO: If this was a vector the usage would be simpler
// https://github.com/privacy-scaling-explorations/halo2/issues/265
instance: &[&[Scheme::Scalar]],
instance: Vec<Vec<Scheme::Scalar>>,
rng: R,
transcript: &'a mut T,
) -> Result<Self, Error>
Expand All @@ -90,9 +88,7 @@ impl<
pub fn new(
params: &'params Scheme::ParamsProver,
pk: &'a ProvingKey<Scheme::Curve>,
// TODO: If this was a vector the usage would be simpler
// https://github.com/privacy-scaling-explorations/halo2/issues/265
instance: &[&[Scheme::Scalar]],
instance: Vec<Vec<Scheme::Scalar>>,
rng: R,
transcript: &'a mut T,
) -> Result<ProverSingle<'a, 'params, Scheme, P, E, R, T, H2cEngine>, Error>
Expand Down Expand Up @@ -175,9 +171,7 @@ impl<
engine: PlonkEngine<Scheme::Curve, M>,
params: &'params Scheme::ParamsProver,
pk: &'a ProvingKey<Scheme::Curve>,
// TODO: If this was a vector the usage would be simpler.
// https://github.com/privacy-scaling-explorations/halo2/issues/265
circuits_instances: &[&[&[Scheme::Scalar]]],
circuits_instances: &[Vec<Vec<Scheme::Scalar>>],
rng: R,
transcript: &'a mut T,
) -> Result<Self, Error>
Expand All @@ -201,7 +195,7 @@ impl<
// commit_instance_fn is a helper function to return the polynomials (and its commitments) of
// instance columns while updating the transcript.
let mut commit_instance_fn =
|instance: &[&[Scheme::Scalar]]| -> Result<InstanceSingle<Scheme::Curve>, Error> {
|instance: &[Vec<Scheme::Scalar>]| -> Result<InstanceSingle<Scheme::Curve>, Error> {
// Create a lagrange polynomial for each instance column

let instance_values = instance
Expand Down Expand Up @@ -905,9 +899,7 @@ impl<
pub fn new(
params: &'params Scheme::ParamsProver,
pk: &'a ProvingKey<Scheme::Curve>,
// TODO: If this was a vector the usage would be simpler.
// https://github.com/privacy-scaling-explorations/halo2/issues/265
circuits_instances: &[&[&[Scheme::Scalar]]],
circuits_instances: &[Vec<Vec<Scheme::Scalar>>],
rng: R,
transcript: &'a mut T,
) -> Result<Prover<'a, 'params, Scheme, P, E, R, T, H2cEngine>, Error>
Expand Down
11 changes: 7 additions & 4 deletions halo2_backend/src/plonk/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub fn verify_proof_single<'params, Scheme, V, E, T, Strategy>(
params: &'params Scheme::ParamsVerifier,
vk: &VerifyingKey<Scheme::Curve>,
strategy: Strategy,
instance: &[&[Scheme::Scalar]],
instance: Vec<Vec<Scheme::Scalar>>,
transcript: &mut T,
) -> Result<Strategy::Output, Error>
where
Expand All @@ -60,7 +60,7 @@ pub fn verify_proof<
params: &'params Scheme::ParamsVerifier,
vk: &VerifyingKey<Scheme::Curve>,
strategy: Strategy,
instances: &[&[&[Scheme::Scalar]]],
instances: &[Vec<Vec<Scheme::Scalar>>],
transcript: &mut T,
) -> Result<Strategy::Output, Error>
where
Expand Down Expand Up @@ -301,9 +301,12 @@ where
.instance_queries
.iter()
.map(|(column, rotation)| {
let instances = instances[column.index];
let instances = &instances[column.index];
let offset = (max_rotation - rotation.0) as usize;
compute_inner_product(instances, &l_i_s[offset..offset + instances.len()])
compute_inner_product(
instances.as_slice(),
&l_i_s[offset..offset + instances.len()],
)
})
.collect::<Vec<_>>()
})
Expand Down
10 changes: 1 addition & 9 deletions halo2_backend/src/plonk/verifier/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ where
// `is_zero() == false` then this argument won't be able to interfere with it
// to make it true, with high probability.
acc.scale(C::Scalar::random(OsRng));

acc.add_msm(&msm);
acc
}
Expand All @@ -109,16 +108,9 @@ where
.into_par_iter()
.enumerate()
.map(|(i, item)| {
let instances: Vec<Vec<_>> = item
.instances
.iter()
.map(|i| i.iter().map(|c| &c[..]).collect())
.collect();
let instances: Vec<_> = instances.iter().map(|i| &i[..]).collect();

let strategy = BatchStrategy::new(params);
let mut transcript = Blake2bRead::init(&item.proof[..]);
verify_proof(params, vk, strategy, &instances, &mut transcript).map_err(|e| {
verify_proof(params, vk, strategy, &item.instances, &mut transcript).map_err(|e| {
tracing::debug!("Batch item {} failed verification: {}", i, e);
e
})
Expand Down
4 changes: 4 additions & 0 deletions halo2_debug/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ all-features = true
rustdoc-args = ["--cfg", "docsrs", "--html-in-header", "katex-header.html"]

[dependencies]
ff = "0.13"
halo2curves = { version = "0.6.1", default-features = false }
num-bigint = "0.4.5"
halo2_middleware = { path = "../halo2_middleware" }
tiny-keccak = { version = "2.0.2", features=["keccak"] }
hex = "0.4.3"
rand_core = "0.6.4"
Loading

0 comments on commit f81fa63

Please sign in to comment.