Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Sinsemilla primitive impl into sinsemilla crate #829

Merged
merged 1 commit into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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 @@
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 Expand Up @@ -655,8 +656,8 @@
let point = merkle_crh
.hash_to_point(
l.into_iter()
.chain(left.into_iter())

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

View workflow job for this annotation

GitHub Actions / Clippy (beta)

explicit call to `.into_iter()` in function argument accepting `IntoIterator`

warning: explicit call to `.into_iter()` in function argument accepting `IntoIterator` --> halo2_gadgets/src/sinsemilla.rs:659:48 | 659 | ... .chain(left.into_iter()) | ^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`: `left` | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` --> /rustc/202008a1b8de96d2e5b6bc02d379db03a877d34d/library/core/src/iter/traits/iterator.rs:471:12 = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion = note: `-W clippy::useless-conversion` implied by `-W clippy::all` = help: to override `-W clippy::all` add `#[allow(clippy::useless_conversion)]`
.chain(right.into_iter()),

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

View workflow job for this annotation

GitHub Actions / Clippy (beta)

explicit call to `.into_iter()` in function argument accepting `IntoIterator`

warning: explicit call to `.into_iter()` in function argument accepting `IntoIterator` --> halo2_gadgets/src/sinsemilla.rs:660:48 | 660 | ... .chain(right.into_iter()), | ^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`: `right` | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` --> /rustc/202008a1b8de96d2e5b6bc02d379db03a877d34d/library/core/src/iter/traits/iterator.rs:471:12 = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion
)
.unwrap();
point.to_affine()
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 @@ -171,7 +171,7 @@
}

#[cfg(test)]
pub mod tests {

Check failure on line 174 in halo2_gadgets/src/sinsemilla/merkle.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/sinsemilla/merkle.rs:174:1 | 174 | pub mod tests { | ^^^^^^^^^^^^^ | note: the lint level is defined here --> halo2_gadgets/src/lib.rs:21:9 | 21 | #![deny(missing_docs)] | ^^^^^^^^^^^^

Check failure on line 174 in halo2_gadgets/src/sinsemilla/merkle.rs

View workflow job for this annotation

GitHub Actions / Code coverage

missing documentation for a module

Check failure on line 174 in halo2_gadgets/src/sinsemilla/merkle.rs

View workflow job for this annotation

GitHub Actions / Code coverage

missing documentation for a module
use super::{
chip::{MerkleChip, MerkleConfig},
MerklePath,
Expand Down Expand Up @@ -322,7 +322,6 @@
(sibling, &node)
};

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

Expand Down
Loading
Loading