c-kzg-4844/bindings/python/tests.py

35 lines
816 B
Python
Raw Normal View History

import ckzg
2022-11-01 14:24:02 +00:00
import random
2022-09-18 22:16:16 +00:00
2022-11-01 14:24:02 +00:00
# Commit to a few random blobs
2022-09-18 22:16:16 +00:00
2022-11-01 14:24:02 +00:00
BLOB_SIZE = 4096
MAX_BLOBS_PER_BLOCK = 16
2022-09-18 22:16:16 +00:00
2022-11-01 14:24:02 +00:00
blobs = [
random.randbytes(32 * BLOB_SIZE) for _ in range(3)
]
2022-11-01 14:24:02 +00:00
ts = ckzg.load_trusted_setup("../../src/trusted_setup.txt")
2022-09-18 22:16:16 +00:00
2022-11-01 14:24:02 +00:00
kzg_commitments = [ckzg.blob_to_kzg_commitment(blob, ts) for blob in blobs]
2022-11-01 14:24:02 +00:00
# Compute proof for these blobs
2022-09-18 22:16:16 +00:00
2022-11-01 14:24:02 +00:00
blobs_bytes = b''.join(blobs)
2022-09-18 22:16:16 +00:00
2022-11-01 14:24:02 +00:00
proof = ckzg.compute_aggregate_kzg_proof(blobs_bytes, ts)
2022-11-01 14:24:02 +00:00
# Verify proof
2022-09-18 22:16:16 +00:00
2022-11-01 14:24:02 +00:00
assert ckzg.verify_aggregate_kzg_proof(blobs_bytes, kzg_commitments, proof, ts), 'verify failed'
2022-11-01 14:24:02 +00:00
# Verification fails at wrong value
2022-09-18 22:16:16 +00:00
2022-11-01 14:24:02 +00:00
other = b'x' if not blobs_bytes.endswith(b'x') else b'y'
other_bytes = blobs_bytes[:-1] + other
2022-11-01 14:24:02 +00:00
assert not ckzg.verify_aggregate_kzg_proof(other_bytes, kzg_commitments, proof, ts), 'verify succeeded incorrectly'
2022-09-18 22:16:16 +00:00
2022-11-01 14:24:02 +00:00
print('tests passed')