Fix edge case in expand_root_of_unity #375
Merged
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.
Valgrind pointed out usage of an uninitialized value in our tests. Since this is part of the trusted setup initialization, I expect this would never happen, but good to fix nevertheless.
In the following test, we provide the wrong root of unity, which causes the loop in
expand_root_of_unity
to break early. Here, the width is 256 but the look will break at 128 (because it encountered a value of one).c-kzg-4844/src/test_c_kzg_4844.c
Lines 1719 to 1727 in b2e4149
In
expand_root_of_unity
, if the loop breaks early, the final check will occur on an uninitialized value:c-kzg-4844/src/c_kzg_4844.c
Lines 1563 to 1567 in b2e4149
I also added
CHECK(width >= 2)
as a sanity check and changed the loop to be more "natural" IMO.