Skip to content

Commit

Permalink
Merge pull request #829 from zcash/sinsemilla-primitive
Browse files Browse the repository at this point in the history
Move Sinsemilla primitive impl into `sinsemilla` crate
  • Loading branch information
str4d authored Dec 14, 2024
2 parents 94cf956 + 19a9f2e commit 7a39f55
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 14,729 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion halo2_gadgets/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ lazy_static = "1"
pasta_curves = "0.5"
proptest = { version = "1.0.0", optional = true }
rand = "0.8"
sinsemilla = "0.1"
subtle = "2.3"
uint = "0.9.2" # MSRV 1.56.1

Expand All @@ -40,6 +41,7 @@ plotters = { version = "0.3.0", default-features = false, optional = true }
[dev-dependencies]
criterion = "0.3"
proptest = "1.0.0"
sinsemilla = { version = "0.1", features = ["test-dependencies"] }

[target.'cfg(unix)'.dev-dependencies]
inferno = ">=0.11, <0.11.5" # MSRV 1.59
Expand All @@ -56,7 +58,10 @@ test-dev-graph = [
"plotters/bitmap_encoder",
"plotters/ttf",
]
test-dependencies = ["proptest"]
test-dependencies = [
"proptest",
"sinsemilla/test-dependencies",
]

# In-development features
# See https://zcash.github.io/halo2/dev/features.html
Expand Down
3 changes: 2 additions & 1 deletion halo2_gadgets/src/sinsemilla.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ use std::fmt::Debug;
pub mod chip;
pub mod merkle;
mod message;
pub mod primitives;

pub use ::sinsemilla as primitives;

/// The set of circuit instructions required to use the [`Sinsemilla`](https://zcash.github.io/halo2/design/gadgets/sinsemilla.html) gadget.
/// This trait is bounded on two constant parameters: `K`, the number of bits
Expand Down
7 changes: 6 additions & 1 deletion halo2_gadgets/src/sinsemilla/chip/hash_to_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,11 @@ where
.collect();

let hasher_S = pallas::Point::hash_to_curve(S_PERSONALIZATION);
let S = |chunk: &[bool]| hasher_S(&lebs2ip_k(chunk).to_le_bytes());
let S = |chunk: &[bool]| {
hasher_S(
&lebs2ip_k(chunk.try_into().expect("correct length")).to_le_bytes(),
)
};

// We can use complete addition here because it differs from
// incomplete addition with negligible probability.
Expand Down Expand Up @@ -249,6 +253,7 @@ where
let words: Value<Vec<u32>> = bitstring.map(|bitstring| {
bitstring
.chunks_exact(sinsemilla::K)
.map(|chunk| chunk.try_into().expect("correct length"))
.map(lebs2ip_k)
.collect()
});
Expand Down
1 change: 0 additions & 1 deletion halo2_gadgets/src/sinsemilla/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,6 @@ pub mod tests {
(sibling, &node)
};

use crate::sinsemilla::primitives as sinsemilla;
let merkle_crh =
sinsemilla::HashDomain::from_Q(TestHashDomain.Q().into());

Expand Down
Loading

0 comments on commit 7a39f55

Please sign in to comment.