Skip to content

Commit

Permalink
Add Sinsemilla gadget
Browse files Browse the repository at this point in the history
  • Loading branch information
therealyingtong committed Feb 26, 2021
1 parent f9a089d commit 8918160
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/circuit/gadget.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub(crate) mod ecc;
pub(crate) mod sinsemilla;
36 changes: 36 additions & 0 deletions src/circuit/gadget/sinsemilla.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//! Gadget and chips for the Sinsemilla hash function.
use halo2::{
arithmetic::CurveAffine,
circuit::{Chip, Layouter},
plonk::Error,
};

/// The set of circuit instructions required to use the [`Sinsemilla`](https://zcash.github.io/halo2/design/gadgets/sinsemilla.html) gadget.
pub trait SinsemillaInstructions<C: CurveAffine>: Chip<Field = C::Base> {
type Message: Iterator<Item = bool> + ExactSizeIterator;

fn extract(point: &C::Curve) -> C::Base;

#[allow(non_snake_case)]
fn Q(domain_prefix: &str) -> C::Curve;

fn hash_to_point(
layouter: &mut impl Layouter<Self>,
domain_prefix: &str,
message: Self::Message,
) -> Result<C::Curve, Error>;

fn hash(
layouter: &mut impl Layouter<Self>,
domain_prefix: &str,
message: Self::Message,
) -> Result<C::Base, Error>;

fn commit(domain_prefix: &str, msg: Self::Message, r: &C::Scalar) -> Result<C::Curve, Error>;

fn short_commit(
domain_prefix: &str,
msg: Self::Message,
r: &C::Scalar,
) -> Result<C::Base, Error>;
}
10 changes: 7 additions & 3 deletions src/primitives/sinsemilla.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ use halo2::{
pasta::pallas,
};

const GROUP_HASH_Q: &str = "z.cash:SinsemillaQ";
const GROUP_HASH_S: &str = "z.cash:SinsemillaS";
/// Domain prefix used in SWU hash-to-curve to generate Q.
pub const GROUP_HASH_Q: &str = "z.cash:SinsemillaQ";

const K: usize = 10;
/// Domain prefix used in SWU hash-to-curve to generate S_i's.
pub const GROUP_HASH_S: &str = "z.cash:SinsemillaS";

/// There are 2^K S_i generators in the Sinsemilla lookup.
pub const K: usize = 10;
const C: usize = 253;

fn lebs2ip_32(bits: &[bool]) -> u32 {
Expand Down

0 comments on commit 8918160

Please sign in to comment.