feat(acir_field): Add little-endian byte serialization for FieldElement #7258
+25
−3
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.
Description
Added a new to_le_bytes() method to FieldElement that provides native little-endian byte serialization. This complements the existing to_be_bytes() method and allows callers to choose their preferred endianness without manual byte reversal.
Changes:
Problem
Resolves #TODO
Summary
Added little-endian byte serialization support for FieldElement to provide more flexibility in byte order handling. Previously, the to_be_bytes() method was using little-endian serialization internally and then reversing the bytes. This PR adds a dedicated to_le_bytes() method to make the endianness handling more explicit and efficient.
Additional Context
The implementation:
Adds new to_le_bytes() method that returns bytes in little-endian order
Removes redundant comments from to_be_bytes()
Includes comprehensive test coverage for both endianness formats
Maintains backward compatibility with existing code
Documentation
[x] No documentation needed.
PR Checklist
[x] I have tested the changes locally.
Added new test case test_endianness() that verifies correct byte ordering
Verified existing tests pass
[x] I have formatted the changes with Prettier and/or cargo fmt on default settings.
Code follows Rust formatting guidelines
All new code is properly documented with comments