Fix edge case in expand_root_of_unity (#375)

This commit is contained in:
Justin Traglia 2023-10-10 09:07:44 -05:00 committed by GitHub
parent 456c3d8fab
commit f3fffecd1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 2 deletions

View File

@ -1557,13 +1557,16 @@ static C_KZG_RET bit_reversal_permutation(
static C_KZG_RET expand_root_of_unity(
fr_t *out, const fr_t *root, uint64_t width
) {
uint64_t i;
CHECK(width >= 2);
out[0] = FR_ONE;
out[1] = *root;
for (uint64_t i = 2; !fr_is_one(&out[i - 1]); i++) {
CHECK(i <= width);
for (i = 2; i <= width; i++) {
blst_fr_mul(&out[i], &out[i - 1], root);
if (fr_is_one(&out[i])) break;
}
CHECK(i == width);
CHECK(fr_is_one(&out[width]));
return C_KZG_OK;