ginger-lib icon indicating copy to clipboard operation
ginger-lib copied to clipboard

Add little endian functions to to bits gadget

Open nicholas-mainardi opened this issue 4 years ago • 0 comments

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 avatar Dec 29 '21 19:12 nicholas-mainardi