Start on a 4844 minimal interface

The object files to implement this are not correct in the Makefile.
The files probably need to be split more carefully to separate 4844
things from the rest.
This commit is contained in:
Ramana Kumar 2022-09-19 23:18:42 +01:00
parent 63fc842d6d
commit a7eea8b533
No known key found for this signature in database
GPG Key ID: ED471C788B900433
4 changed files with 110 additions and 1 deletions

View File

@ -4,18 +4,23 @@ BENCH = fft_fr_bench fft_g1_bench recover_bench zero_poly_bench kzg_proofs_bench
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_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 =
INCLUDE_DIRS = ../inc
.PRECIOUS: %.o
%.o: %.c c_kzg.h bls12_381.h Makefile
%.o: %.c c_kzg_4844.h c_kzg.h bls12_381.h Makefile
clang -Wall -I$(INCLUDE_DIRS) $(CFLAGS) $(KZG_CFLAGS) -c $*.c
libckzg.a: $(LIB_OBJ) Makefile
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
clang -Wall -DKZGTEST -I$(INCLUDE_DIRS) $(CFLAGS) $(KZG_CFLAGS) -o $@ $*.c debug_util.o test_util.o libckzg.a -L../lib -lblst
./$@
@ -50,6 +55,7 @@ bench: $(BENCH)
clean:
rm -f *.o
rm -f libckzg.a
rm -f libckzg4844.a
rm -f $(TESTS)
rm -f $(BENCH)
rm -f $(TUNE)

View File

@ -107,6 +107,8 @@ void free_poly_l(poly_l *p);
// kzg_proofs.c
//
void fr_vector_lincomb(fr_t out[], const fr_t *vectors, const fr_t *scalars, uint64_t n, uint64_t m);
/**
* Stores the setup and parameters needed for computing KZG proofs.
*

49
src/c_kzg_4844.c Normal file
View File

@ -0,0 +1,49 @@
/*
* 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"
void load_trusted_setup(KZGSettings *out) { }
void free_trusted_setup(KZGSettings *s) { 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 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);
}

52
src/c_kzg_4844.h Normal file
View File

@ -0,0 +1,52 @@
/*
* 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"
typedef fr_t BLSFieldElement;
typedef g1_t KZGCommitment;
typedef g1_t KZGProof;
typedef poly_l PolynomialEvalForm;
void load_trusted_setup(KZGSettings *out); // TODO: decide on input format and add appropriate arguments
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 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