From 4101648253163e1fc8362fcb7122b73cdbd915b0 Mon Sep 17 00:00:00 2001 From: Ramana Kumar Date: Fri, 2 Dec 2022 12:49:20 +0000 Subject: [PATCH] Update python test for encoding checks We ensure we are below the modulus by just using a zero final byte for each field element encoding. In the test, I do not understand why changing the final (zero) byte causes verification to succeed instead of failing. But this is why the change is now to the first byte. --- bindings/python/tests.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/bindings/python/tests.py b/bindings/python/tests.py index 7b2082f..2b4ea3e 100644 --- a/bindings/python/tests.py +++ b/bindings/python/tests.py @@ -7,7 +7,9 @@ BLOB_SIZE = 4096 MAX_BLOBS_PER_BLOCK = 16 blobs = [ - random.randbytes(32 * BLOB_SIZE) for _ in range(3) + # use zero final bytes to easily ensure the encodings are valid + b''.join([b''.join([random.randbytes(31), bytes(1)]) for _ in range(BLOB_SIZE)]) + for _ in range(3) ] ts = ckzg.load_trusted_setup("../../src/trusted_setup.txt") @@ -26,8 +28,8 @@ assert ckzg.verify_aggregate_kzg_proof(blobs_bytes, kzg_commitments, proof, ts), # Verification fails at wrong value -other = b'x' if not blobs_bytes.endswith(b'x') else b'y' -other_bytes = blobs_bytes[:-1] + other +other = b'x' if not blobs_bytes.startswith(b'x') else b'y' +other_bytes = other + blobs_bytes[1:] assert not ckzg.verify_aggregate_kzg_proof(other_bytes, kzg_commitments, proof, ts), 'verify succeeded incorrectly'