Skip to content

Commit

Permalink
initial doc
Browse files Browse the repository at this point in the history
  • Loading branch information
YaoGalteland committed Apr 15, 2024
1 parent ec1ebfd commit fc37508
Show file tree
Hide file tree
Showing 24 changed files with 352 additions and 337 deletions.
6 changes: 3 additions & 3 deletions halo2_gadgets/src/ecc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub mod chip;

/// The set of circuit instructions required to use the ECC gadgets.
pub trait EccInstructions<C: CurveAffine>:
Chip<C::Base> + UtilitiesInstructions<C::Base> + Clone + Debug + Eq
Chip<C::Base> + UtilitiesInstructions<C::Base> + Clone + Debug + Eq
{
/// Variable representing a scalar used in variable-base scalar mul.
///
Expand Down Expand Up @@ -380,7 +380,7 @@ impl<C: CurveAffine, EccChip: EccInstructions<C>> NonIdentityPoint<C, EccChip> {
}

impl<C: CurveAffine, EccChip: EccInstructions<C> + Clone + Debug + Eq>
From<NonIdentityPoint<C, EccChip>> for Point<C, EccChip>
From<NonIdentityPoint<C, EccChip>> for Point<C, EccChip>
{
fn from(non_id_point: NonIdentityPoint<C, EccChip>) -> Self {
Self {
Expand Down Expand Up @@ -638,7 +638,7 @@ pub(crate) mod tests {
},
FixedPoints,
};
use crate::utilities::lookup_range_check::{LookupRangeCheckConfig, LookupRangeCheck};
use crate::utilities::lookup_range_check::{LookupRangeCheck, LookupRangeCheckConfig};

#[derive(Debug, Eq, PartialEq, Clone)]
pub(crate) struct TestFixedBases;
Expand Down
24 changes: 12 additions & 12 deletions halo2_gadgets/src/ecc/chip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ impl<FixedPoints: super::FixedPoints<pallas::Affine>> Chip<pallas::Base> for Ecc
}

impl<Fixed: super::FixedPoints<pallas::Affine>> UtilitiesInstructions<pallas::Base>
for EccChip<Fixed>
for EccChip<Fixed>
{
type Var = AssignedCell<pallas::Base, pallas::Base>;
}
Expand Down Expand Up @@ -360,7 +360,7 @@ pub struct EccScalarFixedShort {
/// The circuit-assigned running sum constraining this signed short scalar, or `None`
/// if the scalar has not been used yet.
running_sum:
Option<ArrayVec<AssignedCell<pallas::Base, pallas::Base>, { NUM_WINDOWS_SHORT + 1 }>>,
Option<ArrayVec<AssignedCell<pallas::Base, pallas::Base>, { NUM_WINDOWS_SHORT + 1 }>>,
}

/// A base field element used for fixed-base scalar multiplication.
Expand Down Expand Up @@ -408,12 +408,12 @@ pub enum ScalarVar {
}

impl<Fixed: FixedPoints<pallas::Affine>> EccInstructions<pallas::Affine> for EccChip<Fixed>
where
<Fixed as FixedPoints<pallas::Affine>>::Base:
where
<Fixed as FixedPoints<pallas::Affine>>::Base:
FixedPoint<pallas::Affine, FixedScalarKind = BaseFieldElem>,
<Fixed as FixedPoints<pallas::Affine>>::FullScalar:
<Fixed as FixedPoints<pallas::Affine>>::FullScalar:
FixedPoint<pallas::Affine, FixedScalarKind = FullScalar>,
<Fixed as FixedPoints<pallas::Affine>>::ShortScalar:
<Fixed as FixedPoints<pallas::Affine>>::ShortScalar:
FixedPoint<pallas::Affine, FixedScalarKind = ShortScalar>,
{
type ScalarFixed = EccScalarFixed;
Expand Down Expand Up @@ -625,13 +625,13 @@ impl<Fixed: FixedPoints<pallas::Affine>> EccInstructions<pallas::Affine> for Ecc
}

impl<Fixed: FixedPoints<pallas::Affine>> BaseFitsInScalarInstructions<pallas::Affine>
for EccChip<Fixed>
where
<Fixed as FixedPoints<pallas::Affine>>::Base:
for EccChip<Fixed>
where
<Fixed as FixedPoints<pallas::Affine>>::Base:
FixedPoint<pallas::Affine, FixedScalarKind = BaseFieldElem>,
<Fixed as FixedPoints<pallas::Affine>>::FullScalar:
<Fixed as FixedPoints<pallas::Affine>>::FullScalar:
FixedPoint<pallas::Affine, FixedScalarKind = FullScalar>,
<Fixed as FixedPoints<pallas::Affine>>::ShortScalar:
<Fixed as FixedPoints<pallas::Affine>>::ShortScalar:
FixedPoint<pallas::Affine, FixedScalarKind = ShortScalar>,
{
fn scalar_var_from_base(
Expand All @@ -641,4 +641,4 @@ for EccChip<Fixed>
) -> Result<Self::ScalarVar, Error> {
Ok(ScalarVar::BaseFieldElem(base.clone()))
}
}
}
2 changes: 1 addition & 1 deletion halo2_gadgets/src/ecc/chip/mul/overflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use halo2_proofs::{
};
use pasta_curves::pallas;

use std::iter;
use crate::utilities::lookup_range_check::LookupRangeCheck;
use std::iter;

#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub struct Config {
Expand Down
2 changes: 1 addition & 1 deletion halo2_gadgets/src/ecc/chip/mul_fixed/base_field_elem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use halo2_proofs::{
};
use pasta_curves::pallas;

use std::convert::TryInto;
use crate::utilities::lookup_range_check::LookupRangeCheck;
use std::convert::TryInto;

Check warning on line 19 in halo2_gadgets/src/ecc/chip/mul_fixed/base_field_elem.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

the item `TryInto` is imported redundantly

warning: the item `TryInto` is imported redundantly --> halo2_gadgets/src/ecc/chip/mul_fixed/base_field_elem.rs:19:5 | 19 | use std::convert::TryInto; | ^^^^^^^^^^^^^^^^^^^^^ --> /rustc/6fd1912922a7b468b1875d16571bb7a00d5df93f/library/std/src/prelude/mod.rs:129:13 | = note: the item `TryInto` is already defined here

Check warning on line 19 in halo2_gadgets/src/ecc/chip/mul_fixed/base_field_elem.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

the item `TryInto` is imported redundantly

warning: the item `TryInto` is imported redundantly --> halo2_gadgets/src/ecc/chip/mul_fixed/base_field_elem.rs:19:5 | 19 | use std::convert::TryInto; | ^^^^^^^^^^^^^^^^^^^^^ --> /rustc/6fd1912922a7b468b1875d16571bb7a00d5df93f/library/std/src/prelude/mod.rs:129:13 | = note: the item `TryInto` is already defined here

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Config<Fixed: FixedPoints<pallas::Affine>> {
Expand Down
4 changes: 2 additions & 2 deletions halo2_gadgets/src/ecc/chip/mul_fixed/short.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ use std::convert::TryInto;
use super::super::{EccPoint, EccScalarFixedShort, FixedPoints, L_SCALAR_SHORT, NUM_WINDOWS_SHORT};
use crate::{ecc::chip::MagnitudeSign, utilities::bool_check};

use halo2_proofs::circuit::AssignedCell;
use halo2_proofs::{
circuit::{Layouter, Region},
plonk::{ConstraintSystem, Constraints, Error, Expression, Selector},
poly::Rotation,
};
use pasta_curves::pallas;
use halo2_proofs::circuit::AssignedCell;

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Config<Fixed: FixedPoints<pallas::Affine>> {
Expand Down Expand Up @@ -316,6 +316,7 @@ pub mod tests {
};
use pasta_curves::pallas;

use crate::utilities::lookup_range_check::LookupRangeCheck;
use crate::{
ecc::{
chip::{EccChip, FixedPoint, MagnitudeSign},
Expand All @@ -324,7 +325,6 @@ pub mod tests {
},
utilities::{lookup_range_check::LookupRangeCheckConfig, UtilitiesInstructions},
};
use crate::utilities::lookup_range_check::LookupRangeCheck;

#[allow(clippy::op_ref)]
pub(crate) fn test_mul_fixed_short(
Expand Down
4 changes: 2 additions & 2 deletions halo2_gadgets/src/ecc/chip/witness_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,6 @@ pub mod tests {
layouter.namespace(|| "witness identity"),
Value::known(pallas::Affine::identity()),
)
.expect_err("witnessing 𝒪 should return an error");
.expect_err("witnessing 𝒪 should return an error");
}
}
}
2 changes: 1 addition & 1 deletion halo2_gadgets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ pub mod poseidon;
#[cfg_attr(docsrs, doc(cfg(feature = "unstable-sha256-gadget")))]
pub mod sha256;
pub mod sinsemilla;
pub mod sinsemilla_opt;

Check failure on line 30 in halo2_gadgets/src/lib.rs

View workflow job for this annotation

GitHub Actions / Bitrot check

missing documentation for a module

Check failure on line 30 in halo2_gadgets/src/lib.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

missing documentation for a module

error: missing documentation for a module --> halo2_gadgets/src/lib.rs:30:1 | 30 | pub mod sinsemilla_opt; | ^^^^^^^^^^^^^^^^^^^^^^ | note: the lint level is defined here --> halo2_gadgets/src/lib.rs:21:9 | 21 | #![deny(missing_docs)] | ^^^^^^^^^^^^
pub mod utilities;
pub mod utilities_opt;
pub mod sinsemilla_opt;
34 changes: 16 additions & 18 deletions halo2_gadgets/src/sinsemilla.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ pub trait SinsemillaInstructions<C: CurveAffine, const K: usize, const MAX_WORDS
message: Self::Message,
) -> Result<(Self::NonIdentityPoint, Vec<Self::RunningSum>), Error>;


/// Hashes a message to an ECC curve point.
/// This returns both the resulting point, as well as the message
/// decomposition in the form of intermediate values in a cumulative
Expand All @@ -103,7 +102,6 @@ pub trait SinsemillaInstructions<C: CurveAffine, const K: usize, const MAX_WORDS
message: Self::Message,
) -> Result<(Self::NonIdentityPoint, Vec<Self::RunningSum>), Error>;


/// Extracts the x-coordinate of the output of a Sinsemilla hash.
fn extract(point: &Self::NonIdentityPoint) -> Self::X;
}
Expand All @@ -115,17 +113,17 @@ pub trait SinsemillaInstructions<C: CurveAffine, const K: usize, const MAX_WORDS
/// [`MessagePiece`]: SinsemillaInstructions::MessagePiece
#[derive(Clone, Debug)]
pub struct Message<C: CurveAffine, SinsemillaChip, const K: usize, const MAX_WORDS: usize>
where
SinsemillaChip: SinsemillaInstructions<C, K, MAX_WORDS> + Clone + Debug + Eq,
where
SinsemillaChip: SinsemillaInstructions<C, K, MAX_WORDS> + Clone + Debug + Eq,
{
chip: SinsemillaChip,
inner: SinsemillaChip::Message,
}

impl<C: CurveAffine, SinsemillaChip, const K: usize, const MAX_WORDS: usize>
Message<C, SinsemillaChip, K, MAX_WORDS>
where
SinsemillaChip: SinsemillaInstructions<C, K, MAX_WORDS> + Clone + Debug + Eq,
Message<C, SinsemillaChip, K, MAX_WORDS>
where
SinsemillaChip: SinsemillaInstructions<C, K, MAX_WORDS> + Clone + Debug + Eq,
{
#![allow(dead_code)]
fn from_bitstring(
Expand Down Expand Up @@ -179,16 +177,16 @@ Message<C, SinsemillaChip, K, MAX_WORDS>
/// A message piece with a bitlength of some multiple of `K`.
#[derive(Copy, Clone, Debug)]
pub struct MessagePiece<C: CurveAffine, SinsemillaChip, const K: usize, const MAX_WORDS: usize>
where
SinsemillaChip: SinsemillaInstructions<C, K, MAX_WORDS> + Clone + Debug + Eq,
where
SinsemillaChip: SinsemillaInstructions<C, K, MAX_WORDS> + Clone + Debug + Eq,
{
inner: SinsemillaChip::MessagePiece,
}

impl<C: CurveAffine, SinsemillaChip, const K: usize, const MAX_WORDS: usize>
MessagePiece<C, SinsemillaChip, K, MAX_WORDS>
where
SinsemillaChip: SinsemillaInstructions<C, K, MAX_WORDS> + Clone + Debug + Eq,
MessagePiece<C, SinsemillaChip, K, MAX_WORDS>
where
SinsemillaChip: SinsemillaInstructions<C, K, MAX_WORDS> + Clone + Debug + Eq,
{
/// Returns the inner MessagePiece contained in this gadget.
pub fn inner(&self) -> SinsemillaChip::MessagePiece {
Expand All @@ -197,9 +195,9 @@ MessagePiece<C, SinsemillaChip, K, MAX_WORDS>
}

impl<C: CurveAffine, SinsemillaChip, const K: usize, const MAX_WORDS: usize>
MessagePiece<C, SinsemillaChip, K, MAX_WORDS>
where
SinsemillaChip: SinsemillaInstructions<C, K, MAX_WORDS> + Clone + Debug + Eq,
MessagePiece<C, SinsemillaChip, K, MAX_WORDS>
where
SinsemillaChip: SinsemillaInstructions<C, K, MAX_WORDS> + Clone + Debug + Eq,
{
#![allow(dead_code)]
fn from_bitstring(
Expand Down Expand Up @@ -381,7 +379,7 @@ HashDomain<C, SinsemillaChip, EccChip, K, MAX_WORDS>

/// Trait allowing circuit's Sinsemilla CommitDomains to be enumerated.
pub trait CommitDomains<C: CurveAffine, F: FixedPoints<C>, H: HashDomains<C>>:
Clone + Debug
Clone + Debug
{
/// Returns the fixed point corresponding to the R constant used for
/// randomization in this CommitDomain.
Expand Down Expand Up @@ -578,9 +576,9 @@ pub(crate) mod tests {
use lazy_static::lazy_static;
use pasta_curves::pallas;

use std::convert::TryInto;
use crate::sinsemilla::chip::SinsemillaChipProps;
use crate::utilities::lookup_range_check::LookupRangeCheck;
use std::convert::TryInto;

Check warning on line 581 in halo2_gadgets/src/sinsemilla.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

the item `TryInto` is imported redundantly

warning: the item `TryInto` is imported redundantly --> halo2_gadgets/src/sinsemilla.rs:581:9 | 581 | use std::convert::TryInto; | ^^^^^^^^^^^^^^^^^^^^^ --> /rustc/6fd1912922a7b468b1875d16571bb7a00d5df93f/library/std/src/prelude/mod.rs:129:13 | = note: the item `TryInto` is already defined here

pub(crate) const PERSONALIZATION: &str = "MerkleCRH";

Expand Down Expand Up @@ -650,7 +648,7 @@ pub(crate) mod tests {

let table_idx = meta.lookup_table_column();
#[cfg(feature = "zsa")]
let table_range_check_tag = meta.lookup_table_column();
let table_range_check_tag = meta.lookup_table_column();
let lagrange_coeffs = [
meta.fixed_column(),
meta.fixed_column(),
Expand Down
Loading

0 comments on commit fc37508

Please sign in to comment.