Skip to content

Centralize block-size bounds and improve trait documentation#424

Open
0xxreacher wants to merge 1 commit into
facebook:mainfrom
0xxreacher:patch-1
Open

Centralize block-size bounds and improve trait documentation#424
0xxreacher wants to merge 1 commit into
facebook:mainfrom
0xxreacher:patch-1

Conversation

@0xxreacher

Copy link
Copy Markdown

Summary

This PR introduces an internal ValidBlockSize marker trait and uses it to centralize the block-size constraints required by ProxyHash and Hash.

It also clarifies documentation by explicitly distinguishing a hash function's internal block size from its digest output size.

Changes

  • Add pub(crate) trait ValidBlockSize
  • Add a blanket implementation for types satisfying the block-size requirements
  • Replace duplicated typenum bounds in ProxyHash and Hash
  • Improve documentation around block-size constraints and OutputSize

Motivation

The same typenum constraints were repeated across multiple trait definitions and implementations:

<Self as BlockSizeUser>::BlockSize: IsLess<U256>,
Le<<Self as BlockSizeUser>::BlockSize, U256>: NonZero,

Centralizing these constraints:

  • Reduces duplication
  • Improves readability of trait signatures
  • Provides a single source of truth for block-size requirements
  • Simplifies future maintenance

The documentation updates also make it explicit that the constraint applies to a hash function's internal block size (BlockSizeUser::BlockSize) rather than its digest output size.

Compatibility

This change is purely a refactor and documentation improvement. There are no functional, behavioral, or public API changes.

Introduce an internal `ValidBlockSize` marker trait to centralize
the block-size bounds used by `ProxyHash` and `Hash`.

This refactor removes duplicated typenum constraints, improves
readability, and provides a single source of truth for block-size
requirements.

Also clarify documentation by explicitly distinguishing hash block
size from digest output size.

No functional or public API changes.
@meta-cla meta-cla Bot added the cla signed label Jul 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant