Skip to content

Commit

Permalink
Revert changes to fr_batch_inv & bytes_from_uint64
Browse files Browse the repository at this point in the history
  • Loading branch information
jtraglia committed Sep 17, 2024
1 parent 37eea2c commit 116ba8f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/common/bytes.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
* @remark The output format is big-endian.
*/
void bytes_from_uint64(uint8_t out[8], uint64_t n) {
for (size_t i = 0; i < 8; i++) {
out[7 - i] = n & 0xFF;
for (int i = 7; i >= 0; i--) {
out[i] = n & 0xFF;
n >>= 8;
}
}
Expand Down
14 changes: 8 additions & 6 deletions src/eip4844/eip4844.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,20 @@ static bool fr_is_zero(const fr_t *p) {
* @param[in] a A vector of field elements, length `len`
* @param[in] len The number of field elements
*
* @remark This function only supports len > 0.
* @remark This function does NOT support in-place computation.
* @remark Return C_KZG_BADARGS if a zero is found in the input. In this case,
* the `out` output array has already been mutated.
*/
static C_KZG_RET fr_batch_inv(fr_t *out, const fr_t *a, size_t len) {
static C_KZG_RET fr_batch_inv(fr_t *out, const fr_t *a, int len) {
int i;

assert(len > 0);
assert(a != out);

fr_t accumulator = FR_ONE;

for (size_t i = 0; i < len; i++) {
for (i = 0; i < len; i++) {
out[i] = accumulator;
blst_fr_mul(&accumulator, &accumulator, &a[i]);
}
Expand All @@ -103,10 +106,9 @@ static C_KZG_RET fr_batch_inv(fr_t *out, const fr_t *a, size_t len) {

blst_fr_eucl_inverse(&accumulator, &accumulator);

for (size_t i = len; i > 0; i--) {
size_t index = i - 1;
blst_fr_mul(&out[index], &out[index], &accumulator);
blst_fr_mul(&accumulator, &accumulator, &a[index]);
for (i = len - 1; i >= 0; i--) {
blst_fr_mul(&out[i], &out[i], &accumulator);
blst_fr_mul(&accumulator, &accumulator, &a[i]);
}

return C_KZG_OK;
Expand Down

0 comments on commit 116ba8f

Please sign in to comment.