Trying and failing to interface to vector_lincomb

This commit is contained in:
Ramana Kumar 2022-10-01 18:19:39 +01:00
parent bc89288ca7
commit d52981ef6d
No known key found for this signature in database
GPG Key ID: ED471C788B900433
2 changed files with 28 additions and 14 deletions

View File

@ -70,8 +70,14 @@
} }
#endif #endif
%{
typedef BLSFieldElement* BLSFieldVector;
%}
typedef BLSFieldElement* BLSFieldVector;
%array_class(uint8_t, bytes) %array_class(uint8_t, bytes)
%array_class(BLSFieldElement, BLSFieldElements) %array_class(BLSFieldElement, BLSFieldElements)
%array_class(BLSFieldVector, BLSFieldVectors)
%pointer_class(PolynomialEvalForm, PolynomialEvalFormPtr) %pointer_class(PolynomialEvalForm, PolynomialEvalFormPtr)
%include "../min-src/c_kzg_4844.h" %include "../min-src/c_kzg_4844.h"

View File

@ -29,9 +29,8 @@ blobs_sedes = ssz.List(ssz.Vector(ssz.uint256, BLOB_SIZE), MAX_BLOBS_PER_BLOCK)
kzg_commitments_sedes = ssz.List(ssz.bytes48, MAX_BLOBS_PER_BLOCK) kzg_commitments_sedes = ssz.List(ssz.bytes48, MAX_BLOBS_PER_BLOCK)
# Commit to a few random blobs # Commit to a few random blobs
num_blobs = 3 blobs = [ckzg.BLSFieldElements(BLOB_SIZE) for _ in range(3)]
blobs = [ckzg.BLSFieldElements(BLOB_SIZE) for _ in range(num_blobs)] for i in range(len(blobs)):
for i in range(num_blobs):
for j in range(BLOB_SIZE): for j in range(BLOB_SIZE):
blobs[i][j] = ckzg.blst_fr.from_int(random.randrange(0, 2**256)) blobs[i][j] = ckzg.blst_fr.from_int(random.randrange(0, 2**256))
kzg_commitments = [ckzg.blob_to_kzg_commitment(blob.cast(), ts) for blob in blobs] kzg_commitments = [ckzg.blob_to_kzg_commitment(blob.cast(), ts) for blob in blobs]
@ -54,24 +53,33 @@ hashed = ssz.hash.hashlib.sha256(encoded_blobs + encoded_commitments).digest()
h = ckzg.bytes.frompybytes(hashed) h = ckzg.bytes.frompybytes(hashed)
r = ckzg.bytes_to_bls_field(h.cast()) r = ckzg.bytes_to_bls_field(h.cast())
r_powers = ckzg.BLSFieldElements(len(kzg_commitments)) r_powers = ckzg.BLSFieldElements(len(blobs))
ckzg.compute_powers(r_powers.cast(), r, len(kzg_commitments)) ckzg.compute_powers(r_powers.cast(), r, len(blobs))
values = ckzg.BLSFieldElements(len(r_powers)) vectors = ckzg.BLSFieldVectors(len(blobs))
for i, v in enumerate(blobs):
vectors[i] = v.cast()
# ckzg.vector_lincomb(values.cast(), blobs ret, pptr = ckzg.alloc_polynomial(len(blobs))
assert ret == 0
aggregated_poly = ckzg.PolynomialEvalFormPtr_frompointer(pptr).value()
# aggregated_poly = Polynomial(vector_lincomb(blobs, r_powers)) # ckzg.vector_lincomb(
# # aggregated_poly.values,
# # Compute commitment to aggregated polynomial # vectors.cast(),
# aggregated_poly_commitment = KZGCommitment(g1_lincomb(kzg_commitments, r_powers)) # r_powers.cast(),
# # len(blobs),
# return aggregated_poly, aggregated_poly_commitment # BLOB_SIZE)
#aggregated_poly_commitment =
#ckzg.g1_lincomb(kzg_commitments
#KZGCommitment(g1_lincomb(kzg_commitments, r_powers))
print('Tests passed') print('Tests passed')
def cleanup(): def cleanup():
ckzg.free_polynomial(pptr)
ckzg.free_trusted_setup(ts) ckzg.free_trusted_setup(ts)
atexit.register(cleanup) atexit.register(cleanup)