Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(acir_field): Add little-endian byte serialization for FieldElement #7258

Merged
merged 16 commits into from
Feb 18, 2025

Conversation

VolodymyrBg
Copy link
Contributor

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:

  • Added to_le_bytes() method that returns bytes in little-endian order
  • Cleaned up documentation around byte ordering
  • Added test case to verify correct endianness handling

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

Copy link
Contributor

github-actions bot commented Feb 1, 2025

Thank you for your contribution to the Noir language.

Please do not force push to this branch after the Noir team have started review of this PR. Doing so will only delay us merging your PR as we will need to start the review process from scratch.

Thanks for your understanding.

@VolodymyrBg
Copy link
Contributor Author

@aakoshh Corrected

@VolodymyrBg VolodymyrBg requested a review from aakoshh February 10, 2025 15:38
@VolodymyrBg VolodymyrBg requested a review from aakoshh February 11, 2025 14:12
@VolodymyrBg
Copy link
Contributor Author

@aakoshh Done

Copy link
Contributor

@aakoshh aakoshh left a comment

Choose a reason for hiding this comment

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

Thank you for adding this @VolodymyrBg 🙏

It looks good to me, but I'd like to defer to @TomAFrench about it, in case he remembers more context about this TODO.

FWIW I see one location where we're reversing after to_be_bytes, although I'm confused by the comment whether it should be big or little endian.

@VolodymyrBg VolodymyrBg requested a review from aakoshh February 12, 2025 17:08
@TomAFrench
Copy link
Member

This doesn't compile.

@aakoshh aakoshh requested a review from TomAFrench February 13, 2025 09:21
@aakoshh
Copy link
Contributor

aakoshh commented Feb 13, 2025

@VolodymyrBg can you run cargo fmt to format the source? You can configure your editor to do it for you on save. That's why it's failing: https://github.com/noir-lang/noir/actions/runs/13265342549/job/37106914185

@aakoshh
Copy link
Contributor

aakoshh commented Feb 13, 2025

Oh wait, it looks like fbfc367 truncated most of field_element.rs 👀

@VolodymyrBg
Copy link
Contributor Author

Oh wait, it looks like fbfc367 truncated most of field_element.rs 👀

Really, corrected

@aakoshh
Copy link
Contributor

aakoshh commented Feb 13, 2025

Thanks. I'd like to ask though that you revert this branch to 445ac75 , apply the formatting fix there, then force push.

That's because if you look at the blame then it looks like you authored the whole thing, because it all comes from the commit that restored the lost lines. Compared that to what it looked like before a lot of the history is now buried.

@VolodymyrBg
Copy link
Contributor Author

@aakoshh Done

@aakoshh
Copy link
Contributor

aakoshh commented Feb 14, 2025

@TomAFrench this seems ready apart from the circuit size report.

@VolodymyrBg
Copy link
Contributor Author

@TomAFrench
@aakoshh

Copy link
Contributor

@aakoshh aakoshh left a comment

Choose a reason for hiding this comment

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

LGTM!

@aakoshh aakoshh enabled auto-merge February 18, 2025 19:33
@aakoshh aakoshh added this pull request to the merge queue Feb 18, 2025
Merged via the queue into noir-lang:master with commit f37eedc Feb 18, 2025
99 of 100 checks passed
TomAFrench added a commit that referenced this pull request Feb 19, 2025
* master:
  fix(performance): Remove redundant slice access check from brillig (#7434)
  chore(docs): updating tutorials and other nits to beta.2 (#7405)
  feat: LSP hover for integer literals (#7368)
  feat(experimental): Compile match expressions (#7312)
  feat(acir_field): Add little-endian byte serialization for FieldElement (#7258)
  feat: allow unquoting TraitConstraint in trait impl position (#7395)
  feat(brillig): Hoist shared constants across functions to the global space (#7216)
  feat(LSP): auto-import via visible reexport (#7409)
  fix(brillig): Brillig entry point analysis and function specialization through duplication (#7277)
  chore: redo typo PR by maximevtush (#7425)
  fix(ssa): Accurately mark binary ops for hoisting and check Div/Mod against induction variable lower bound (#7396)
  feat!: remove bigint from stdlib (#7411)
AztecBot added a commit to AztecProtocol/aztec-packages that referenced this pull request Feb 19, 2025
…m brillig (noir-lang/noir#7434)

chore(docs): updating tutorials and other nits to beta.2 (noir-lang/noir#7405)
feat: LSP hover for integer literals (noir-lang/noir#7368)
feat(experimental): Compile match expressions (noir-lang/noir#7312)
feat(acir_field): Add little-endian byte serialization for FieldElement (noir-lang/noir#7258)
feat: allow unquoting TraitConstraint in trait impl position (noir-lang/noir#7395)
feat(brillig): Hoist shared constants across functions to the global space (noir-lang/noir#7216)
feat(LSP): auto-import via visible reexport (noir-lang/noir#7409)
fix(brillig): Brillig entry point analysis and function specialization through duplication (noir-lang/noir#7277)
chore: redo typo PR by maximevtush (noir-lang/noir#7425)
fix(ssa): Accurately mark binary ops for hoisting and check Div/Mod against induction variable lower bound (noir-lang/noir#7396)
feat!: remove bigint from stdlib (noir-lang/noir#7411)
chore: bump aztec-packages commit (noir-lang/noir#7415)
chore: deprecate `merkle` module of stdlib (noir-lang/noir#7413)
chore(ci): lock aztec-packages commit in CI (noir-lang/noir#7414)
feat: while statement (noir-lang/noir#7280)
AztecBot added a commit to AztecProtocol/aztec-packages that referenced this pull request Feb 19, 2025
…oir-lang/noir#7434)

chore(docs): updating tutorials and other nits to beta.2 (noir-lang/noir#7405)
feat: LSP hover for integer literals (noir-lang/noir#7368)
feat(experimental): Compile match expressions (noir-lang/noir#7312)
feat(acir_field): Add little-endian byte serialization for FieldElement (noir-lang/noir#7258)
feat: allow unquoting TraitConstraint in trait impl position (noir-lang/noir#7395)
feat(brillig): Hoist shared constants across functions to the global space (noir-lang/noir#7216)
feat(LSP): auto-import via visible reexport (noir-lang/noir#7409)
fix(brillig): Brillig entry point analysis and function specialization through duplication (noir-lang/noir#7277)
chore: redo typo PR by maximevtush (noir-lang/noir#7425)
fix(ssa): Accurately mark binary ops for hoisting and check Div/Mod against induction variable lower bound (noir-lang/noir#7396)
feat!: remove bigint from stdlib (noir-lang/noir#7411)
chore: bump aztec-packages commit (noir-lang/noir#7415)
chore: deprecate `merkle` module of stdlib (noir-lang/noir#7413)
chore(ci): lock aztec-packages commit in CI (noir-lang/noir#7414)
feat: while statement (noir-lang/noir#7280)
TomAFrench added a commit to AztecProtocol/aztec-packages that referenced this pull request Feb 19, 2025
Automated pull of development from the
[noir](https://github.com/noir-lang/noir) programming language, a
dependency of Aztec.
BEGIN_COMMIT_OVERRIDE
fix(performance): Remove redundant slice access check from brillig
(noir-lang/noir#7434)
chore(docs): updating tutorials and other nits to beta.2
(noir-lang/noir#7405)
feat: LSP hover for integer literals
(noir-lang/noir#7368)
feat(experimental): Compile match expressions
(noir-lang/noir#7312)
feat(acir_field): Add little-endian byte serialization for FieldElement
(noir-lang/noir#7258)
feat: allow unquoting TraitConstraint in trait impl position
(noir-lang/noir#7395)
feat(brillig): Hoist shared constants across functions to the global
space (noir-lang/noir#7216)
feat(LSP): auto-import via visible reexport
(noir-lang/noir#7409)
fix(brillig): Brillig entry point analysis and function specialization
through duplication (noir-lang/noir#7277)
chore: redo typo PR by maximevtush
(noir-lang/noir#7425)
fix(ssa): Accurately mark binary ops for hoisting and check Div/Mod
against induction variable lower bound
(noir-lang/noir#7396)
feat!: remove bigint from stdlib
(noir-lang/noir#7411)
chore: bump aztec-packages commit
(noir-lang/noir#7415)
chore: deprecate `merkle` module of stdlib
(noir-lang/noir#7413)
chore(ci): lock aztec-packages commit in CI
(noir-lang/noir#7414)
feat: while statement (noir-lang/noir#7280)
END_COMMIT_OVERRIDE

---------

Co-authored-by: Tom French <tom@tomfren.ch>
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