Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions halo2_gadgets/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@ and this project adheres to Rust's notion of
a shorthand for `LookupRangeCheck` specialized with `pallas::Base` and `sinsemilla::K`
- `halo2_gadgets::utilities::lookup_range_check::PallasLookupRangeCheckConfig` which is
a shorthand for `LookupRangeCheckConfig` specialized with `pallas::Base` and `sinsemilla::K`
- `halo2_gadgets::ecc::Point::{mul_sign, new_from_constant}`
- `halo2_gadgets::sinsemilla::CommitDomain::{blinding_factor, hash_with_private_init, q_init}`
- `halo2_gadgets::utilities::cond_swap::CondSwapChip::{mux_on_points, mux_on_non_identity_points}`

### Changed
- `halo2_gadgets::utilities::lookup_range_check::witness_short` now takes a generic `Lookup`
instead of directly taking a `LookupRangeCheckConfig<F, K>` reference
- `halo2_gadgets::sinsemilla::merkle::chip::MerkleConfig::cond_swap_config` is now public
- `halo2_gadgets::sinsemilla::chip::SinsemillaChip::configure` has a new input
`init_from_private_point` to enable the evaluation of Sinsemilla hash from a private point.

## [0.3.1] - 2024-12-16
- `halo2_gadgets::poseidon::primitives` is now a re-export of the new `halo2_poseidon`
Expand Down
19 changes: 11 additions & 8 deletions halo2_gadgets/src/ecc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,14 @@ pub(crate) mod tests {
use group::{prime::PrimeCurveAffine, Curve, Group};
use std::marker::PhantomData;

use halo2_proofs::{
circuit::{Layouter, SimpleFloorPlanner, Value},
dev::MockProver,
plonk::{Circuit, ConstraintSystem, Error},
};
use lazy_static::lazy_static;
use pasta_curves::pallas;

use super::{
chip::{
find_zs_and_us, BaseFieldElem, EccChip, EccConfig, FixedPoint, FullScalar, ShortScalar,
Expand All @@ -638,13 +646,6 @@ pub(crate) mod tests {
PallasLookupRangeCheck, PallasLookupRangeCheck4_5BConfig, PallasLookupRangeCheckConfig,
},
};
use halo2_proofs::{
circuit::{Layouter, SimpleFloorPlanner, Value},
dev::MockProver,
plonk::{Circuit, ConstraintSystem, Error},
};
use lazy_static::lazy_static;
use pasta_curves::pallas;

#[derive(Debug, Eq, PartialEq, Clone)]
pub(crate) struct TestFixedBases;
Expand Down Expand Up @@ -841,7 +842,9 @@ pub(crate) mod tests {

// Load 10-bit lookup table. In the Action circuit, this will be
// provided by the Sinsemilla chip.
config.lookup_config.load(&mut layouter)?;
config
.lookup_config
.load_only_range_check_table(&mut layouter)?;

// Generate a random non-identity point P
let p_val = pallas::Point::random(rand::rngs::OsRng).to_affine(); // P
Expand Down
2 changes: 1 addition & 1 deletion halo2_gadgets/src/ecc/chip/mul_fixed/short.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@

/// Multiply the point by sign, using the q_mul_fixed_short gate.
/// Constraints `sign` in {-1, 1}
pub fn assign_scalar_sign(
pub(crate) fn assign_scalar_sign(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the visiability reduction?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To evaluate a variable-base sign-scalar multiplication in Orchard, we use the function mul_sign.
This function assign_scalarmulis used internally withinmul_sign` and is never called outside of Halo2.

&self,
mut layouter: impl Layouter<pallas::Base>,
sign: &AssignedCell<pallas::Base, pallas::Base>,
Expand Down Expand Up @@ -576,11 +576,11 @@
"-1".into()
} else {
// Format value as hex.
let s = format!("{:?}", v);

Check warning on line 579 in halo2_gadgets/src/ecc/chip/mul_fixed/short.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

variables can be used directly in the `format!` string

warning: variables can be used directly in the `format!` string --> halo2_gadgets/src/ecc/chip/mul_fixed/short.rs:579:21 | 579 | let s = format!("{:?}", v); | ^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args = note: `-W clippy::uninlined-format-args` implied by `-W clippy::all` = help: to override `-W clippy::all` add `#[allow(clippy::uninlined_format_args)]` help: change this to | 579 - let s = format!("{:?}", v); 579 + let s = format!("{v:?}"); |
// Remove leading zeroes.
let s = s.strip_prefix("0x").unwrap();
let s = s.trim_start_matches('0');
format!("0x{}", s)

Check warning on line 583 in halo2_gadgets/src/ecc/chip/mul_fixed/short.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

variables can be used directly in the `format!` string

warning: variables can be used directly in the `format!` string --> halo2_gadgets/src/ecc/chip/mul_fixed/short.rs:583:13 | 583 | format!("0x{}", s) | ^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args help: change this to | 583 - format!("0x{}", s) 583 + format!("0x{s}") |
}
}

Expand Down
7 changes: 3 additions & 4 deletions halo2_gadgets/src/sinsemilla/chip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use halo2_proofs::{
};
use pasta_curves::pallas;

mod generator_table;
pub(crate) mod generator_table;
use generator_table::GeneratorTableConfig;

mod hash_to_point;
Expand Down Expand Up @@ -153,9 +153,7 @@ where
layouter: &mut impl Layouter<pallas::Base>,
) -> Result<<Self as Chip<pallas::Base>>::Loaded, Error> {
// Load the lookup table.
config
.generator_table
.load(config.lookup_config.table_range_check_tag(), layouter)
config.generator_table.load(config.lookup_config, layouter)
}

/// Creates the Sinsemilla chip
Expand Down Expand Up @@ -285,6 +283,7 @@ where

Constraints::with_selector(q_s1, [("Secant line", secant_line), ("y check", y_check)])
});

Comment thread
PaulLaux marked this conversation as resolved.
config
}
}
Expand Down
151 changes: 11 additions & 140 deletions halo2_gadgets/src/sinsemilla/chip/generator_table.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use ff::PrimeFieldBits;
use group::ff::PrimeField;
use halo2_proofs::{
circuit::{Layouter, Value},
circuit::Layouter,
plonk::{ConstraintSystem, Error, Expression, TableColumn},
poly::Rotation,
};

use super::{CommitDomains, FixedPoints, HashDomains};
use crate::{
sinsemilla::primitives::{self as sinsemilla, K, SINSEMILLA_S},
utilities::lookup_range_check::PallasLookupRangeCheck,
sinsemilla::primitives::{self as sinsemilla, SINSEMILLA_S},
utilities::lookup_range_check::{LookupRangeCheck, PallasLookupRangeCheck},
};
use pasta_curves::pallas;

Expand Down Expand Up @@ -82,144 +83,14 @@ impl GeneratorTableConfig {
}

/// Load the generator table into the circuit.
pub fn load(
pub fn load<F, const K: usize>(
&self,
table_range_check_tag: Option<TableColumn>,
lookup_config: impl LookupRangeCheck<F, K>,
layouter: &mut impl Layouter<pallas::Base>,
) -> Result<(), Error> {
match table_range_check_tag {
Some(tag) => self.load_with_tag(tag, layouter),
None => self.load_without_tag(layouter),
}
}

/// Load the generator table into the circuit.
///
/// | table_idx | table_x | table_y |
/// ------------------------------------------------
/// | 0 | X(S\[0\]) | Y(S\[0\]) |
/// | 1 | X(S\[1\]) | Y(S\[1\]) |
/// | ... | ... | ... |
/// | 2^10-1 | X(S\[2^10-1\]) | Y(S\[2^10-1\]) |
pub fn load_without_tag(
&self,
layouter: &mut impl Layouter<pallas::Base>,
) -> Result<(), Error> {
layouter.assign_table(
|| "generator_table",
|mut table| {
for (index, (x, y)) in SINSEMILLA_S.iter().enumerate() {
table.assign_cell(
|| "table_idx",
self.table_idx,
index,
|| Value::known(pallas::Base::from(index as u64)),
)?;
table.assign_cell(|| "table_x", self.table_x, index, || Value::known(*x))?;
table.assign_cell(|| "table_y", self.table_y, index, || Value::known(*y))?;
}
Ok(())
},
)
}

/// Load the generator table into the circuit.
///
/// | table_idx | table_x | table_y | table_range_check_tag |
/// -------------------------------------------------------------------
/// | 0 | X(S\[0\]) | Y(S\[0\]) | 0 |
/// | 1 | X(S\[1\]) | Y(S\[1\]) | 0 |
/// | ... | ... | ... | 0 |
/// | 2^10-1 | X(S\[2^10-1\]) | Y(S\[2^10-1\]) | 0 |
/// | 0 | X(S\[0\]) | Y(S\[0\]) | 4 |
/// | 1 | X(S\[1\]) | Y(S\[1\]) | 4 |
/// | ... | ... | ... | 4 |
/// | 2^4-1 | X(S\[2^4-1\]) | Y(S\[2^4-1\]) | 4 |
/// | 0 | X(S\[0\]) | Y(S\[0\]) | 5 |
/// | 1 | X(S\[1\]) | Y(S\[1\]) | 5 |
/// | ... | ... | ... | 5 |
/// | 2^5-1 | X(S\[2^5-1\]) | Y(S\[2^5-1\]) | 5 |
pub fn load_with_tag(
&self,
table_range_check_tag: TableColumn,
layouter: &mut impl Layouter<pallas::Base>,
) -> Result<(), Error> {
layouter.assign_table(
|| "generator_table",
|mut table| {
for (index, (x, y)) in SINSEMILLA_S.iter().enumerate() {
table.assign_cell(
|| "table_idx",
self.table_idx,
index,
|| Value::known(pallas::Base::from(index as u64)),
)?;
table.assign_cell(|| "table_x", self.table_x, index, || Value::known(*x))?;
table.assign_cell(|| "table_y", self.table_y, index, || Value::known(*y))?;

table.assign_cell(
|| "table_range_check_tag",
table_range_check_tag,
index,
|| Value::known(pallas::Base::zero()),
)?;
if index < (1 << 4) {
let new_index = index + (1 << K);
table.assign_cell(
|| "table_idx",
self.table_idx,
new_index,
|| Value::known(pallas::Base::from(index as u64)),
)?;
table.assign_cell(
|| "table_x",
self.table_x,
new_index,
|| Value::known(*x),
)?;
table.assign_cell(
|| "table_y",
self.table_y,
new_index,
|| Value::known(*y),
)?;
table.assign_cell(
|| "table_range_check_tag",
table_range_check_tag,
new_index,
|| Value::known(pallas::Base::from(4_u64)),
)?;
}
if index < (1 << 5) {
let new_index = index + (1 << 10) + (1 << 4);
table.assign_cell(
|| "table_idx",
self.table_idx,
new_index,
|| Value::known(pallas::Base::from(index as u64)),
)?;
table.assign_cell(
|| "table_x",
self.table_x,
new_index,
|| Value::known(*x),
)?;
table.assign_cell(
|| "table_y",
self.table_y,
new_index,
|| Value::known(*y),
)?;
table.assign_cell(
|| "table_range_check_tag",
table_range_check_tag,
new_index,
|| Value::known(pallas::Base::from(5_u64)),
)?;
}
}
Ok(())
},
)
) -> Result<(), Error>
where
F: PrimeFieldBits,
{
lookup_config.load(self, layouter)
}
}
2 changes: 1 addition & 1 deletion halo2_gadgets/src/sinsemilla/chip/hash_to_point.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::super::{CommitDomains, HashDomains, SinsemillaInstructions};
use super::{NonIdentityEccPoint, SinsemillaChip};
use crate::{
ecc::FixedPoints,
sinsemilla::chip::{NonIdentityEccPoint, SinsemillaChip},
sinsemilla::primitives::{self as sinsemilla, lebs2ip_k, INV_TWO_POW_K, SINSEMILLA_S},
utilities::lookup_range_check::PallasLookupRangeCheck,
};
Expand Down
1 change: 0 additions & 1 deletion halo2_gadgets/src/tests.rs

This file was deleted.

Loading
Loading