Skip to content

Port kzg_4844 tests to pytest#4606

Merged
jtraglia merged 6 commits into
ethereum:masterfrom
leolara:leolara/port_kzg_4844_pytest
Sep 26, 2025
Merged

Port kzg_4844 tests to pytest#4606
jtraglia merged 6 commits into
ethereum:masterfrom
leolara:leolara/port_kzg_4844_pytest

Conversation

@leolara

@leolara leolara commented Sep 22, 2025

Copy link
Copy Markdown
Member

It does what it says.

Comparing the generated files with diff -qr produces:

Only in consensus-spec-tests/new/general/deneb/kzg: blob_to_kzg_commitment

which make sense because that was ported already and it is only in the pytest version.

Note: I have left the non-pytest version commented out so you can check the generated files yourself. I will remove it once it is approved.

@leolara leolara requested a review from jtraglia September 22, 2025 17:05
@jtraglia

jtraglia commented Sep 22, 2025

Copy link
Copy Markdown
Member

Hmm these templates feel very repetitive. Instead, could we have two templates for each test. A success template and a failure template. Then pass the test name prefix to the template as well?

Edit: better yet, a single template for each function which has a valid: bool parameter.

@jtraglia jtraglia left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment above.

@leolara

leolara commented Sep 23, 2025

Copy link
Copy Markdown
Member Author

Hmm these templates feel very repetitive. Instead, could we have two templates for each test. A success template and a failure template. Then pass the test name prefix to the template as well?

Here is a list of all the tests templates for ZKG 8488:

 test_compute_challenge.py:
  - _compute_challenge_case_valid

  test_compute_kzg_proof.py:
  - _compute_kzg_proof_case_valid
  - _compute_kzg_proof_case_invalid_blob
  - _compute_kzg_proof_case_invalid_z

  test_compute_blob_kzg_proof.py:
  - _compute_blob_kzg_proof_case_valid_blob
  - _compute_blob_kzg_proof_case_invalid_blob
  - _compute_blob_kzg_proof_case_invalid_commitment

  test_blob_to_kzg_commitment.py:
  - _blob_to_kzg_commitment_case_valid_blob
  - _blob_to_kzg_commitment_case_invalid_blob

  test_verify_kzg_proof.py:
  - _verify_kzg_proof_case_correct_proof
  - _verify_kzg_proof_case_incorrect_proof
  - _verify_kzg_proof_case_incorrect_proof_point_at_infinity
  - _verify_kzg_proof_case_correct_proof_point_at_infinity_for_zero
  _poly
  - _verify_kzg_proof_case_correct_proof_point_at_infinity_for_twos
  _poly
  - _verify_kzg_proof_case_invalid_commitment
  - _verify_kzg_proof_case_invalid_z
  - _verify_kzg_proof_case_invalid_y
  - _verify_kzg_proof_case_invalid_proof

  test_verify_blob_kzg_proof.py:
  - _verify_blob_kzg_proof_case_correct_proof
  - _verify_blob_kzg_proof_case_incorrect_proof
  - _verify_blob_kzg_proof_case_incorrect_proof_point_at_infinity
  - _verify_blob_kzg_proof_case_correct_proof_point_at_infinity_for
  _zero_poly
  - _verify_blob_kzg_proof_case_correct_proof_point_at_infinity_for
  _twos_poly
  - _verify_blob_kzg_proof_case_invalid_blob
  - _verify_blob_kzg_proof_case_invalid_commitment
  - _verify_blob_kzg_proof_case_invalid_proof

  test_verify_blob_kzg_proof_batch.py:
  - _verify_blob_kzg_proof_batch_case
  - _verify_blob_kzg_proof_batch_case_incorrect_proof_add_one
  - _verify_blob_kzg_proof_batch_case_incorrect_proof_point_at_infi
  nity
  - _verify_blob_kzg_proof_batch_case_invalid_blob
  - _verify_blob_kzg_proof_batch_case_invalid_commitment
  - _verify_blob_kzg_proof_batch_case_invalid_proof
  - _verify_blob_kzg_proof_batch_case_blob_length_different
  - _verify_blob_kzg_proof_batch_case_commitment_length_different
  - _verify_blob_kzg_proof_batch_case_proof_length_different

Which ones in your opinion are testing the same thing?

@jtraglia jtraglia added the testing CI, actions, tests, testing infra label Sep 23, 2025
@jtraglia

jtraglia commented Sep 23, 2025

Copy link
Copy Markdown
Member

@leolara I'm saying that in each file, there can be a single template.

  • _compute_blob_kzg_proof_case_valid_blob
  • _compute_blob_kzg_proof_case_invalid_blob
  • _compute_blob_kzg_proof_case_invalid_commitment

Consolidated into a single _compute_blob_kzg_proof_template function with the following params:

  • test_name: str
  • get_inputs: fn
  • valid: bool

I'm just asking for something a bit more generic so we don't have so many template functions.

For example: I would like to see it done like this: test_compute_blob_kzg_proof.py

@jtraglia jtraglia left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@leolara you've removed the templates but kept the duplicate code, which is the exact opposite of what I wanted.

y: Bytes32 -- the claimed result of the evaluation
proof: KZGProof -- The KZG proof
output: bool -- true (valid proof) or false (incorrect proof)
output: bool -- true (valid proof) or false (incorrect proof), None if exception is thrown by verify_kzg_proof

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is stated at the bottom of each file:

result should match the expected `output`. If the commitment or proof is invalid
(e.g. not on the curve or not in the G1 subgroup of the BLS curve) or `z` or `y`
are not a valid BLS field element, it should error, i.e. the output should be
`null`.

I agree that this could be clearer though. Let's revert this & follow up with another PR that updates this for all KZG formats, instead of just this one.

Also, this can be simplified & we should null instead of None.

true (valid proof), false (incorrect proof), null (error)

@jtraglia jtraglia left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@leolara thank you for reducing the repetitive code.

This PR looks good to me. I can confirm the outputs are the same.

Image

@jtraglia jtraglia changed the title Port KZG 4844 test generation to pytest Port kzg_4844 tests to pytest Sep 26, 2025
@jtraglia jtraglia merged commit 3c21f03 into ethereum:master Sep 26, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

testing CI, actions, tests, testing infra

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants