Skip to content

Commit

Permalink
Merge branch 'improve-backward-compatability-without-zsa' of github.c…
Browse files Browse the repository at this point in the history
…om:QED-it/halo2 into improve-backward-compatability-without-zsa
  • Loading branch information
YaoGalteland committed Jun 4, 2024
2 parents 5800687 + 9ecbd65 commit 236dfc5
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 44 deletions.
8 changes: 4 additions & 4 deletions halo2_gadgets/src/ecc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ pub(crate) mod tests {
};
use crate::{
tests::test_utils::{test_against_stored_proof, test_against_stored_vk},
utilities::lookup_range_check::{LookupRangeCheck, PallasLookupRC10b},
utilities::lookup_range_check::{LookupRangeCheck, PallasLookupRCConfig},
};

#[derive(Debug, Eq, PartialEq, Clone)]
Expand Down Expand Up @@ -732,7 +732,7 @@ pub(crate) mod tests {

#[allow(non_snake_case)]
impl Circuit<pallas::Base> for MyCircuit {
type Config = EccConfig<TestFixedBases, PallasLookupRC10b>;
type Config = EccConfig<TestFixedBases, PallasLookupRCConfig>;
type FloorPlanner = SimpleFloorPlanner;

fn without_witnesses(&self) -> Self {
Expand Down Expand Up @@ -767,8 +767,8 @@ pub(crate) mod tests {
let constants = meta.fixed_column();
meta.enable_constant(constants);

let range_check = PallasLookupRC10b::configure(meta, advices[9], lookup_table);
EccChip::<TestFixedBases, PallasLookupRC10b>::configure(
let range_check = PallasLookupRCConfig::configure(meta, advices[9], lookup_table);
EccChip::<TestFixedBases, PallasLookupRCConfig>::configure(
meta,
advices,
lagrange_coeffs,
Expand Down
6 changes: 3 additions & 3 deletions halo2_gadgets/src/ecc/chip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use super::{BaseFitsInScalarInstructions, EccInstructions, FixedPoints};
use crate::utilities::{
lookup_range_check::{PallasLookupRC, PallasLookupRC10b},
lookup_range_check::{PallasLookupRC, PallasLookupRCConfig},
UtilitiesInstructions,
};
use arrayvec::ArrayVec;
Expand Down Expand Up @@ -139,7 +139,7 @@ impl From<NonIdentityEccPoint> for EccPoint {
#[allow(non_snake_case)]
pub struct EccConfig<
FixedPoints: super::FixedPoints<pallas::Affine>,
Lookup: PallasLookupRC = PallasLookupRC10b,
Lookup: PallasLookupRC = PallasLookupRCConfig,
> {
/// Advice columns needed by instructions in the ECC chip.
pub advices: [Column<Advice>; 10],
Expand Down Expand Up @@ -232,7 +232,7 @@ pub trait FixedPoint<C: CurveAffine>: std::fmt::Debug + Eq + Clone {
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct EccChip<
FixedPoints: super::FixedPoints<pallas::Affine>,
Lookup: PallasLookupRC = PallasLookupRC10b,
Lookup: PallasLookupRC = PallasLookupRCConfig,
> {
config: EccConfig<FixedPoints, Lookup>,
}
Expand Down
4 changes: 2 additions & 2 deletions halo2_gadgets/src/ecc/chip/mul.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{add, EccPoint, NonIdentityEccPoint, ScalarVar, T_Q};
use crate::utilities::{
lookup_range_check::{PallasLookupRC, PallasLookupRC10b},
lookup_range_check::{PallasLookupRC, PallasLookupRCConfig},
{bool_check, ternary},
};
use std::{
Expand Down Expand Up @@ -46,7 +46,7 @@ const INCOMPLETE_LO_LEN: usize = INCOMPLETE_LEN - INCOMPLETE_HI_LEN;
const COMPLETE_RANGE: Range<usize> = INCOMPLETE_LEN..(INCOMPLETE_LEN + NUM_COMPLETE_BITS);

#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub struct Config<Lookup: PallasLookupRC = PallasLookupRC10b> {
pub struct Config<Lookup: PallasLookupRC = PallasLookupRCConfig> {
// Selector used to check switching logic on LSB
q_mul_lsb: Selector,
// Configuration used in complete addition
Expand Down
4 changes: 2 additions & 2 deletions halo2_gadgets/src/ecc/chip/mul/overflow.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::{T_Q, Z};
use crate::{
sinsemilla::primitives as sinsemilla,
utilities::lookup_range_check::{PallasLookupRC, PallasLookupRC10b},
utilities::lookup_range_check::{PallasLookupRC, PallasLookupRCConfig},
};

use group::ff::PrimeField;
Expand All @@ -16,7 +16,7 @@ use pasta_curves::pallas;
use std::iter;

#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub struct Config<Lookup: PallasLookupRC = PallasLookupRC10b> {
pub struct Config<Lookup: PallasLookupRC = PallasLookupRCConfig> {
// Selector to check z_0 = alpha + t_q (mod p)
q_mul_overflow: Selector,
// 10-bit lookup table
Expand Down
5 changes: 3 additions & 2 deletions halo2_gadgets/src/ecc/chip/mul_fixed/base_field_elem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use super::H_BASE;

use crate::utilities::{
bitrange_subset, bool_check,
lookup_range_check::{PallasLookupRC, PallasLookupRC10b},
lookup_range_check::{PallasLookupRC, PallasLookupRCConfig},
range_check,
};

Expand All @@ -18,7 +18,8 @@ use pasta_curves::pallas;
use std::convert::TryInto;

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Config<Fixed: FixedPoints<pallas::Affine>, Lookup: PallasLookupRC = PallasLookupRC10b> {
pub struct Config<Fixed: FixedPoints<pallas::Affine>, Lookup: PallasLookupRC = PallasLookupRCConfig>
{
q_mul_fixed_base_field: Selector,
canon_advices: [Column<Advice>; 3],
lookup_config: Lookup,
Expand Down
8 changes: 4 additions & 4 deletions halo2_gadgets/src/ecc/chip/mul_fixed/short.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ pub mod tests {
FixedPointShort, NonIdentityPoint, Point, ScalarFixedShort,
},
utilities::{
lookup_range_check::{LookupRangeCheck, PallasLookupRC, PallasLookupRC10b},
lookup_range_check::{LookupRangeCheck, PallasLookupRC, PallasLookupRCConfig},
UtilitiesInstructions,
},
};
Expand Down Expand Up @@ -428,7 +428,7 @@ pub mod tests {
}

impl Circuit<pallas::Base> for MyCircuit {
type Config = EccConfig<TestFixedBases, PallasLookupRC10b>;
type Config = EccConfig<TestFixedBases, PallasLookupRCConfig>;
type FloorPlanner = SimpleFloorPlanner;

fn without_witnesses(&self) -> Self {
Expand Down Expand Up @@ -464,8 +464,8 @@ pub mod tests {
let constants = meta.fixed_column();
meta.enable_constant(constants);

let range_check = PallasLookupRC10b::configure(meta, advices[9], lookup_table);
EccChip::<TestFixedBases, PallasLookupRC10b>::configure(
let range_check = PallasLookupRCConfig::configure(meta, advices[9], lookup_table);
EccChip::<TestFixedBases, PallasLookupRCConfig>::configure(
meta,
advices,
lagrange_coeffs,
Expand Down
24 changes: 17 additions & 7 deletions halo2_gadgets/src/sinsemilla.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ pub(crate) mod tests {
},
sinsemilla::primitives::{self as sinsemilla, K},
tests::test_utils::{test_against_stored_proof, test_against_stored_vk},
utilities::lookup_range_check::{LookupRangeCheck, PallasLookupRC10b},
utilities::lookup_range_check::{LookupRangeCheck, PallasLookupRCConfig},
};

use group::{ff::Field, Curve};
Expand Down Expand Up @@ -519,9 +519,19 @@ pub(crate) mod tests {
impl Circuit<pallas::Base> for MyCircuit {
#[allow(clippy::type_complexity)]
type Config = (
EccConfig<TestFixedBases, PallasLookupRC10b>,
SinsemillaConfig<TestHashDomain, TestCommitDomain, TestFixedBases, PallasLookupRC10b>,
SinsemillaConfig<TestHashDomain, TestCommitDomain, TestFixedBases, PallasLookupRC10b>,
EccConfig<TestFixedBases, PallasLookupRCConfig>,
SinsemillaConfig<
TestHashDomain,
TestCommitDomain,
TestFixedBases,
PallasLookupRCConfig,
>,
SinsemillaConfig<
TestHashDomain,
TestCommitDomain,
TestFixedBases,
PallasLookupRCConfig,
>,
);
type FloorPlanner = SimpleFloorPlanner;

Expand Down Expand Up @@ -567,9 +577,9 @@ pub(crate) mod tests {
meta.lookup_table_column(),
);

let range_check = PallasLookupRC10b::configure(meta, advices[9], table_idx);
let range_check = PallasLookupRCConfig::configure(meta, advices[9], table_idx);

let ecc_config = EccChip::<TestFixedBases, PallasLookupRC10b>::configure(
let ecc_config = EccChip::<TestFixedBases, PallasLookupRCConfig>::configure(
meta,
advices,
lagrange_coeffs,
Expand Down Expand Up @@ -609,7 +619,7 @@ pub(crate) mod tests {
TestHashDomain,
TestCommitDomain,
TestFixedBases,
PallasLookupRC10b,
PallasLookupRCConfig,
>::load(config.1.clone(), &mut layouter)?;

// This MerkleCRH example is purely for illustrative purposes.
Expand Down
6 changes: 3 additions & 3 deletions halo2_gadgets/src/sinsemilla/chip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
chip::{DoubleAndAdd, NonIdentityEccPoint},
FixedPoints,
},
utilities::lookup_range_check::{PallasLookupRC, PallasLookupRC10b},
utilities::lookup_range_check::{PallasLookupRC, PallasLookupRCConfig},
};
use std::marker::PhantomData;

Expand All @@ -30,7 +30,7 @@ mod hash_to_point;

/// Configuration for the Sinsemilla hash chip
#[derive(Eq, PartialEq, Clone, Debug)]
pub struct SinsemillaConfig<Hash, Commit, F, Lookup = PallasLookupRC10b>
pub struct SinsemillaConfig<Hash, Commit, F, Lookup = PallasLookupRCConfig>
where
Hash: HashDomains<pallas::Affine>,
F: FixedPoints<pallas::Affine>,
Expand Down Expand Up @@ -98,7 +98,7 @@ where
///
/// [Chip description](https://zcash.github.io/halo2/design/gadgets/sinsemilla.html#plonk--halo-2-constraints).
#[derive(Eq, PartialEq, Clone, Debug)]
pub struct SinsemillaChip<Hash, Commit, Fixed, Lookup = PallasLookupRC10b>
pub struct SinsemillaChip<Hash, Commit, Fixed, Lookup = PallasLookupRCConfig>
where
Hash: HashDomains<pallas::Affine>,
Fixed: FixedPoints<pallas::Affine>,
Expand Down
10 changes: 5 additions & 5 deletions halo2_gadgets/src/sinsemilla/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ pub mod tests {
tests::test_utils::{test_against_stored_proof, test_against_stored_vk},
utilities::{
i2lebsp,
lookup_range_check::{LookupRangeCheck, PallasLookupRC10b},
lookup_range_check::{LookupRangeCheck, PallasLookupRCConfig},
UtilitiesInstructions,
},
};
Expand All @@ -213,8 +213,8 @@ pub mod tests {

impl Circuit<pallas::Base> for MyCircuit {
type Config = (
MerkleConfig<TestHashDomain, TestCommitDomain, TestFixedBases, PallasLookupRC10b>,
MerkleConfig<TestHashDomain, TestCommitDomain, TestFixedBases, PallasLookupRC10b>,
MerkleConfig<TestHashDomain, TestCommitDomain, TestFixedBases, PallasLookupRCConfig>,
MerkleConfig<TestHashDomain, TestCommitDomain, TestFixedBases, PallasLookupRCConfig>,
);
type FloorPlanner = SimpleFloorPlanner;

Expand Down Expand Up @@ -252,7 +252,7 @@ pub mod tests {
meta.lookup_table_column(),
);

let range_check = PallasLookupRC10b::configure(meta, advices[9], lookup.0);
let range_check = PallasLookupRCConfig::configure(meta, advices[9], lookup.0);

let sinsemilla_config_1 = SinsemillaChip::configure(
meta,
Expand Down Expand Up @@ -287,7 +287,7 @@ pub mod tests {
TestHashDomain,
TestCommitDomain,
TestFixedBases,
PallasLookupRC10b,
PallasLookupRCConfig,
>::load(config.0.sinsemilla_config.clone(), &mut layouter)?;

// Construct Merkle chips which will be placed side-by-side in the circuit.
Expand Down
6 changes: 3 additions & 3 deletions halo2_gadgets/src/sinsemilla/merkle/chip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use super::MerkleInstructions;
use crate::{
sinsemilla::{primitives as sinsemilla, MessagePiece},
utilities::{
lookup_range_check::{PallasLookupRC, PallasLookupRC10b},
lookup_range_check::{PallasLookupRC, PallasLookupRCConfig},
RangeConstrained,
},
{
Expand All @@ -31,7 +31,7 @@ use group::ff::PrimeField;

/// Configuration for the `MerkleChip` implementation.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct MerkleConfig<Hash, Commit, Fixed, Lookup = PallasLookupRC10b>
pub struct MerkleConfig<Hash, Commit, Fixed, Lookup = PallasLookupRCConfig>
where
Hash: HashDomains<pallas::Affine>,
Fixed: FixedPoints<pallas::Affine>,
Expand All @@ -55,7 +55,7 @@ where
/// This chip does **NOT** constrain `left⋆` and `right⋆` to be canonical encodings of
/// `left` and `right`.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct MerkleChip<Hash, Commit, Fixed, Lookup = PallasLookupRC10b>
pub struct MerkleChip<Hash, Commit, Fixed, Lookup = PallasLookupRCConfig>
where
Hash: HashDomains<pallas::Affine>,
Fixed: FixedPoints<pallas::Affine>,
Expand Down
11 changes: 5 additions & 6 deletions halo2_gadgets/src/tests/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ use halo2_proofs::{
const TEST_DATA_DIR: &str = "src/tests/circuit_data";
const GEN_ENV_VAR: &str = "CIRCUIT_TEST_GENERATE_NEW_DATA";

/// A proof structure
#[derive(Clone, Debug)]
pub struct Proof(Vec<u8>);

impl AsRef<[u8]> for Proof {
fn as_ref(&self) -> &[u8] {
&self.0
Expand Down Expand Up @@ -61,6 +61,7 @@ impl Proof {
let mut transcript = Blake2bRead::init(&self.0[..]);
plonk::verify_proof(params, vk, strategy, &[&[]], &mut transcript)
}

/// Constructs a new Proof value.
pub fn new(bytes: Vec<u8>) -> Self {
Proof(bytes)
Expand Down Expand Up @@ -91,8 +92,7 @@ pub(crate) fn test_against_stored_vk<C: Circuit<pallas::Base>>(circuit: &C, circ
);
}

/// If the environment variable GEN_ENV_VAR_PROOF is set,
/// write the old proof in a file
/// If the env variable GEN_ENV_VAR is set, write the `Proof` to a file
fn conditionally_save_proof_to_disk<C: Circuit<pallas::Base>>(
vk: &VerifyingKey<Affine>,
params: &Params<Affine>,
Expand Down Expand Up @@ -121,12 +121,11 @@ pub(crate) fn test_against_stored_proof<C: Circuit<pallas::Base>>(
let params: Params<Affine> = Params::new(11);
let vk = plonk::keygen_vk(&params, &circuit).unwrap();

// Conditionally save proof to disk
conditionally_save_proof_to_disk(&vk, &params, circuit, &full_file_name);

// Read proof from disk
// Read the proof from storage
let proof = Proof::new(fs::read(full_file_name).expect("Unable to read proof test file"));

// Verify the old proof with the new vk
// Verify the stored proof with the generated vk
assert!(proof.verify(&vk, &params).is_ok());
}
6 changes: 3 additions & 3 deletions halo2_gadgets/src/utilities/lookup_range_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,11 +450,11 @@ pub trait PallasLookupRC:
{
}

/// `PallasLookupRC10b` is a shorthand for `LookupRangeCheckConfig` specialized with
/// `PallasLookupRCConfig` is a shorthand for `LookupRangeCheckConfig` specialized with
/// `pallas::Base` and `sinsemilla::K` and used to improve readability```
pub type PallasLookupRC10b = LookupRangeCheckConfig<pallas::Base, { sinsemilla::K }>;
pub type PallasLookupRCConfig = LookupRangeCheckConfig<pallas::Base, { sinsemilla::K }>;

impl PallasLookupRC for PallasLookupRC10b {}
impl PallasLookupRC for PallasLookupRCConfig {}

#[cfg(test)]
mod tests {
Expand Down

0 comments on commit 236dfc5

Please sign in to comment.