From 6041c9b9d6f518aa51731c167ccaec4151664162 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Tue, 19 Sep 2023 23:09:38 +0800 Subject: [PATCH 1/4] Add KZGProof at `G1_POINT_AT_INFINITY` case --- tests/generators/kzg_4844/main.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/tests/generators/kzg_4844/main.py b/tests/generators/kzg_4844/main.py index 1c5aefc61..3bbd0c8ab 100644 --- a/tests/generators/kzg_4844/main.py +++ b/tests/generators/kzg_4844/main.py @@ -399,6 +399,20 @@ def case05_verify_blob_kzg_proof(): 'output': None } + # Edge case: Incorrect `G1_POINT_AT_INFINITY` Proof + blob = BLOB_RANDOM_VALID1 + commitment = spec.blob_to_kzg_commitment(blob) + proof = spec.G1_POINT_AT_INFINITY + assert not spec.verify_blob_kzg_proof(blob, commitment, proof) + yield 'verify_blob_kzg_proof_case_incorrect_proof_point_at_infinity', { + 'input': { + 'blob': encode_hex(blob), + 'commitment': encode_hex(commitment), + 'proof': encode_hex(proof), + }, + 'output': False + } + def case06_verify_blob_kzg_proof_batch(): # Valid cases @@ -423,7 +437,7 @@ def case06_verify_blob_kzg_proof_batch(): # Incorrect proof proofs_incorrect = [bls_add_one(proofs[0])] + proofs[1:] assert not spec.verify_blob_kzg_proof_batch(VALID_BLOBS, commitments, proofs_incorrect) - yield 'verify_blob_kzg_proof_batch_case_invalid_proof', { + yield 'verify_blob_kzg_proof_batch_case_incorrect_proof_add_one', { 'input': { 'blobs': encode_hex_list(VALID_BLOBS), 'commitments': encode_hex_list(commitments), @@ -509,6 +523,21 @@ def case06_verify_blob_kzg_proof_batch(): 'output': None } + # Edge case: Incorrect `G1_POINT_AT_INFINITY` Proof + blob = BLOB_RANDOM_VALID1 + commitment = spec.blob_to_kzg_commitment(blob) + proof = spec.G1_POINT_AT_INFINITY + assert not spec.verify_blob_kzg_proof_batch([blob], [commitment], [proof]) + + yield 'verify_blob_kzg_proof_batch_case_incorrect_proof_point_at_infinity', { + 'input': { + 'blobs': encode_hex_list([blob]), + 'commitments': encode_hex_list([commitment]), + 'proofs': encode_hex_list([proof]), + }, + 'output': False + } + def create_provider(fork_name: SpecForkName, handler_name: str, From 171ae02280cab244c828ee6f7c6325386b3fc19c Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Wed, 20 Sep 2023 00:18:08 +0800 Subject: [PATCH 2/4] Apply suggestions from code review Co-authored-by: Justin Traglia <95511699+jtraglia@users.noreply.github.com> --- tests/generators/kzg_4844/main.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/generators/kzg_4844/main.py b/tests/generators/kzg_4844/main.py index 3bbd0c8ab..ec9c613b9 100644 --- a/tests/generators/kzg_4844/main.py +++ b/tests/generators/kzg_4844/main.py @@ -399,7 +399,7 @@ def case05_verify_blob_kzg_proof(): 'output': None } - # Edge case: Incorrect `G1_POINT_AT_INFINITY` Proof + # Incorrect `G1_POINT_AT_INFINITY` proof blob = BLOB_RANDOM_VALID1 commitment = spec.blob_to_kzg_commitment(blob) proof = spec.G1_POINT_AT_INFINITY @@ -523,12 +523,11 @@ def case06_verify_blob_kzg_proof_batch(): 'output': None } - # Edge case: Incorrect `G1_POINT_AT_INFINITY` Proof + # Incorrect `G1_POINT_AT_INFINITY` proof blob = BLOB_RANDOM_VALID1 commitment = spec.blob_to_kzg_commitment(blob) proof = spec.G1_POINT_AT_INFINITY assert not spec.verify_blob_kzg_proof_batch([blob], [commitment], [proof]) - yield 'verify_blob_kzg_proof_batch_case_incorrect_proof_point_at_infinity', { 'input': { 'blobs': encode_hex_list([blob]), From 256367b17c2ee4571a0dd9d5b09761415ee792ff Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Wed, 20 Sep 2023 00:21:18 +0800 Subject: [PATCH 3/4] Group the "incorrect_proof" test cases --- tests/generators/kzg_4844/main.py | 56 +++++++++++++++---------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/tests/generators/kzg_4844/main.py b/tests/generators/kzg_4844/main.py index ec9c613b9..5393f8dea 100644 --- a/tests/generators/kzg_4844/main.py +++ b/tests/generators/kzg_4844/main.py @@ -354,6 +354,20 @@ def case05_verify_blob_kzg_proof(): 'output': False } + # Incorrect `G1_POINT_AT_INFINITY` proof + blob = BLOB_RANDOM_VALID1 + commitment = spec.blob_to_kzg_commitment(blob) + proof = spec.G1_POINT_AT_INFINITY + assert not spec.verify_blob_kzg_proof(blob, commitment, proof) + yield 'verify_blob_kzg_proof_case_incorrect_proof_point_at_infinity', { + 'input': { + 'blob': encode_hex(blob), + 'commitment': encode_hex(commitment), + 'proof': encode_hex(proof), + }, + 'output': False + } + # Edge case: Invalid blob for blob in INVALID_BLOBS: proof = G1 @@ -399,20 +413,6 @@ def case05_verify_blob_kzg_proof(): 'output': None } - # Incorrect `G1_POINT_AT_INFINITY` proof - blob = BLOB_RANDOM_VALID1 - commitment = spec.blob_to_kzg_commitment(blob) - proof = spec.G1_POINT_AT_INFINITY - assert not spec.verify_blob_kzg_proof(blob, commitment, proof) - yield 'verify_blob_kzg_proof_case_incorrect_proof_point_at_infinity', { - 'input': { - 'blob': encode_hex(blob), - 'commitment': encode_hex(commitment), - 'proof': encode_hex(proof), - }, - 'output': False - } - def case06_verify_blob_kzg_proof_batch(): # Valid cases @@ -446,6 +446,20 @@ def case06_verify_blob_kzg_proof_batch(): 'output': False } + # Incorrect `G1_POINT_AT_INFINITY` proof + blob = BLOB_RANDOM_VALID1 + commitment = spec.blob_to_kzg_commitment(blob) + proof = spec.G1_POINT_AT_INFINITY + assert not spec.verify_blob_kzg_proof_batch([blob], [commitment], [proof]) + yield 'verify_blob_kzg_proof_batch_case_incorrect_proof_point_at_infinity', { + 'input': { + 'blobs': encode_hex_list([blob]), + 'commitments': encode_hex_list([commitment]), + 'proofs': encode_hex_list([proof]), + }, + 'output': False + } + # Edge case: Invalid blobs for blob in INVALID_BLOBS: blobs_invalid = VALID_BLOBS[:4] + [blob] + VALID_BLOBS[5:] @@ -523,20 +537,6 @@ def case06_verify_blob_kzg_proof_batch(): 'output': None } - # Incorrect `G1_POINT_AT_INFINITY` proof - blob = BLOB_RANDOM_VALID1 - commitment = spec.blob_to_kzg_commitment(blob) - proof = spec.G1_POINT_AT_INFINITY - assert not spec.verify_blob_kzg_proof_batch([blob], [commitment], [proof]) - yield 'verify_blob_kzg_proof_batch_case_incorrect_proof_point_at_infinity', { - 'input': { - 'blobs': encode_hex_list([blob]), - 'commitments': encode_hex_list([commitment]), - 'proofs': encode_hex_list([proof]), - }, - 'output': False - } - def create_provider(fork_name: SpecForkName, handler_name: str, From 395bb714421bc95bf2966ede3d4b74c4cd561a51 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Wed, 20 Sep 2023 00:39:47 +0800 Subject: [PATCH 4/4] Add `verify_kzg_proof_case_incorrect_proof_point_at_infinity` --- tests/generators/kzg_4844/main.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/generators/kzg_4844/main.py b/tests/generators/kzg_4844/main.py index 5393f8dea..6e43a77ad 100644 --- a/tests/generators/kzg_4844/main.py +++ b/tests/generators/kzg_4844/main.py @@ -214,6 +214,22 @@ def case03_verify_kzg_proof(): 'output': False } + # Incorrect `G1_POINT_AT_INFINITY` proof + blob = BLOB_RANDOM_VALID1 + _, y = spec.compute_kzg_proof(blob, z) + commitment = spec.blob_to_kzg_commitment(blob) + proof = spec.G1_POINT_AT_INFINITY + assert not spec.verify_kzg_proof(commitment, z, y, proof) + yield 'verify_kzg_proof_case_incorrect_proof_point_at_infinity', { + 'input': { + 'commitment': encode_hex(commitment), + 'z': encode_hex(z), + 'y': encode_hex(y), + 'proof': encode_hex(proof), + }, + 'output': False + } + # Edge case: Invalid commitment for commitment in INVALID_G1_POINTS: blob, z = VALID_BLOBS[2], VALID_FIELD_ELEMENTS[1]