kroma-network / tachyon

Modular ZK(Zero Knowledge) backend accelerated by GPU
MIT License
7.78k stars 226 forks source link

refac: fix zero case for inverse and div #424

Closed ashjeong closed 1 month ago

ashjeong commented 2 months ago

Background: Functions with constexpr and __device__ signal the use of the function on the GPU side. Since CHECK() is not GPU-interoperable, this function should not be used in any function on the GPU side.

Inverse: Originally the special edge case of the inverse of 0 was to be checked in the innermost inverse functions using CHECK(), yet this was not possible due to the reasoning above. To accommodate this possible error, a mixture of bool returns with output parameters and std::optional returns was adopted such that the upper hierarchical calls of inverse functions (aka in tests and non-(constexpr/__device__) functions) must check the outcome of the inverse and kill the program if the return is invalid.

Div: Div functions follow the same changes as dictated for the inverse functions above with regards to the divide by 0 edge case.

This PR should be merged after #422

Resolves #76