Skip to content

Add domain separation parameter to hash_to_scalar#164

Merged
moCello merged 2 commits intomasterfrom
mocello/hash-to-scalar-domain
Mar 20, 2026
Merged

Add domain separation parameter to hash_to_scalar#164
moCello merged 2 commits intomasterfrom
mocello/hash-to-scalar-domain

Conversation

@moCello
Copy link
Copy Markdown
Member

@moCello moCello commented Mar 20, 2026

Add a domain: &[u8; 32] parameter to Scalar::hash_to_scalar for domain separation. When the domain is all zeros, no prefix is applied — output is identical to the previous implementation. When non-zero, the 32-byte domain is prepended to the input before hashing.

This is a compile-time breaking API change. All existing callers should initially pass &[0u8; 32] and adopt real domain tags incrementally.

Add a `domain: &[u8; 32]` parameter to `Scalar::hash_to_scalar` for
domain separation. When the domain is all zeros, no prefix is applied —
output is identical to the previous implementation. When non-zero, the
32-byte domain is prepended to the input before hashing.

This is a compile-time breaking API change. All existing callers
should initially pass `&[0u8; 32]` and adopt real domain tags
incrementally.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces explicit domain separation for Scalar::hash_to_scalar by adding a 32-byte domain parameter and conditionally prefixing it to the hash input, while preserving legacy behavior when the domain is all zeros.

Changes:

  • Updated Scalar::hash_to_scalar signature to hash_to_scalar(domain: &[u8; 32], input: &[u8]) and prepends domain iff it’s non-zero.
  • Added tests to ensure the zero-domain path matches the legacy construction and updated existing fuzz property usage.
  • Documented the breaking API change in CHANGELOG.md.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/scalar/dusk.rs Adds the domain parameter + conditional prefixing logic; adds/updates tests for legacy compatibility and domain separation.
CHANGELOG.md Notes the new domain parameter and the backward-compatible zero-domain behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/scalar/dusk.rs
Comment thread src/scalar/dusk.rs
Pin the exact scalar output for a known domain and input, ensuring
any change to the hash construction is caught by the test suite.
@moCello moCello force-pushed the mocello/hash-to-scalar-domain branch from 88cb6ff to 44fd528 Compare March 20, 2026 14:57
@moCello moCello merged commit f79aa6f into master Mar 20, 2026
3 checks passed
@moCello moCello deleted the mocello/hash-to-scalar-domain branch March 20, 2026 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants