Work example up to evaluating a poly_l
This commit is contained in:
parent
560127f1f5
commit
8e5209c491
|
@ -6,17 +6,23 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "c_kzg.h"
|
#include "c_kzg.h"
|
||||||
#include "bls12_381.h"
|
#include "bls12_381.h"
|
||||||
|
#include "test_util.h"
|
||||||
%}
|
%}
|
||||||
%rename(alloc_poly) new_poly;
|
%rename(alloc_poly) new_poly;
|
||||||
%rename(alloc_poly_l) new_poly_l;
|
%rename(alloc_poly_l) new_poly_l;
|
||||||
|
|
||||||
%typemap(in, numinputs=0) OBJECT *out ($1_basetype tmp) { $1 = &tmp; }
|
%typemap(in, numinputs=0) OBJECT *OUTPUT($1_basetype tmp) { $1 = &tmp; }
|
||||||
%typemap(argout) OBJECT *out {
|
%typemap(argout) OBJECT *OUTPUT {
|
||||||
PyObject *obj = SWIG_NewPointerObj(memcpy(malloc(sizeof($1_basetype)),$1,sizeof($1_basetype)),
|
PyObject *obj = SWIG_NewPointerObj(memcpy(malloc(sizeof($1_basetype)),$1,sizeof($1_basetype)),
|
||||||
$descriptor, SWIG_POINTER_NEW);
|
$descriptor, SWIG_POINTER_NEW);
|
||||||
$result = ($result == NULL) ? obj : SWIG_Python_AppendOutput($result, obj);
|
$result = ($result == NULL) ? obj : SWIG_Python_AppendOutput($result, obj);
|
||||||
}
|
}
|
||||||
%apply OBJECT *out { fr_t *out, poly *out, poly_l *out }
|
%apply OBJECT *OUTPUT {
|
||||||
|
fr_t *out, poly *out, poly_l *out,
|
||||||
|
g1_t *out, g2_t *out,
|
||||||
|
blst_scalar *out,
|
||||||
|
FFTSettings *out, KZGSettings *out
|
||||||
|
}
|
||||||
|
|
||||||
%typemap(in, numinputs=0) uint64_t out[4] (uint64_t tmp[4]) { $1 = tmp; }
|
%typemap(in, numinputs=0) uint64_t out[4] (uint64_t tmp[4]) { $1 = tmp; }
|
||||||
%typemap(argout) uint64_t out[4] {
|
%typemap(argout) uint64_t out[4] {
|
||||||
|
@ -29,7 +35,6 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
%typemap(in) const uint64_t[4] (uint64_t tmp[4]) {
|
%typemap(in) const uint64_t[4] (uint64_t tmp[4]) {
|
||||||
int i;
|
|
||||||
if (PyTuple_Check($input)) {
|
if (PyTuple_Check($input)) {
|
||||||
if (!PyArg_ParseTuple($input, "KKKK", tmp, tmp+1, tmp+2, tmp+3)) {
|
if (!PyArg_ParseTuple($input, "KKKK", tmp, tmp+1, tmp+2, tmp+3)) {
|
||||||
PyErr_SetString(PyExc_TypeError, "tuple must have 4 elements");
|
PyErr_SetString(PyExc_TypeError, "tuple must have 4 elements");
|
||||||
|
@ -43,8 +48,12 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
%array_class(fr_t, frArray)
|
%array_class(fr_t, frArray)
|
||||||
|
%array_class(g1_t, g1Array)
|
||||||
|
%array_class(g2_t, g2Array)
|
||||||
%pointer_class(poly, polyp)
|
%pointer_class(poly, polyp)
|
||||||
%pointer_class(poly_l, poly_lp)
|
%pointer_class(poly_l, poly_lp)
|
||||||
|
|
||||||
%include "../src/c_kzg.h"
|
%include "../src/c_kzg.h"
|
||||||
%include "../src/bls12_381.h"
|
%include "../src/bls12_381.h"
|
||||||
|
%include "../inc/blst.h"
|
||||||
|
%include "../src/test_util.h"
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
INCLUDE_DIRS = .. ../../src ../../inc
|
INCLUDE_DIRS = .. ../../src ../../inc
|
||||||
INCLUDE_PY = $(shell python -c 'import sysconfig; print(sysconfig.get_config_var("INCLUDEPY"))')
|
INCLUDE_PY = $(shell python -c 'import sysconfig; print(sysconfig.get_config_var("INCLUDEPY"))')
|
||||||
|
|
||||||
_ckzg.so: c_kzg_wrap.c ../../src/libckzg.a ../../lib/libblst.a
|
_ckzg.so: c_kzg_wrap.c ../../src/libckzg.a ../../lib/libblst.a ../../src/test_util.o
|
||||||
clang -O -Wall -shared -fPIC -Wl,-Bsymbolic -I${INCLUDE_PY} ${addprefix -I,${INCLUDE_DIRS}} -o $@ $^
|
clang -O -Wall -shared -fPIC -Wl,-Bsymbolic -I${INCLUDE_PY} ${addprefix -I,${INCLUDE_DIRS}} -o $@ $^
|
||||||
|
|
||||||
c_kzg_wrap.c ckzg.py: ../c_kzg.swg
|
c_kzg_wrap.c ckzg.py: ../c_kzg.swg
|
||||||
|
|
|
@ -10,7 +10,27 @@ cfa = ckzg.frArray(len(coeffs))
|
||||||
for i, c in enumerate(coeffs):
|
for i, c in enumerate(coeffs):
|
||||||
cfa[i] = c
|
cfa[i] = c
|
||||||
ret, pptr = ckzg.new_poly_with_coeffs(cfa.cast(), len(coeffs))
|
ret, pptr = ckzg.new_poly_with_coeffs(cfa.cast(), len(coeffs))
|
||||||
|
assert ret == 0
|
||||||
p = ckzg.polyp_frompointer(pptr).value()
|
p = ckzg.polyp_frompointer(pptr).value()
|
||||||
assert p.length == 4
|
assert p.length == 4
|
||||||
pcoeffs = ckzg.frArray_frompointer(p.coeffs)
|
pcoeffs = ckzg.frArray_frompointer(p.coeffs)
|
||||||
assert ckzg.fr_to_uint64s(pcoeffs[1]) == (2, 0, 0, 0)
|
assert ckzg.fr_to_uint64s(pcoeffs[1]) == (2, 0, 0, 0)
|
||||||
|
max_scale = 4
|
||||||
|
ret, fs = ckzg.new_fft_settings(max_scale)
|
||||||
|
assert ret == 0
|
||||||
|
secret_s = ckzg.blst_scalar_from_uint64((29,3,1,4))
|
||||||
|
num_secrets = 2 ** max_scale
|
||||||
|
g1s = ckzg.g1Array(num_secrets)
|
||||||
|
g2s = ckzg.g2Array(num_secrets)
|
||||||
|
ckzg.generate_trusted_setup(g1s.cast(), g2s.cast(), secret_s, num_secrets)
|
||||||
|
ret, ks = ckzg.new_kzg_settings(g1s.cast(), g2s.cast(), num_secrets, fs)
|
||||||
|
assert ret == 0
|
||||||
|
ret, p_l = ckzg.new_poly_l_from_poly(p, ks)
|
||||||
|
assert ret == 0
|
||||||
|
ret, y = ckzg.eval_poly_l(p_l, c2, fs)
|
||||||
|
assert ret == 0
|
||||||
|
print(ckzg.fr_to_uint64s(y))
|
||||||
|
ckzg.free_poly(p)
|
||||||
|
ckzg.free_poly_l(p_l)
|
||||||
|
ckzg.free_fft_settings(fs)
|
||||||
|
ckzg.free_kzg_settings(ks)
|
||||||
|
|
|
@ -57,7 +57,7 @@ typedef struct {
|
||||||
fr_t *reverse_roots_of_unity; /**< Descending powers of the root of unity, size `width + 1`. */
|
fr_t *reverse_roots_of_unity; /**< Descending powers of the root of unity, size `width + 1`. */
|
||||||
} FFTSettings;
|
} FFTSettings;
|
||||||
|
|
||||||
C_KZG_RET new_fft_settings(FFTSettings *s, unsigned int max_scale);
|
C_KZG_RET new_fft_settings(FFTSettings *out, unsigned int max_scale);
|
||||||
void free_fft_settings(FFTSettings *s);
|
void free_fft_settings(FFTSettings *s);
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -131,7 +131,7 @@ C_KZG_RET check_proof_single(bool *out, const g1_t *commitment, const g1_t *proo
|
||||||
C_KZG_RET compute_proof_multi(g1_t *out, const poly *p, const fr_t *x0, uint64_t n, const KZGSettings *ks);
|
C_KZG_RET compute_proof_multi(g1_t *out, const poly *p, const fr_t *x0, uint64_t n, const KZGSettings *ks);
|
||||||
C_KZG_RET check_proof_multi(bool *out, const g1_t *commitment, const g1_t *proof, const fr_t *x, const fr_t *ys,
|
C_KZG_RET check_proof_multi(bool *out, const g1_t *commitment, const g1_t *proof, const fr_t *x, const fr_t *ys,
|
||||||
uint64_t n, const KZGSettings *ks);
|
uint64_t n, const KZGSettings *ks);
|
||||||
C_KZG_RET new_kzg_settings(KZGSettings *ks, const g1_t *secret_g1, const g2_t *secret_g2, uint64_t length,
|
C_KZG_RET new_kzg_settings(KZGSettings *out, const g1_t *secret_g1, const g2_t *secret_g2, uint64_t length,
|
||||||
const FFTSettings *fs);
|
const FFTSettings *fs);
|
||||||
void free_kzg_settings(KZGSettings *ks);
|
void free_kzg_settings(KZGSettings *ks);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue