Skip to content

Little endianness serialization method #156

Open
TalDerei wants to merge 1 commit into
zkcrypto:mainfrom
TalDerei:le-serialization
Open

Little endianness serialization method #156
TalDerei wants to merge 1 commit into
zkcrypto:mainfrom
TalDerei:le-serialization

Conversation

@TalDerei
Copy link
Copy Markdown

@TalDerei TalDerei commented May 27, 2026

References #155 (comment) and pairs with zkcrypto/group#81. Adds a second to_le_repr serialization on PrimeField as a provided trait method.

@TalDerei TalDerei mentioned this pull request May 27, 2026
@tarcieri
Copy link
Copy Markdown
Contributor

This is what we did in RustCrypto#10 but I was hoping there was a more elegant solution

Comment thread src/lib.rs
Comment on lines +296 to +298
/// The default implementation assumes [`Self::to_repr`] already returns a little-endian
/// encoding. Implementors whose [`Self::to_repr`] uses big-endian encoding must override
/// this method (e.g. by reversing the bytes).
Copy link
Copy Markdown
Member

@str4d str4d May 28, 2026

Choose a reason for hiding this comment

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

This is a bad assumption to include in a root trait's default method, because downstream trait implementers will not be aware that they need to override it.

Comment thread src/lib.rs
/// The default implementation assumes [`Self::to_repr`] already returns a little-endian
/// encoding. Implementors whose [`Self::to_repr`] uses big-endian encoding must override
/// this method (e.g. by reversing the bytes).
fn to_le_repr(&self) -> Self::Repr {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This cannot return Self::Repr, because this is not guaranteed to be round-trip compatible with Self::from_repr.

Copy link
Copy Markdown
Member

@str4d str4d left a comment

Choose a reason for hiding this comment

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

NACK for reasons in my comments and in #155 (comment).

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