scipr-lab / libff

C++ library for Finite Fields and Elliptic Curves
Other
149 stars 82 forks source link

Investigate potential off by one issue in pack_bit_vector_into_field_element_vector #107

Open ValarDragon opened 2 years ago

ValarDragon commented 2 years ago

pack_bit_vector_into_field_element_vector everywhere uses fieldT::floor_size_in_bits(), but it seems like it should be using capacity/ceil_size_in_bits().

(This got changed from capacity in #103, however that was a non-breaking change, and actually just reflected what the old field API did)

Jun-Hee-Lee commented 1 year ago

@ValarDragon, I also thought this was an error and checked it. However, div_ceil is called inside the function. Therefore, The repacked_size seems to be calculated safely.

When "vector bit size" and "field bit size" are the same, and the "vector value" is greater than the "field size", I think ceil_size_in_bits() is not sufficient.

Am I misunderstanding?