Add domain separation parameter to hash_to_scalar#164
Merged
Conversation
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.
1d9deeb to
661534b
Compare
There was a problem hiding this comment.
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_scalarsignature tohash_to_scalar(domain: &[u8; 32], input: &[u8])and prependsdomainiff 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.
HDauven
approved these changes
Mar 20, 2026
Pin the exact scalar output for a known domain and input, ensuring any change to the hash construction is caught by the test suite.
88cb6ff to
44fd528
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add a
domain: &[u8; 32]parameter toScalar::hash_to_scalarfor 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.