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

Add little endian functions to to bits gadget #151

Conversation

nicholas-mainardi
Copy link

@nicholas-mainardi nicholas-mainardi commented Dec 29, 2021

This PR addressed the issue #148 by adding the functions to_bits_le and from_bits_le to the ToBitsGadget and FromBitsGadget, respectively. These functions allow to serialize/deserialize for the types implementing such gadgets to/from a little-endian bit representation. A default implementation is provided that relies on the functions to_bits and from_bits, which serializes/deserializes the type to/from a big endian bit representation.
Similalry, this PR adds the functions write_bits_le and read_bits_le functions to the ToBits and FromBits traits, respectively, in the algebra package, with default implementations relying on the write_bits and read_bits functions, respectively.
The function to_bits_strict_le is also added to the ToBitsGadget to check the validity of the little-endian bit representation of the serialized type. The default implementation simply reverse a valid big-endian bit representation obtained by callid the to_bits_strict function of ToBitsGadget.

Unit tests in r1cs/gadgets/std/src/fields/mod.rs, which verify the correctness of serialization/deserialization of field gadgets to/from big endian bit representation, are enriched to also test serialization/deserialization to/from little endian bit representation.

@nicholas-mainardi nicholas-mainardi changed the base branch from master to refactor_ginger_monorepo December 29, 2021 19:04
algebra/src/bits.rs Outdated Show resolved Hide resolved
r1cs/gadgets/std/src/bits/mod.rs Outdated Show resolved Hide resolved
r1cs/gadgets/std/src/fields/mod.rs Outdated Show resolved Hide resolved
@DanieleDiBenedetto DanieleDiBenedetto linked an issue Jan 13, 2022 that may be closed by this pull request
@DanieleDiBenedetto DanieleDiBenedetto marked this pull request as ready for review February 10, 2022 14:45
@DanieleDiBenedetto DanieleDiBenedetto changed the base branch from refactor_ginger_monorepo to rc/feat/comp_gadget May 2, 2022 09:30
@DanieleDiBenedetto DanieleDiBenedetto changed the base branch from rc/feat/comp_gadget to refactor_ginger_monorepo May 2, 2022 09:31
@DanieleDiBenedetto DanieleDiBenedetto force-pushed the add-little-endian-functions-to-ToBits-gadget branch from 93a929c to 1984dc3 Compare May 2, 2022 09:55
@DanieleDiBenedetto DanieleDiBenedetto changed the base branch from refactor_ginger_monorepo to rc/feat/comp_gadget May 2, 2022 09:56
@nicholas-mainardi nicholas-mainardi force-pushed the add-little-endian-functions-to-ToBits-gadget branch from 25d50da to ce8ee6d Compare May 4, 2022 09:32
@DanieleDiBenedetto DanieleDiBenedetto changed the base branch from rc/feat/comp_gadget to fix-cmp-with-eq-implementation May 5, 2022 11:20
@DanieleDiBenedetto DanieleDiBenedetto changed the base branch from fix-cmp-with-eq-implementation to rc/feat/comp_gadget May 5, 2022 11:24
@nicholas-mainardi nicholas-mainardi changed the base branch from rc/feat/comp_gadget to fix-cmp-with-eq-implementation May 9, 2022 17:11
@nicholas-mainardi nicholas-mainardi changed the base branch from fix-cmp-with-eq-implementation to rc/feat/comp_gadget May 9, 2022 17:21
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.

Uniform endianness of bits/bytes serialization
2 participants