Closed jtraglia closed 1 year ago
Can we just add the check CHECK(i == width);
without changing the loop logic?
I feel like this is a non-trivial loop logic and the less we change it the better.
IIRC you'd have to compare i to width - 1. It's not as pretty. I think this way is safer.
Even though, it changes the loop logic, I think the latter is a lot easier to understand (like you can know the maximum number of iterations immediately)
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).https://github.com/ethereum/c-kzg-4844/blob/b2e41491ad1859f1792964a2432a419b64dc6fb2/src/test_c_kzg_4844.c#L1719-L1727
In
expand_root_of_unity
, if the loop breaks early, the final check will occur on an uninitialized value:https://github.com/ethereum/c-kzg-4844/blob/b2e41491ad1859f1792964a2432a419b64dc6fb2/src/c_kzg_4844.c#L1563-L1567
I also added
CHECK(width >= 2)
as a sanity check and changed the loop to be more "natural" IMO.