Remove 4844 version from src (use min-src)
This commit is contained in:
parent
fe4dfcc0eb
commit
b284636afd
10
src/Makefile
10
src/Makefile
|
@ -1,26 +1,21 @@
|
||||||
TESTS = bls12_381_test das_extension_test c_kzg_alloc_test fft_common_test fft_fr_test fft_g1_test \
|
TESTS = bls12_381_test das_extension_test c_kzg_alloc_test fft_common_test fft_fr_test fft_g1_test \
|
||||||
fk20_proofs_test kzg_proofs_test poly_test recover_test utility_test zero_poly_test c_kzg_4844_test
|
fk20_proofs_test kzg_proofs_test poly_test recover_test utility_test zero_poly_test
|
||||||
BENCH = fft_fr_bench fft_g1_bench recover_bench zero_poly_bench kzg_proofs_bench poly_bench poly_barycentric_bench compute_proof_lagrange_bench
|
BENCH = fft_fr_bench fft_g1_bench recover_bench zero_poly_bench kzg_proofs_bench poly_bench poly_barycentric_bench compute_proof_lagrange_bench
|
||||||
TUNE = poly_mul_tune poly_div_tune
|
TUNE = poly_mul_tune poly_div_tune
|
||||||
LIB_SRC = bls12_381.c c_kzg_alloc.c das_extension.c fft_common.c fft_fr.c fft_g1.c fk20_proofs.c kzg_proofs.c poly.c recover.c utility.c zero_poly.c
|
LIB_SRC = bls12_381.c c_kzg_alloc.c das_extension.c fft_common.c fft_fr.c fft_g1.c fk20_proofs.c kzg_proofs.c poly.c recover.c utility.c zero_poly.c
|
||||||
LIB_OBJ = $(LIB_SRC:.c=.o)
|
LIB_OBJ = $(LIB_SRC:.c=.o)
|
||||||
LIB_4844_SRC = c_kzg_4844.c kzg_proofs.c
|
|
||||||
LIB_4844_OBJ = $(LIB_4844_SRC:.c=.o)
|
|
||||||
|
|
||||||
KZG_CFLAGS =
|
KZG_CFLAGS =
|
||||||
INCLUDE_DIRS = ../inc
|
INCLUDE_DIRS = ../inc
|
||||||
|
|
||||||
.PRECIOUS: %.o
|
.PRECIOUS: %.o
|
||||||
|
|
||||||
%.o: %.c c_kzg_4844.h c_kzg.h bls12_381.h Makefile
|
%.o: %.c c_kzg.h bls12_381.h Makefile
|
||||||
clang -Wall -I$(INCLUDE_DIRS) $(CFLAGS) $(KZG_CFLAGS) -c $*.c
|
clang -Wall -I$(INCLUDE_DIRS) $(CFLAGS) $(KZG_CFLAGS) -c $*.c
|
||||||
|
|
||||||
libckzg.a: $(LIB_OBJ) Makefile
|
libckzg.a: $(LIB_OBJ) Makefile
|
||||||
ar rc libckzg.a $(LIB_OBJ)
|
ar rc libckzg.a $(LIB_OBJ)
|
||||||
|
|
||||||
libckzg4844.a: $(LIB_4844_OBJ) Makefile
|
|
||||||
ar rc libckzg4844.a $(LIB_4844_OBJ)
|
|
||||||
|
|
||||||
%_test: %.c debug_util.o test_util.o libckzg.a Makefile
|
%_test: %.c debug_util.o test_util.o libckzg.a Makefile
|
||||||
clang -Wall -DKZGTEST -I$(INCLUDE_DIRS) $(CFLAGS) $(KZG_CFLAGS) -o $@ $*.c debug_util.o test_util.o libckzg.a -L../lib -lblst
|
clang -Wall -DKZGTEST -I$(INCLUDE_DIRS) $(CFLAGS) $(KZG_CFLAGS) -o $@ $*.c debug_util.o test_util.o libckzg.a -L../lib -lblst
|
||||||
./$@
|
./$@
|
||||||
|
@ -55,7 +50,6 @@ bench: $(BENCH)
|
||||||
clean:
|
clean:
|
||||||
rm -f *.o
|
rm -f *.o
|
||||||
rm -f libckzg.a
|
rm -f libckzg.a
|
||||||
rm -f libckzg4844.a
|
|
||||||
rm -f $(TESTS)
|
rm -f $(TESTS)
|
||||||
rm -f $(BENCH)
|
rm -f $(BENCH)
|
||||||
rm -f $(TUNE)
|
rm -f $(TUNE)
|
||||||
|
|
120
src/c_kzg_4844.c
120
src/c_kzg_4844.c
|
@ -1,120 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2021 Benjamin Edgington
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "c_kzg_4844.h"
|
|
||||||
#include "c_kzg_alloc.h"
|
|
||||||
|
|
||||||
#include <inttypes.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
C_KZG_RET load_trusted_setup(KZGSettings *out, FILE *in) {
|
|
||||||
// custom version of new_kzg_settings to avoid unnecessary allocation
|
|
||||||
|
|
||||||
uint64_t n2, i;
|
|
||||||
int j; uint8_t c[96];
|
|
||||||
blst_p1_affine g1_affine;
|
|
||||||
blst_p2_affine g2_affine;
|
|
||||||
|
|
||||||
fscanf(in, "%" SCNu64, &out->length);
|
|
||||||
fscanf(in, "%" SCNu64, &n2);
|
|
||||||
|
|
||||||
TRY(new_g1_array(&out->secret_g1, out->length));
|
|
||||||
TRY(new_g1_array(&out->secret_g1_l, out->length));
|
|
||||||
TRY(new_g2_array(&out->secret_g2, n2));
|
|
||||||
|
|
||||||
for (i = 0; i < out->length; i++) {
|
|
||||||
for (j = 0; j < 48; j++) {
|
|
||||||
fscanf(in, "%2hhx", &c[j]);
|
|
||||||
}
|
|
||||||
blst_p1_uncompress(&g1_affine, c);
|
|
||||||
blst_p1_from_affine(&out->secret_g1[i], &g1_affine);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < n2; i++) {
|
|
||||||
for (j = 0; j < 96; j++) {
|
|
||||||
fscanf(in, "%2hhx", &c[j]);
|
|
||||||
}
|
|
||||||
blst_p2_uncompress(&g2_affine, c);
|
|
||||||
blst_p2_from_affine(&out->secret_g2[i], &g2_affine);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int max_scale = 0;
|
|
||||||
while (((uint64_t)1 << max_scale) < out->length) max_scale++;
|
|
||||||
|
|
||||||
out->fs = (FFTSettings*)malloc(sizeof(FFTSettings));
|
|
||||||
|
|
||||||
TRY(new_fft_settings((FFTSettings*)out->fs, max_scale));
|
|
||||||
|
|
||||||
return fft_g1(out->secret_g1_l, out->secret_g1, true, out->length, out->fs);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void free_trusted_setup(KZGSettings *s) {
|
|
||||||
free_fft_settings((FFTSettings*)s->fs);
|
|
||||||
free_kzg_settings(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
void compute_powers(BLSFieldElement out[], const BLSFieldElement *x, uint64_t n) { fr_pow(out, x, n); }
|
|
||||||
|
|
||||||
void vector_lincomb(BLSFieldElement out[], const BLSFieldElement[] *vectors, const BLSFieldElement *scalars, uint64_t num_vectors, uint64_t vector_len) {
|
|
||||||
fr_vector_lincomb(out, vectors, scalars, num_vectors, vector_len);
|
|
||||||
}
|
|
||||||
|
|
||||||
void g1_lincomb(KZGCommitment *out, const KZGCommitment points[], const BLSFieldElement scalars[], uint64_t num_points) {
|
|
||||||
g1_linear_combination(out, points, scalars, num_points);
|
|
||||||
|
|
||||||
void blob_to_kzg_commitment(KZGCommitment *out, const BLSFieldElement blob[], const KZGSettings *s) {
|
|
||||||
g1_linear_combination(out, s->secret_g1_l, blob, s->length);
|
|
||||||
}
|
|
||||||
|
|
||||||
void bytes_to_bls_field(BLSFieldElement *out, const scalar_t *bytes) {
|
|
||||||
fr_from_scalar(out, bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
C_KZG_RET evaluate_polynomial_in_evaluation_form(BLSFieldElement *out, const PolynomialEvalForm *polynomial, const BLSFieldElement *z, const KZGSettings *s) {
|
|
||||||
return eval_poly_l(out, polynomial, z, s->fs);
|
|
||||||
}
|
|
||||||
|
|
||||||
C_KZG_RET verify_kzg_proof(bool *out, const KZGCommitment *polynomial_kzg, const BLSFieldElement *z, const BLSFieldElement *y, const KZGProof *kzg_proof, const KZGSettings *s) {
|
|
||||||
return check_proof_single(out, polynomial_kzg, kzg_proof, z, y, s);
|
|
||||||
}
|
|
||||||
|
|
||||||
C_KZG_RET compute_kzg_proof(KZGProof *out, const PolynomialEvalForm *polynomial, const BLSFieldElement *z, const KZGSettings *s) {
|
|
||||||
BLSFieldElement value;
|
|
||||||
TRY(evaluate_polynomial_in_evaluation_form(&value, polynomial, z, s));
|
|
||||||
return compute_proof_single_l(out, polynomial, z, &value, s);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef KZGTEST
|
|
||||||
|
|
||||||
#include "../inc/acutest.h"
|
|
||||||
#include "test_util.h"
|
|
||||||
|
|
||||||
void load_trusted_setup_test(void) {
|
|
||||||
FILE *in = fopen("trusted_setup.txt", "r");
|
|
||||||
KZGSettings ks;
|
|
||||||
TEST_CHECK(C_KZG_OK == load_trusted_setup(&ks, in));
|
|
||||||
fclose(in);
|
|
||||||
free_trusted_setup(&ks);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_LIST = {
|
|
||||||
{"C_KZG_4844_TEST", title},
|
|
||||||
{"load_trusted_setup_test", load_trusted_setup_test},
|
|
||||||
{NULL, NULL} /* zero record marks the end of the list */
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // KZGTEST
|
|
|
@ -1,55 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2021 Benjamin Edgington
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @file c_kzg_4844.h
|
|
||||||
*
|
|
||||||
* Minimal interface required for EIP-4844.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef C_KZG_4844_H
|
|
||||||
#define C_KZG_4844_H
|
|
||||||
|
|
||||||
#include "c_kzg.h"
|
|
||||||
#include "control.h"
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
typedef fr_t BLSFieldElement;
|
|
||||||
typedef g1_t KZGCommitment;
|
|
||||||
typedef g1_t KZGProof;
|
|
||||||
typedef poly_l PolynomialEvalForm;
|
|
||||||
|
|
||||||
C_KZG_RET load_trusted_setup(KZGSettings *out, FILE *in);
|
|
||||||
|
|
||||||
void free_trusted_setup(KZGSettings *s);
|
|
||||||
|
|
||||||
void compute_powers(BLSFieldElement out[], const BLSFieldElement *x, uint64_t n);
|
|
||||||
|
|
||||||
void vector_lincomb(BLSFieldElement out[], const BLSFieldElement *vectors[], const BLSFieldElement *scalars, uint64_t num_vectors, uint64_t vector_len);
|
|
||||||
|
|
||||||
void g1_lincomb(KZGCommitment *out, const KZGCommitment points[], const BLSFieldElement scalars[], uint64_t num_points);
|
|
||||||
|
|
||||||
void blob_to_kzg_commitment(KZGCommitment *out, const BLSFieldElement blob[], const KZGSettings *s);
|
|
||||||
|
|
||||||
void bytes_to_bls_field(BLSFieldElement *out, const scalar_t *bytes);
|
|
||||||
|
|
||||||
C_KZG_RET evaluate_polynomial_in_evaluation_form(BLSFieldElement *out, const PolynomialEvalForm *polynomial, const BLSFieldElement *z, const KZGSettings *s);
|
|
||||||
|
|
||||||
C_KZG_RET verify_kzg_proof(bool *out, const KZGCommitment *polynomial_kzg, const BLSFieldElement *z, const BLSFieldElement *y, const KZGProof *kzg_proof, const KZGSettings *s);
|
|
||||||
|
|
||||||
C_KZG_RET compute_kzg_proof(KZGProof *out, const PolynomialEvalForm *polynomial, const BLSFieldElement *z, const KZGSettings *s);
|
|
||||||
|
|
||||||
#endif // C_KZG_4844_H
|
|
Loading…
Reference in New Issue