Skip to content

Commit

Permalink
Take into account Pablo's review
Browse files Browse the repository at this point in the history
  • Loading branch information
ConstanceBeguier committed Aug 2, 2024
1 parent 8a2cbee commit 03dbe70
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 25 deletions.
1 change: 0 additions & 1 deletion halo2_gadgets/src/ecc/chip/mul_fixed/short.rs
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,6 @@ pub mod tests {

let column = config.advices[0];

//let short_config = config.mul_fixed_short.clone();
let base = Point::new(chip, layouter.namespace(|| "load base"), self.base)?;

let sign = self.load_private(layouter.namespace(|| "load sign"), column, self.sign)?;
Expand Down
2 changes: 0 additions & 2 deletions halo2_gadgets/src/sinsemilla.rs
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,6 @@ pub(crate) mod tests {
}

impl<Lookup: PallasLookupRangeCheck> Circuit<pallas::Base> for MyCircuit<Lookup> {
#[allow(clippy::type_complexity)]
type Config = MyConfig<Lookup>;
type FloorPlanner = SimpleFloorPlanner;

Expand Down Expand Up @@ -875,7 +874,6 @@ pub(crate) mod tests {
impl<Lookup: PallasLookupRangeCheck> Circuit<pallas::Base>
for MyCircuitWithHashFromPrivatePoint<Lookup>
{
#[allow(clippy::type_complexity)]
type Config = MyConfig<Lookup>;
type FloorPlanner = SimpleFloorPlanner;

Expand Down
22 changes: 17 additions & 5 deletions halo2_gadgets/src/sinsemilla/chip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ use generator_table::GeneratorTableConfig;
mod hash_to_point;

/// Configuration for the Sinsemilla hash chip
///
/// If `init_from_private_point` is true, the chip can compute a hash from a private point.
/// However, compared to when `init_from_private_point` is set to false,
/// computing the hash from a public point will take one additional row.
#[derive(Eq, PartialEq, Clone, Debug)]
pub struct SinsemillaConfig<Hash, Commit, F, Lookup = PallasLookupRangeCheckConfig>
where
Expand Down Expand Up @@ -61,7 +65,9 @@ where
/// An advice column configured to perform lookup range checks.
lookup_config: Lookup,

enable_hash_from_private_point: bool,
/// If true, it is possible to compute a hash from a private point.
init_from_private_point: bool,

_marker: PhantomData<(Hash, Commit, F)>,
}

Expand Down Expand Up @@ -152,6 +158,12 @@ where
.load(config.lookup_config.table_range_check_tag(), layouter)
}

/// Creates the Sinsemilla chip
///
/// If `init_from_private_point` is true, the chip can compute a hash from a private point.
/// However, compared to when `init_from_private_point` is set to false,
/// computing the hash from a public point will take one additional row.
///
/// # Side-effects
///
/// All columns in `advices` and will be equality-enabled.
Expand All @@ -164,7 +176,7 @@ where
fixed_y_q: Column<Fixed>,
lookup: (TableColumn, TableColumn, TableColumn),
range_check: Lookup,
enable_hash_from_private_point: bool,
init_from_private_point: bool,
) -> <Self as Chip<pallas::Base>>::Config {
// Enable equality on all advice columns
for advice in advices.iter() {
Expand All @@ -190,7 +202,7 @@ where
table_y: lookup.2,
},
lookup_config: range_check,
enable_hash_from_private_point,
init_from_private_point,
_marker: PhantomData,
};

Expand All @@ -214,7 +226,7 @@ where
// https://p.z.cash/halo2-0.1:sinsemilla-constraints?partial
meta.create_gate("Initial y_Q", |meta| {
let q_s4 = meta.query_selector(config.q_sinsemilla4);
let y_q = if enable_hash_from_private_point {
let y_q = if init_from_private_point {
meta.query_advice(config.double_and_add.x_p, Rotation::prev())
} else {
meta.query_fixed(config.fixed_y_q)
Expand Down Expand Up @@ -345,7 +357,7 @@ where
Q: &Self::NonIdentityPoint,
message: Self::Message,
) -> Result<(Self::NonIdentityPoint, Vec<Self::RunningSum>), Error> {
if !self.config().enable_hash_from_private_point {
if !self.config().init_from_private_point {
return Err(Error::HashFromPrivatePoint);
}

Expand Down
10 changes: 5 additions & 5 deletions halo2_gadgets/src/sinsemilla/chip/hash_to_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ where
),
Error,
> {
if !self.config().enable_hash_from_private_point {
if !self.config().init_from_private_point {
return Err(Error::HashFromPrivatePoint);
}

Expand All @@ -90,12 +90,12 @@ where
#[allow(non_snake_case)]
/// Assign the coordinates of the initial public point `Q`.
///
/// If enable_hash_from_private_point is not set,
/// If init_from_private_point is not set,
/// | offset | x_A | q_sinsemilla4 | fixed_y_q |
/// --------------------------------------
/// | 0 | x_Q | 1 | y_Q |
///
/// If enable_hash_from_private_point is set,
/// If init_from_private_point is set,
/// | offset | x_A | x_P | q_sinsemilla4 |
/// --------------------------------------
/// | 0 | | y_Q | |
Expand All @@ -114,7 +114,7 @@ where

// Constrain the initial x_a, lambda_1, lambda_2, x_p using the q_sinsemilla4
// selector.
let y_a: Y<pallas::Base> = if config.enable_hash_from_private_point {
let y_a: Y<pallas::Base> = if config.init_from_private_point {
// Enable `q_sinsemilla4` on the second row.
config.q_sinsemilla4.enable(region, 1)?;
let y_a: AssignedCell<Assigned<pallas::Base>, pallas::Base> = region
Expand Down Expand Up @@ -168,7 +168,7 @@ where
) -> Result<(usize, X<pallas::Base>, Y<pallas::Base>), Error> {
let config = self.config().clone();

if !config.enable_hash_from_private_point {
if !config.init_from_private_point {
return Err(Error::HashFromPrivatePoint);
}

Expand Down
11 changes: 5 additions & 6 deletions halo2_gadgets/src/sinsemilla/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,12 +619,11 @@ pub mod tests {
let root = root.titled("MerkleCRH Path", ("sans-serif", 60)).unwrap();

let circuit: MyCircuitWithHashFromPrivatePoint<PallasLookupRangeCheck45BConfig> =
MyCircuitWithHashFromPrivatePoint {
leaf: Value::default(),
leaf_pos: Value::default(),
merkle_path: Value::default(),
_lookup_marker: PhantomData,
};
MyCircuitWithHashFromPrivatePoint::new(
Value::default(),
Value::default(),
Value::default(),
);
halo2_proofs::dev::CircuitLayout::default()
.show_labels(true)
.render(11, &circuit, &root)
Expand Down
22 changes: 16 additions & 6 deletions halo2_gadgets/src/utilities/cond_swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,17 +435,27 @@ mod tests {
_lookup_marker: PhantomData<Lookup>,
}

impl<Lookup: PallasLookupRangeCheck> MyMuxCircuit<Lookup> {
fn new(
left_point: Value<EpAffine>,
right_point: Value<EpAffine>,
choice: Value<pallas::Base>,
) -> Self {
MyMuxCircuit {
left_point,
right_point,
choice,
_lookup_marker: PhantomData,
}
}
}

impl<Lookup: PallasLookupRangeCheck> Circuit<pallas::Base> for MyMuxCircuit<Lookup> {
type Config = MyMuxConfig<Lookup>;
type FloorPlanner = SimpleFloorPlanner;

fn without_witnesses(&self) -> Self {
MyMuxCircuit::<Lookup> {
left_point: Value::default(),
right_point: Value::default(),
choice: Value::default(),
_lookup_marker: PhantomData,
}
MyMuxCircuit::<Lookup>::new(Value::default(), Value::default(), Value::default())
}

fn configure(meta: &mut ConstraintSystem<pallas::Base>) -> Self::Config {
Expand Down

0 comments on commit 03dbe70

Please sign in to comment.