mirror of
https://github.com/status-im/c-kzg-4844.git
synced 2025-01-09 17:55:47 +00:00
Apply formatting rules
This commit is contained in:
parent
9085893ef7
commit
80c513f653
1
.gitignore
vendored
1
.gitignore
vendored
@ -7,3 +7,4 @@ inc/blst.h
|
|||||||
inc/blst_aux.h
|
inc/blst_aux.h
|
||||||
.vscode/
|
.vscode/
|
||||||
*.json
|
*.json
|
||||||
|
.clang-format
|
||||||
|
@ -19,11 +19,10 @@
|
|||||||
static const blst_fr fr_zero = {0L, 0L, 0L, 0L};
|
static const blst_fr fr_zero = {0L, 0L, 0L, 0L};
|
||||||
|
|
||||||
// This is 1 in Blst's `blst_fr` limb representation. Crazy but true.
|
// This is 1 in Blst's `blst_fr` limb representation. Crazy but true.
|
||||||
static const blst_fr fr_one =
|
static const blst_fr fr_one = {0x00000001fffffffeL, 0x5884b7fa00034802L, 0x998c4fefecbc4ff5L, 0x1824b159acc5056fL};
|
||||||
{0x00000001fffffffeL, 0x5884b7fa00034802L, 0x998c4fefecbc4ff5L, 0x1824b159acc5056fL};
|
|
||||||
|
|
||||||
// The G1 identity/infinity in affine representation
|
// The G1 identity/infinity in affine representation
|
||||||
static const blst_p1_affine identity_g1_affine = {{0L,0L,0L,0L,0L,0L},{0L,0L,0L,0L,0L,0L}};
|
static const blst_p1_affine identity_g1_affine = {{0L, 0L, 0L, 0L, 0L, 0L}, {0L, 0L, 0L, 0L, 0L, 0L}};
|
||||||
|
|
||||||
bool fr_is_zero(const blst_fr *p);
|
bool fr_is_zero(const blst_fr *p);
|
||||||
bool fr_is_one(const blst_fr *p);
|
bool fr_is_one(const blst_fr *p);
|
||||||
|
@ -21,7 +21,9 @@
|
|||||||
// This is -1 (the second root of unity)
|
// This is -1 (the second root of unity)
|
||||||
uint64_t m1[] = {0xffffffff00000000L, 0x53bda402fffe5bfeL, 0x3339d80809a1d805L, 0x73eda753299d7d48L};
|
uint64_t m1[] = {0xffffffff00000000L, 0x53bda402fffe5bfeL, 0x3339d80809a1d805L, 0x73eda753299d7d48L};
|
||||||
|
|
||||||
void title(void) {;}
|
void title(void) {
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
void fr_is_zero_works(void) {
|
void fr_is_zero_works(void) {
|
||||||
blst_fr zero;
|
blst_fr zero;
|
||||||
@ -177,11 +179,10 @@ void pairings_work(void) {
|
|||||||
TEST_CHECK(false == pairings_verify(&g1_3, &g2_3, &g1_5, &g2_5));
|
TEST_CHECK(false == pairings_verify(&g1_3, &g2_3, &g1_5, &g2_5));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_LIST =
|
TEST_LIST = {
|
||||||
{
|
|
||||||
{"BLST_UTIL_TEST", title},
|
{"BLST_UTIL_TEST", title},
|
||||||
{"fr_is_zero_works", fr_is_zero_works },
|
{"fr_is_zero_works", fr_is_zero_works},
|
||||||
{"fr_is_one_works", fr_is_one_works },
|
{"fr_is_one_works", fr_is_one_works},
|
||||||
{"fr_from_uint64_works", fr_from_uint64_works},
|
{"fr_from_uint64_works", fr_from_uint64_works},
|
||||||
{"fr_equal_works", fr_equal_works},
|
{"fr_equal_works", fr_equal_works},
|
||||||
{"fr_negate_works", fr_negate_works},
|
{"fr_negate_works", fr_negate_works},
|
||||||
@ -193,5 +194,5 @@ TEST_LIST =
|
|||||||
{"identity_g1_is_infinity", identity_g1_is_infinity},
|
{"identity_g1_is_infinity", identity_g1_is_infinity},
|
||||||
{"g1_linear_combination", g1_linear_combination},
|
{"g1_linear_combination", g1_linear_combination},
|
||||||
{"pairings_work", pairings_work},
|
{"pairings_work", pairings_work},
|
||||||
{ NULL, NULL } /* zero record marks the end of the list */
|
{NULL, NULL} /* zero record marks the end of the list */
|
||||||
};
|
};
|
||||||
|
@ -30,13 +30,14 @@ typedef enum {
|
|||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#define ASSERT(cond, ret) if (!(cond)) \
|
#define ASSERT(cond, ret) \
|
||||||
{ \
|
if (!(cond)) { \
|
||||||
printf("\n%s:%d: Failed ASSERT: %s\n", __FILE__, __LINE__, #cond); \
|
printf("\n%s:%d: Failed ASSERT: %s\n", __FILE__, __LINE__, #cond); \
|
||||||
abort(); \
|
abort(); \
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#define ASSERT(cond, ret) if (!(cond)) return (ret)
|
#define ASSERT(cond, ret) \
|
||||||
|
if (!(cond)) return (ret)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -18,7 +18,9 @@
|
|||||||
#include "debug_util.h"
|
#include "debug_util.h"
|
||||||
#include "c_kzg_util.h"
|
#include "c_kzg_util.h"
|
||||||
|
|
||||||
void title(void) {;}
|
void title(void) {
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
void malloc_works(void) {
|
void malloc_works(void) {
|
||||||
int *p;
|
int *p;
|
||||||
@ -30,10 +32,9 @@ void malloc_huge_fails(void) {
|
|||||||
TEST_CHECK(C_KZG_MALLOC == c_kzg_malloc((void **)&p, -1));
|
TEST_CHECK(C_KZG_MALLOC == c_kzg_malloc((void **)&p, -1));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_LIST =
|
TEST_LIST = {
|
||||||
{
|
|
||||||
{"C_KZG_UTIL_TEST", title},
|
{"C_KZG_UTIL_TEST", title},
|
||||||
{"malloc_works", malloc_works},
|
{"malloc_works", malloc_works},
|
||||||
{"malloc_huge_fails", malloc_huge_fails},
|
{"malloc_huge_fails", malloc_huge_fails},
|
||||||
{ NULL, NULL } /* zero record marks the end of the list */
|
{NULL, NULL} /* zero record marks the end of the list */
|
||||||
};
|
};
|
||||||
|
@ -50,8 +50,7 @@ void print_fr(const blst_fr *a) {
|
|||||||
//
|
//
|
||||||
|
|
||||||
void print_limbs(const blst_fp *fp) {
|
void print_limbs(const blst_fp *fp) {
|
||||||
printf("(%08lx, %08lx, %08lx, %08lx, %08lx, %08lx)",
|
printf("(%08lx, %08lx, %08lx, %08lx, %08lx, %08lx)", fp->l[0], fp->l[1], fp->l[2], fp->l[3], fp->l[4], fp->l[5]);
|
||||||
fp->l[0], fp->l[1], fp->l[2], fp->l[3], fp->l[4], fp->l[5]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -53,8 +53,10 @@ C_KZG_RET new_fft_settings(FFTSettings *fs, const unsigned int max_scale) {
|
|||||||
fs->max_width = (uint64_t)1 << max_scale;
|
fs->max_width = (uint64_t)1 << max_scale;
|
||||||
blst_fr_from_uint64(&fs->root_of_unity, scale2_root_of_unity[max_scale]);
|
blst_fr_from_uint64(&fs->root_of_unity, scale2_root_of_unity[max_scale]);
|
||||||
|
|
||||||
ASSERT(c_kzg_malloc((void **)&fs->expanded_roots_of_unity, (fs->max_width + 1) * sizeof(blst_fr)) == C_KZG_OK, C_KZG_MALLOC);
|
ASSERT(c_kzg_malloc((void **)&fs->expanded_roots_of_unity, (fs->max_width + 1) * sizeof(blst_fr)) == C_KZG_OK,
|
||||||
ASSERT(c_kzg_malloc((void **)&fs->reverse_roots_of_unity, (fs->max_width + 1) * sizeof(blst_fr)) == C_KZG_OK, C_KZG_MALLOC);
|
C_KZG_MALLOC);
|
||||||
|
ASSERT(c_kzg_malloc((void **)&fs->reverse_roots_of_unity, (fs->max_width + 1) * sizeof(blst_fr)) == C_KZG_OK,
|
||||||
|
C_KZG_MALLOC);
|
||||||
|
|
||||||
ret = expand_root_of_unity(fs->expanded_roots_of_unity, &fs->root_of_unity, fs->max_width);
|
ret = expand_root_of_unity(fs->expanded_roots_of_unity, &fs->root_of_unity, fs->max_width);
|
||||||
if (ret != C_KZG_OK) return ret;
|
if (ret != C_KZG_OK) return ret;
|
||||||
|
@ -21,8 +21,7 @@
|
|||||||
// [pow(PRIMITIVE_ROOT, (MODULUS - 1) // (2**i), MODULUS) for i in range(32)]
|
// [pow(PRIMITIVE_ROOT, (MODULUS - 1) // (2**i), MODULUS) for i in range(32)]
|
||||||
//
|
//
|
||||||
// These are not in `blst_fr` limb format and must be converted via `blst_fr_from_uint64()`
|
// These are not in `blst_fr` limb format and must be converted via `blst_fr_from_uint64()`
|
||||||
static const uint64_t scale2_root_of_unity[][4] =
|
static const uint64_t scale2_root_of_unity[][4] = {
|
||||||
{
|
|
||||||
{0x0000000000000001L, 0x0000000000000000L, 0x0000000000000000L, 0x0000000000000000L},
|
{0x0000000000000001L, 0x0000000000000000L, 0x0000000000000000L, 0x0000000000000000L},
|
||||||
{0xffffffff00000000L, 0x53bda402fffe5bfeL, 0x3339d80809a1d805L, 0x73eda753299d7d48L},
|
{0xffffffff00000000L, 0x53bda402fffe5bfeL, 0x3339d80809a1d805L, 0x73eda753299d7d48L},
|
||||||
{0x0001000000000000L, 0xec03000276030000L, 0x8d51ccce760304d0L, 0x0000000000000000L},
|
{0x0001000000000000L, 0xec03000276030000L, 0x8d51ccce760304d0L, 0x0000000000000000L},
|
||||||
@ -54,8 +53,7 @@ static const uint64_t scale2_root_of_unity[][4] =
|
|||||||
{0xaba2f51842f2a254L, 0x4d7f3c3aa71efc0cL, 0x97ae418dd274a80aL, 0x2967385d5e3e7682L},
|
{0xaba2f51842f2a254L, 0x4d7f3c3aa71efc0cL, 0x97ae418dd274a80aL, 0x2967385d5e3e7682L},
|
||||||
{0x75c55c7b575a0b79L, 0x3ba4a15774a7ded1L, 0xc3974d73a04fccf3L, 0x705aba4f4a939684L},
|
{0x75c55c7b575a0b79L, 0x3ba4a15774a7ded1L, 0xc3974d73a04fccf3L, 0x705aba4f4a939684L},
|
||||||
{0x8409a9ea14ebb608L, 0xfad0084e66bac611L, 0x04287254811c1dfbL, 0x086d072b23b30c29L},
|
{0x8409a9ea14ebb608L, 0xfad0084e66bac611L, 0x04287254811c1dfbL, 0x086d072b23b30c29L},
|
||||||
{0xb427c9b367e4756aL, 0xc7537fb902ebc38dL, 0x51de21becd6a205fL, 0x6064ab727923597dL}
|
{0xb427c9b367e4756aL, 0xc7537fb902ebc38dL, 0x51de21becd6a205fL, 0x6064ab727923597dL}};
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint64_t max_width;
|
uint64_t max_width;
|
||||||
@ -65,7 +63,7 @@ typedef struct {
|
|||||||
} FFTSettings;
|
} FFTSettings;
|
||||||
|
|
||||||
bool is_power_of_two(const uint64_t n);
|
bool is_power_of_two(const uint64_t n);
|
||||||
C_KZG_RET expand_root_of_unity(blst_fr * roots, const blst_fr *root_of_unity, const uint64_t width);
|
C_KZG_RET expand_root_of_unity(blst_fr *roots, const blst_fr *root_of_unity, const uint64_t width);
|
||||||
C_KZG_RET reverse(blst_fr *out, const blst_fr *roots, const uint64_t width);
|
C_KZG_RET reverse(blst_fr *out, const blst_fr *roots, const uint64_t width);
|
||||||
C_KZG_RET new_fft_settings(FFTSettings *s, const unsigned int max_scale);
|
C_KZG_RET new_fft_settings(FFTSettings *s, const unsigned int max_scale);
|
||||||
void free_fft_settings(FFTSettings *s);
|
void free_fft_settings(FFTSettings *s);
|
||||||
|
@ -21,11 +21,12 @@
|
|||||||
|
|
||||||
#define NUM_ROOTS 32
|
#define NUM_ROOTS 32
|
||||||
|
|
||||||
void title(void) {;}
|
void title(void) {
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
void roots_of_unity_is_the_expected_size(void) {
|
void roots_of_unity_is_the_expected_size(void) {
|
||||||
TEST_CHECK(NUM_ROOTS ==
|
TEST_CHECK(NUM_ROOTS == sizeof(scale2_root_of_unity) / sizeof(scale2_root_of_unity[0]));
|
||||||
sizeof(scale2_root_of_unity) / sizeof(scale2_root_of_unity[0]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void roots_of_unity_are_plausible(void) {
|
void roots_of_unity_are_plausible(void) {
|
||||||
@ -101,7 +102,7 @@ void new_fft_settings_is_plausible(void) {
|
|||||||
|
|
||||||
void is_power_of_two_works(void) {
|
void is_power_of_two_works(void) {
|
||||||
// All actual powers of two
|
// All actual powers of two
|
||||||
for (int i = 0; i <=63; i++) {
|
for (int i = 0; i <= 63; i++) {
|
||||||
TEST_CHECK(true == is_power_of_two((uint64_t)1 << i));
|
TEST_CHECK(true == is_power_of_two((uint64_t)1 << i));
|
||||||
TEST_MSG("Case %d", i);
|
TEST_MSG("Case %d", i);
|
||||||
}
|
}
|
||||||
@ -114,8 +115,7 @@ void is_power_of_two_works(void) {
|
|||||||
TEST_CHECK(false == is_power_of_two(1234567));
|
TEST_CHECK(false == is_power_of_two(1234567));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_LIST =
|
TEST_LIST = {
|
||||||
{
|
|
||||||
{"FFT_COMMON_TEST", title},
|
{"FFT_COMMON_TEST", title},
|
||||||
{"roots_of_unity_is_the_expected_size", roots_of_unity_is_the_expected_size},
|
{"roots_of_unity_is_the_expected_size", roots_of_unity_is_the_expected_size},
|
||||||
{"roots_of_unity_are_plausible", roots_of_unity_are_plausible},
|
{"roots_of_unity_are_plausible", roots_of_unity_are_plausible},
|
||||||
@ -123,5 +123,5 @@ TEST_LIST =
|
|||||||
{"expand_roots_is_plausible", expand_roots_is_plausible},
|
{"expand_roots_is_plausible", expand_roots_is_plausible},
|
||||||
{"new_fft_settings_is_plausible", new_fft_settings_is_plausible},
|
{"new_fft_settings_is_plausible", new_fft_settings_is_plausible},
|
||||||
{"is_power_of_two_works", is_power_of_two_works},
|
{"is_power_of_two_works", is_power_of_two_works},
|
||||||
{ NULL, NULL } /* zero record marks the end of the list */
|
{NULL, NULL} /* zero record marks the end of the list */
|
||||||
};
|
};
|
||||||
|
@ -18,7 +18,8 @@
|
|||||||
#include "blst_util.h"
|
#include "blst_util.h"
|
||||||
|
|
||||||
// Slow Fourier Transform (simple, good for small sizes)
|
// Slow Fourier Transform (simple, good for small sizes)
|
||||||
void fft_fr_slow(blst_fr *out, const blst_fr *in, uint64_t stride, const blst_fr *roots, uint64_t roots_stride, uint64_t l) {
|
void fft_fr_slow(blst_fr *out, const blst_fr *in, uint64_t stride, const blst_fr *roots, uint64_t roots_stride,
|
||||||
|
uint64_t l) {
|
||||||
blst_fr v, last, jv, r;
|
blst_fr v, last, jv, r;
|
||||||
for (uint64_t i = 0; i < l; i++) {
|
for (uint64_t i = 0; i < l; i++) {
|
||||||
blst_fr_mul(&last, &in[0], &roots[0]);
|
blst_fr_mul(&last, &in[0], &roots[0]);
|
||||||
@ -33,7 +34,8 @@ void fft_fr_slow(blst_fr *out, const blst_fr *in, uint64_t stride, const blst_fr
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fast Fourier Transform
|
// Fast Fourier Transform
|
||||||
void fft_fr_fast(blst_fr *out, const blst_fr *in, uint64_t stride, const blst_fr *roots, uint64_t roots_stride, uint64_t l) {
|
void fft_fr_fast(blst_fr *out, const blst_fr *in, uint64_t stride, const blst_fr *roots, uint64_t roots_stride,
|
||||||
|
uint64_t l) {
|
||||||
uint64_t half = l / 2;
|
uint64_t half = l / 2;
|
||||||
if (half > 2) { // TODO: Tunable parameter
|
if (half > 2) { // TODO: Tunable parameter
|
||||||
fft_fr_fast(out, in, stride * 2, roots, roots_stride * 2, half);
|
fft_fr_fast(out, in, stride * 2, roots, roots_stride * 2, half);
|
||||||
@ -50,7 +52,7 @@ void fft_fr_fast(blst_fr *out, const blst_fr *in, uint64_t stride, const blst_fr
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The main entry point for forward and reverse FFTs
|
// The main entry point for forward and reverse FFTs
|
||||||
C_KZG_RET fft_fr (blst_fr *out, const blst_fr *in, const FFTSettings *fs, bool inv, uint64_t n) {
|
C_KZG_RET fft_fr(blst_fr *out, const blst_fr *in, const FFTSettings *fs, bool inv, uint64_t n) {
|
||||||
uint64_t stride = fs->max_width / n;
|
uint64_t stride = fs->max_width / n;
|
||||||
ASSERT(n <= fs->max_width, C_KZG_BADARGS);
|
ASSERT(n <= fs->max_width, C_KZG_BADARGS);
|
||||||
ASSERT(is_power_of_two(n), C_KZG_BADARGS);
|
ASSERT(is_power_of_two(n), C_KZG_BADARGS);
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
#include "c_kzg.h"
|
#include "c_kzg.h"
|
||||||
#include "fft_common.h"
|
#include "fft_common.h"
|
||||||
|
|
||||||
void fft_fr_slow(blst_fr *out, const blst_fr *in, uint64_t stride, const blst_fr *roots, uint64_t roots_stride, uint64_t l);
|
void fft_fr_slow(blst_fr *out, const blst_fr *in, uint64_t stride, const blst_fr *roots, uint64_t roots_stride,
|
||||||
void fft_fr_fast(blst_fr *out, const blst_fr *in, uint64_t stride, const blst_fr *roots, uint64_t roots_stride, uint64_t l);
|
uint64_t l);
|
||||||
C_KZG_RET fft_fr (blst_fr *out, const blst_fr *in, const FFTSettings *fs, bool inv, uint64_t n);
|
void fft_fr_fast(blst_fr *out, const blst_fr *in, uint64_t stride, const blst_fr *roots, uint64_t roots_stride,
|
||||||
|
uint64_t l);
|
||||||
|
C_KZG_RET fft_fr(blst_fr *out, const blst_fr *in, const FFTSettings *fs, bool inv, uint64_t n);
|
||||||
|
@ -19,8 +19,7 @@
|
|||||||
#include "fft_fr.h"
|
#include "fft_fr.h"
|
||||||
#include "blst_util.h"
|
#include "blst_util.h"
|
||||||
|
|
||||||
const uint64_t inv_fft_expected[][4] =
|
const uint64_t inv_fft_expected[][4] = {
|
||||||
{
|
|
||||||
{0x7fffffff80000008L, 0xa9ded2017fff2dffL, 0x199cec0404d0ec02L, 0x39f6d3a994cebea4L},
|
{0x7fffffff80000008L, 0xa9ded2017fff2dffL, 0x199cec0404d0ec02L, 0x39f6d3a994cebea4L},
|
||||||
{0x27325dd08ac4cee9L, 0xcbb94f168ddacca9L, 0x6843be68485784b1L, 0x5a6faf9039451673L},
|
{0x27325dd08ac4cee9L, 0xcbb94f168ddacca9L, 0x6843be68485784b1L, 0x5a6faf9039451673L},
|
||||||
{0x16d00224dcf9382cL, 0xfee079062d1eaa93L, 0x3ce49204a2235046L, 0x163147176461030eL},
|
{0x16d00224dcf9382cL, 0xfee079062d1eaa93L, 0x3ce49204a2235046L, 0x163147176461030eL},
|
||||||
@ -36,10 +35,11 @@ const uint64_t inv_fft_expected[][4] =
|
|||||||
{0x7fff7fff80000000L, 0x33dd520044fdadffL, 0xd2f4059cc9cf699aL, 0x39f6d3a994cebea3L},
|
{0x7fff7fff80000000L, 0x33dd520044fdadffL, 0xd2f4059cc9cf699aL, 0x39f6d3a994cebea3L},
|
||||||
{0xef296e7ffb8ca216L, 0xd5b902cbcef9c1b6L, 0xf06dfe5c7fca260dL, 0x13993b7d05187205L},
|
{0xef296e7ffb8ca216L, 0xd5b902cbcef9c1b6L, 0xf06dfe5c7fca260dL, 0x13993b7d05187205L},
|
||||||
{0xe92ffdda2306c7d4L, 0x54dd2afcd2dfb16bL, 0xf6554603677e87beL, 0x5dbc603bc53c7a39L},
|
{0xe92ffdda2306c7d4L, 0x54dd2afcd2dfb16bL, 0xf6554603677e87beL, 0x5dbc603bc53c7a39L},
|
||||||
{0xd8cda22e753b3117L, 0x880454ec72238f55L, 0xcaf6199fc14a5353L, 0x197df7c2f05866d4L}
|
{0xd8cda22e753b3117L, 0x880454ec72238f55L, 0xcaf6199fc14a5353L, 0x197df7c2f05866d4L}};
|
||||||
};
|
|
||||||
|
|
||||||
void title(void) {;}
|
void title(void) {
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
void compare_sft_fft(void) {
|
void compare_sft_fft(void) {
|
||||||
// Initialise: ascending values of i (could be anything), and arbitrary size
|
// Initialise: ascending values of i (could be anything), and arbitrary size
|
||||||
@ -111,11 +111,10 @@ void inverse_fft(void) {
|
|||||||
free_fft_settings(&fs);
|
free_fft_settings(&fs);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_LIST =
|
TEST_LIST = {
|
||||||
{
|
|
||||||
{"FFT_FR_TEST", title},
|
{"FFT_FR_TEST", title},
|
||||||
{"compare_sft_fft", compare_sft_fft},
|
{"compare_sft_fft", compare_sft_fft},
|
||||||
{"roundtrip_fft", roundtrip_fft},
|
{"roundtrip_fft", roundtrip_fft},
|
||||||
{"inverse_fft", inverse_fft},
|
{"inverse_fft", inverse_fft},
|
||||||
{ NULL, NULL } /* zero record marks the end of the list */
|
{NULL, NULL} /* zero record marks the end of the list */
|
||||||
};
|
};
|
||||||
|
@ -51,7 +51,7 @@ void fft_g1_fast(blst_p1 *out, blst_p1 *in, uint64_t stride, blst_fr *roots, uin
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The main entry point for forward and reverse FFTs
|
// The main entry point for forward and reverse FFTs
|
||||||
C_KZG_RET fft_g1 (blst_p1 *out, blst_p1 *in, FFTSettings *fs, bool inv, uint64_t n) {
|
C_KZG_RET fft_g1(blst_p1 *out, blst_p1 *in, FFTSettings *fs, bool inv, uint64_t n) {
|
||||||
uint64_t stride = fs->max_width / n;
|
uint64_t stride = fs->max_width / n;
|
||||||
ASSERT(n <= fs->max_width, C_KZG_BADARGS);
|
ASSERT(n <= fs->max_width, C_KZG_BADARGS);
|
||||||
ASSERT(is_power_of_two(n), C_KZG_BADARGS);
|
ASSERT(is_power_of_two(n), C_KZG_BADARGS);
|
||||||
|
@ -19,4 +19,4 @@
|
|||||||
|
|
||||||
void fft_g1_slow(blst_p1 *out, blst_p1 *in, uint64_t stride, blst_fr *roots, uint64_t roots_stride, uint64_t l);
|
void fft_g1_slow(blst_p1 *out, blst_p1 *in, uint64_t stride, blst_fr *roots, uint64_t roots_stride, uint64_t l);
|
||||||
void fft_g1_fast(blst_p1 *out, blst_p1 *in, uint64_t stride, blst_fr *roots, uint64_t roots_stride, uint64_t l);
|
void fft_g1_fast(blst_p1 *out, blst_p1 *in, uint64_t stride, blst_fr *roots, uint64_t roots_stride, uint64_t l);
|
||||||
C_KZG_RET fft_g1 (blst_p1 *out, blst_p1 *in, FFTSettings *fs, bool inv, uint64_t n);
|
C_KZG_RET fft_g1(blst_p1 *out, blst_p1 *in, FFTSettings *fs, bool inv, uint64_t n);
|
||||||
|
@ -18,7 +18,9 @@
|
|||||||
#include "debug_util.h"
|
#include "debug_util.h"
|
||||||
#include "fft_g1.h"
|
#include "fft_g1.h"
|
||||||
|
|
||||||
void title(void) {;}
|
void title(void) {
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
void make_data(blst_p1 *out, uint64_t n) {
|
void make_data(blst_p1 *out, uint64_t n) {
|
||||||
// Multiples of g1_gen
|
// Multiples of g1_gen
|
||||||
@ -70,10 +72,9 @@ void roundtrip_fft(void) {
|
|||||||
free_fft_settings(&fs);
|
free_fft_settings(&fs);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_LIST =
|
TEST_LIST = {
|
||||||
{
|
|
||||||
{"FFT_G1_TEST", title},
|
{"FFT_G1_TEST", title},
|
||||||
{"compare_sft_fft", compare_sft_fft},
|
{"compare_sft_fft", compare_sft_fft},
|
||||||
{"roundtrip_fft", roundtrip_fft},
|
{"roundtrip_fft", roundtrip_fft},
|
||||||
{ NULL, NULL } /* zero record marks the end of the list */
|
{NULL, NULL} /* zero record marks the end of the list */
|
||||||
};
|
};
|
||||||
|
@ -36,7 +36,8 @@ C_KZG_RET compute_proof_single(blst_p1 *out, const KZGSettings *ks, poly *p, con
|
|||||||
return compute_proof_multi(out, ks, p, x0, 1);
|
return compute_proof_multi(out, ks, p, x0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
C_KZG_RET check_proof_single(bool *out, const KZGSettings *ks, const blst_p1 *commitment, const blst_p1 *proof, const blst_fr *x, blst_fr *y) {
|
C_KZG_RET check_proof_single(bool *out, const KZGSettings *ks, const blst_p1 *commitment, const blst_p1 *proof,
|
||||||
|
const blst_fr *x, blst_fr *y) {
|
||||||
blst_p2 x_g2, s_minus_x;
|
blst_p2 x_g2, s_minus_x;
|
||||||
blst_p1 y_g1, commitment_minus_y;
|
blst_p1 y_g1, commitment_minus_y;
|
||||||
p2_mul(&x_g2, blst_p2_generator(), x);
|
p2_mul(&x_g2, blst_p2_generator(), x);
|
||||||
@ -84,7 +85,8 @@ C_KZG_RET compute_proof_multi(blst_p1 *out, const KZGSettings *ks, poly *p, cons
|
|||||||
|
|
||||||
// Check a proof for a KZG commitment for an evaluation f(x w^i) = y_i
|
// Check a proof for a KZG commitment for an evaluation f(x w^i) = y_i
|
||||||
// The ys must have a power of 2 length
|
// The ys must have a power of 2 length
|
||||||
C_KZG_RET check_proof_multi(bool *out, const KZGSettings *ks, const blst_p1 *commitment, const blst_p1 *proof, const blst_fr *x, const blst_fr *ys, uint64_t n) {
|
C_KZG_RET check_proof_multi(bool *out, const KZGSettings *ks, const blst_p1 *commitment, const blst_p1 *proof,
|
||||||
|
const blst_fr *x, const blst_fr *ys, uint64_t n) {
|
||||||
poly interp;
|
poly interp;
|
||||||
blst_fr inv_x, inv_x_pow, x_pow;
|
blst_fr inv_x, inv_x_pow, x_pow;
|
||||||
blst_p2 xn2, xn_minus_yn;
|
blst_p2 xn2, xn_minus_yn;
|
||||||
|
@ -29,6 +29,8 @@ typedef struct {
|
|||||||
C_KZG_RET new_kzg_settings(KZGSettings *ks, FFTSettings *fs, blst_p1 *secret_g1, blst_p2 *secret_g2, uint64_t length);
|
C_KZG_RET new_kzg_settings(KZGSettings *ks, FFTSettings *fs, blst_p1 *secret_g1, blst_p2 *secret_g2, uint64_t length);
|
||||||
void commit_to_poly(blst_p1 *out, const KZGSettings *ks, const poly *p);
|
void commit_to_poly(blst_p1 *out, const KZGSettings *ks, const poly *p);
|
||||||
C_KZG_RET compute_proof_single(blst_p1 *out, const KZGSettings *ks, poly *p, const blst_fr *x0);
|
C_KZG_RET compute_proof_single(blst_p1 *out, const KZGSettings *ks, poly *p, const blst_fr *x0);
|
||||||
C_KZG_RET check_proof_single(bool *out, const KZGSettings *ks, const blst_p1 *commitment, const blst_p1 *proof, const blst_fr *x, blst_fr *y);
|
C_KZG_RET check_proof_single(bool *out, const KZGSettings *ks, const blst_p1 *commitment, const blst_p1 *proof,
|
||||||
|
const blst_fr *x, blst_fr *y);
|
||||||
C_KZG_RET compute_proof_multi(blst_p1 *out, const KZGSettings *ks, poly *p, const blst_fr *x0, uint64_t n);
|
C_KZG_RET compute_proof_multi(blst_p1 *out, const KZGSettings *ks, poly *p, const blst_fr *x0, uint64_t n);
|
||||||
C_KZG_RET check_proof_multi(bool *out, const KZGSettings *ks, const blst_p1 *commitment, const blst_p1 *proof, const blst_fr *x, const blst_fr *ys, uint64_t n);
|
C_KZG_RET check_proof_multi(bool *out, const KZGSettings *ks, const blst_p1 *commitment, const blst_p1 *proof,
|
||||||
|
const blst_fr *x, const blst_fr *ys, uint64_t n);
|
||||||
|
@ -19,13 +19,9 @@
|
|||||||
#include "kzg_proofs.h"
|
#include "kzg_proofs.h"
|
||||||
|
|
||||||
// The generator for our "trusted" setup
|
// The generator for our "trusted" setup
|
||||||
blst_scalar secret =
|
blst_scalar secret = {0xa4, 0x73, 0x31, 0x95, 0x28, 0xc8, 0xb6, 0xea, 0x4d, 0x08, 0xcc,
|
||||||
{
|
0x53, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
0xa4, 0x73, 0x31, 0x95, 0x28, 0xc8, 0xb6, 0xea,
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; // Little-endian?
|
||||||
0x4d, 0x08, 0xcc, 0x53, 0x18, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
|
||||||
}; // Little-endian?
|
|
||||||
|
|
||||||
void generate_setup(blst_p1 *s1, blst_p2 *s2, const blst_scalar *secret, const uint64_t n) {
|
void generate_setup(blst_p1 *s1, blst_p2 *s2, const blst_scalar *secret, const uint64_t n) {
|
||||||
blst_fr s_pow, s;
|
blst_fr s_pow, s;
|
||||||
@ -38,7 +34,9 @@ void generate_setup(blst_p1 *s1, blst_p2 *s2, const blst_scalar *secret, const u
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void title(void) {;}
|
void title(void) {
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
void proof_single(void) {
|
void proof_single(void) {
|
||||||
// Our polynomial: degree 15, 16 coefficients
|
// Our polynomial: degree 15, 16 coefficients
|
||||||
@ -172,11 +170,10 @@ void commit_to_nil_poly(void) {
|
|||||||
TEST_CHECK(blst_p1_affine_is_equal(&identity_g1_affine, &result_affine));
|
TEST_CHECK(blst_p1_affine_is_equal(&identity_g1_affine, &result_affine));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_LIST =
|
TEST_LIST = {
|
||||||
{
|
|
||||||
{"KZG_PROOFS_TEST", title},
|
{"KZG_PROOFS_TEST", title},
|
||||||
{"proof_single", proof_single},
|
{"proof_single", proof_single},
|
||||||
{"proof_multi", proof_multi},
|
{"proof_multi", proof_multi},
|
||||||
{"commit_to_nil_poly", commit_to_nil_poly},
|
{"commit_to_nil_poly", commit_to_nil_poly},
|
||||||
{ NULL, NULL } /* zero record marks the end of the list */
|
{NULL, NULL} /* zero record marks the end of the list */
|
||||||
};
|
};
|
||||||
|
@ -18,7 +18,9 @@
|
|||||||
#include "debug_util.h"
|
#include "debug_util.h"
|
||||||
#include "poly.h"
|
#include "poly.h"
|
||||||
|
|
||||||
void title(void) {;}
|
void title(void) {
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
void poly_div_length(void) {
|
void poly_div_length(void) {
|
||||||
poly a, b;
|
poly a, b;
|
||||||
@ -190,8 +192,7 @@ void poly_eval_nil_check(void) {
|
|||||||
free_poly(&p);
|
free_poly(&p);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_LIST =
|
TEST_LIST = {
|
||||||
{
|
|
||||||
{"POLY_TEST", title},
|
{"POLY_TEST", title},
|
||||||
{"poly_div_length", poly_div_length},
|
{"poly_div_length", poly_div_length},
|
||||||
{"poly_div_0", poly_div_0},
|
{"poly_div_0", poly_div_0},
|
||||||
@ -201,5 +202,5 @@ TEST_LIST =
|
|||||||
{"poly_eval_check", poly_eval_check},
|
{"poly_eval_check", poly_eval_check},
|
||||||
{"poly_eval_0_check", poly_eval_0_check},
|
{"poly_eval_0_check", poly_eval_0_check},
|
||||||
{"poly_eval_nil_check", poly_eval_nil_check},
|
{"poly_eval_nil_check", poly_eval_nil_check},
|
||||||
{ NULL, NULL } /* zero record marks the end of the list */
|
{NULL, NULL} /* zero record marks the end of the list */
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user