Skip to content

Commit

Permalink
Add default generic arguments for PallasLookup to improve backward co…
Browse files Browse the repository at this point in the history
…mpatibility

This change adds default generic arguments for types implementing the PallasLookup trait,
assigning them to PallasLookupConfig by default. This adjustment allows existing code to
function without requiring users to explicitly specify PallasLookupConfig, thus minimizing
breaking changes. Users will still need to bring the PallasLookup trait into scope using
'use ... PallasLookup'.
dmidem committed May 17, 2024
1 parent f75b054 commit 5414d95
Showing 6 changed files with 32 additions and 15 deletions.
15 changes: 12 additions & 3 deletions halo2_gadgets/src/ecc/chip.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
//! Chip implementations for the ECC gadgets.
use super::{BaseFitsInScalarInstructions, EccInstructions, FixedPoints};
use crate::utilities::{lookup_range_check::PallasLookup, UtilitiesInstructions};
use crate::utilities::{
lookup_range_check::{PallasLookup, PallasLookupConfig},
UtilitiesInstructions,
};
use arrayvec::ArrayVec;

use ff::PrimeField;
@@ -134,7 +137,10 @@ impl From<NonIdentityEccPoint> for EccPoint {
/// Configuration for [`EccChip`].
#[derive(Clone, Debug, Eq, PartialEq)]
#[allow(non_snake_case)]
pub struct EccConfig<FixedPoints: super::FixedPoints<pallas::Affine>, Lookup: PallasLookup> {
pub struct EccConfig<
FixedPoints: super::FixedPoints<pallas::Affine>,
Lookup: PallasLookup = PallasLookupConfig,
> {
/// Advice columns needed by instructions in the ECC chip.
pub advices: [Column<Advice>; 10],

@@ -224,7 +230,10 @@ pub trait FixedPoint<C: CurveAffine>: std::fmt::Debug + Eq + Clone {

/// An [`EccInstructions`] chip that uses 10 advice columns.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct EccChip<FixedPoints: super::FixedPoints<pallas::Affine>, Lookup: PallasLookup> {
pub struct EccChip<
FixedPoints: super::FixedPoints<pallas::Affine>,
Lookup: PallasLookup = PallasLookupConfig,
> {
config: EccConfig<FixedPoints, Lookup>,
}

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::PallasLookup,
lookup_range_check::{PallasLookup, PallasLookupConfig},
{bool_check, ternary},
};
use std::{
@@ -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: PallasLookup> {
pub struct Config<Lookup: PallasLookup = PallasLookupConfig> {
// Selector used to check switching logic on LSB
q_mul_lsb: Selector,
// Configuration used in complete addition
7 changes: 5 additions & 2 deletions halo2_gadgets/src/ecc/chip/mul/overflow.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use super::{T_Q, Z};
use crate::{sinsemilla::primitives as sinsemilla, utilities::lookup_range_check::PallasLookup};
use crate::{
sinsemilla::primitives as sinsemilla,
utilities::lookup_range_check::{PallasLookup, PallasLookupConfig},
};

use group::ff::PrimeField;
use halo2_proofs::circuit::AssignedCell;
@@ -13,7 +16,7 @@ use pasta_curves::pallas;
use std::iter;

#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub struct Config<Lookup: PallasLookup> {
pub struct Config<Lookup: PallasLookup = PallasLookupConfig> {
// Selector to check z_0 = alpha + t_q (mod p)
q_mul_overflow: Selector,
// 10-bit lookup table
6 changes: 4 additions & 2 deletions halo2_gadgets/src/ecc/chip/mul_fixed/base_field_elem.rs
Original file line number Diff line number Diff line change
@@ -2,7 +2,9 @@ use super::super::{EccBaseFieldElemFixed, EccPoint, FixedPoints, NUM_WINDOWS, T_
use super::H_BASE;

use crate::utilities::{
bitrange_subset, bool_check, lookup_range_check::PallasLookup, range_check,
bitrange_subset, bool_check,
lookup_range_check::{PallasLookup, PallasLookupConfig},
range_check,
};

use group::ff::PrimeField;
@@ -16,7 +18,7 @@ use pasta_curves::pallas;
use std::convert::TryInto;

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Config<Fixed: FixedPoints<pallas::Affine>, Lookup: PallasLookup> {
pub struct Config<Fixed: FixedPoints<pallas::Affine>, Lookup: PallasLookup = PallasLookupConfig> {
q_mul_fixed_base_field: Selector,
canon_advices: [Column<Advice>; 3],
lookup_config: Lookup,
6 changes: 3 additions & 3 deletions halo2_gadgets/src/sinsemilla/chip.rs
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ use crate::{
chip::{DoubleAndAdd, NonIdentityEccPoint},
FixedPoints,
},
utilities::lookup_range_check::PallasLookup,
utilities::lookup_range_check::{PallasLookup, PallasLookupConfig},
};
use std::marker::PhantomData;

@@ -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>
pub struct SinsemillaConfig<Hash, Commit, F, Lookup = PallasLookupConfig>
where
Hash: HashDomains<pallas::Affine>,
F: FixedPoints<pallas::Affine>,
@@ -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>
pub struct SinsemillaChip<Hash, Commit, Fixed, Lookup = PallasLookupConfig>
where
Hash: HashDomains<pallas::Affine>,
Fixed: FixedPoints<pallas::Affine>,
9 changes: 6 additions & 3 deletions halo2_gadgets/src/sinsemilla/merkle/chip.rs
Original file line number Diff line number Diff line change
@@ -11,7 +11,10 @@ use super::MerkleInstructions;

use crate::{
sinsemilla::{primitives as sinsemilla, MessagePiece},
utilities::{lookup_range_check::PallasLookup, RangeConstrained},
utilities::{
lookup_range_check::{PallasLookup, PallasLookupConfig},
RangeConstrained,
},
{
ecc::FixedPoints,
sinsemilla::{
@@ -28,7 +31,7 @@ use group::ff::PrimeField;

/// Configuration for the `MerkleChip` implementation.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct MerkleConfig<Hash, Commit, Fixed, Lookup>
pub struct MerkleConfig<Hash, Commit, Fixed, Lookup = PallasLookupConfig>
where
Hash: HashDomains<pallas::Affine>,
Fixed: FixedPoints<pallas::Affine>,
@@ -52,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>
pub struct MerkleChip<Hash, Commit, Fixed, Lookup = PallasLookupConfig>
where
Hash: HashDomains<pallas::Affine>,
Fixed: FixedPoints<pallas::Affine>,

0 comments on commit 5414d95

Please sign in to comment.