Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
###############################################################################
# Test cases for compute_blob_kzg_proof
###############################################################################

from eth_utils.hexadecimal import encode_hex

from eth2spec.test.context import only_generator, single_phase, spec_test, with_phases
from eth2spec.test.helpers.constants import DENEB
from eth2spec.test.utils.kzg_tests import G1, INVALID_BLOBS, INVALID_G1_POINTS, VALID_BLOBS
from tests.infra.manifest import manifest
from tests.infra.template_test import template_test


@template_test
def _compute_blob_kzg_proof_case_valid_blob(blob_index):
blob = VALID_BLOBS[blob_index]

@manifest(preset_name="general", suite_name="kzg-mainnet")
@only_generator("too slow")
@with_phases([DENEB])
@spec_test
@single_phase
def the_test(spec):
commitment = spec.blob_to_kzg_commitment(blob)
proof = spec.compute_blob_kzg_proof(blob, commitment)

yield (
"data",
"data",
{
"input": {
"blob": encode_hex(blob),
"commitment": encode_hex(commitment),
},
"output": encode_hex(proof),
},
)

return (the_test, f"test_compute_blob_kzg_proof_case_valid_blob_{blob_index}")


for blob_index in range(len(VALID_BLOBS)):
_compute_blob_kzg_proof_case_valid_blob(blob_index)


@template_test
def _compute_blob_kzg_proof_case_invalid_blob(blob_index):
blob = INVALID_BLOBS[blob_index]
commitment = G1

@manifest(preset_name="general", suite_name="kzg-mainnet")
@only_generator("too slow")
@with_phases([DENEB])
@spec_test
@single_phase
def the_test(spec):
try:
proof = spec.compute_blob_kzg_proof(blob, commitment)
except Exception:
proof = None

# assert exception is thrown
assert proof == None

yield (
"data",
"data",
{
"input": {
"blob": encode_hex(blob),
"commitment": encode_hex(commitment),
},
"output": None,
},
)

return (the_test, f"test_compute_blob_kzg_proof_case_invalid_blob_{blob_index}")


for blob_index in range(len(INVALID_BLOBS)):
_compute_blob_kzg_proof_case_invalid_blob(blob_index)


@template_test
def _compute_blob_kzg_proof_case_invalid_commitment(commitment_index):
blob = VALID_BLOBS[1]
commitment = INVALID_G1_POINTS[commitment_index]

@manifest(preset_name="general", suite_name="kzg-mainnet")
@only_generator("too slow")
@with_phases([DENEB])
@spec_test
@single_phase
def the_test(spec):
try:
proof = spec.compute_blob_kzg_proof(blob, commitment)
except Exception:
proof = None

# assert exception is thrown
assert proof == None

yield (
"data",
"data",
{
"input": {
"blob": encode_hex(blob),
"commitment": encode_hex(commitment),
},
"output": None,
},
)

return (the_test, f"test_compute_blob_kzg_proof_case_invalid_commitment_{commitment_index}")


for commitment_index in range(len(INVALID_G1_POINTS)):
_compute_blob_kzg_proof_case_invalid_commitment(commitment_index)
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
###############################################################################
# Test cases for compute_challenge
###############################################################################

from eth_utils.hexadecimal import encode_hex

from eth2spec.test.context import only_generator, single_phase, spec_test, with_phases
from eth2spec.test.helpers.constants import DENEB
from eth2spec.test.utils.kzg_tests import VALID_BLOBS
from tests.infra.manifest import manifest
from tests.infra.template_test import template_test


@template_test
def _compute_challenge_case_valid(blob_index):
blob = VALID_BLOBS[blob_index]

@manifest(preset_name="general", suite_name="kzg-mainnet")
@only_generator("too slow")
@with_phases([DENEB])
@spec_test
@single_phase
def the_test(spec):
commitment = spec.blob_to_kzg_commitment(blob)
challenge = spec.compute_challenge(blob, commitment)

yield (
"data",
"data",
{
"input": {
"blob": encode_hex(blob),
"commitment": encode_hex(commitment),
},
"output": encode_hex(spec.bls_field_to_bytes(challenge)),
},
)

return (the_test, f"test_compute_challenge_case_valid_{blob_index}")


for blob_index in range(len(VALID_BLOBS)):
_compute_challenge_case_valid(blob_index)


@manifest(preset_name="general", suite_name="kzg-mainnet")
@only_generator("too slow")
@with_phases([DENEB])
@spec_test
@single_phase
def test_compute_challenge_case_mismatched_commitment(spec):
# Use commitment from a different blob
commitment = spec.blob_to_kzg_commitment(VALID_BLOBS[4])
blob = VALID_BLOBS[3]
challenge = spec.compute_challenge(blob, commitment)

yield (
"data",
"data",
{
"input": {
"blob": encode_hex(blob),
"commitment": encode_hex(commitment),
},
"output": encode_hex(spec.bls_field_to_bytes(challenge)),
},
)


@manifest(preset_name="general", suite_name="kzg-mainnet")
@only_generator("too slow")
@with_phases([DENEB])
@spec_test
@single_phase
def test_compute_challenge_case_commitment_at_infinity(spec):
commitment = spec.G1_POINT_AT_INFINITY
blob = VALID_BLOBS[4]
challenge = spec.compute_challenge(blob, commitment)

yield (
"data",
"data",
{
"input": {
"blob": encode_hex(blob),
"commitment": encode_hex(commitment),
},
"output": encode_hex(spec.bls_field_to_bytes(challenge)),
},
)
127 changes: 127 additions & 0 deletions tests/core/pyspec/eth2spec/test/deneb/kzg/test_compute_kzg_proof.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
###############################################################################
# Test cases for compute_kzg_proof
###############################################################################

from eth_utils import encode_hex

from eth2spec.test.context import only_generator, single_phase, spec_test, with_phases
from eth2spec.test.helpers.constants import DENEB
from eth2spec.test.utils.kzg_tests import (
INVALID_BLOBS,
INVALID_FIELD_ELEMENTS,
VALID_BLOBS,
VALID_FIELD_ELEMENTS,
)
from tests.infra.manifest import manifest
from tests.infra.template_test import template_test


@template_test
def _compute_kzg_proof_case_valid(blob_index, z_index):
blob = VALID_BLOBS[blob_index]
z = VALID_FIELD_ELEMENTS[z_index]

@manifest(preset_name="general", suite_name="kzg-mainnet")
@only_generator("too slow")
@with_phases([DENEB])
@spec_test
@single_phase
def the_test(spec):
proof, y = spec.compute_kzg_proof(blob, z)

yield (
"data",
"data",
{
"input": {
"blob": encode_hex(blob),
"z": encode_hex(z),
},
"output": (encode_hex(proof), encode_hex(y)),
},
)

return (the_test, f"test_compute_kzg_proof_case_valid_blob_{blob_index}_{z_index}")


for blob_index in range(len(VALID_BLOBS)):
for z_index in range(len(VALID_FIELD_ELEMENTS)):
_compute_kzg_proof_case_valid(blob_index, z_index)


@template_test
def _compute_kzg_proof_case_invalid_blob(blob_index):
blob = INVALID_BLOBS[blob_index]
z = VALID_FIELD_ELEMENTS[0]

@manifest(preset_name="general", suite_name="kzg-mainnet")
@only_generator("too slow")
@with_phases([DENEB])
@spec_test
@single_phase
def the_test(spec):
try:
proof, y = spec.compute_kzg_proof(blob, z)
output = (encode_hex(proof), encode_hex(y))
except Exception:
output = None

# assert exception is thrown
assert output == None

yield (
"data",
"data",
{
"input": {
"blob": encode_hex(blob),
"z": encode_hex(z),
},
"output": output,
},
)

return (the_test, f"test_compute_kzg_proof_case_invalid_blob_{blob_index}")


for blob_index in range(len(INVALID_BLOBS)):
_compute_kzg_proof_case_invalid_blob(blob_index)


@template_test
def _compute_kzg_proof_case_invalid_z(z_index):
blob = VALID_BLOBS[4]
z = INVALID_FIELD_ELEMENTS[z_index]

@manifest(preset_name="general", suite_name="kzg-mainnet")
@only_generator("too slow")
@with_phases([DENEB])
@spec_test
@single_phase
def the_test(spec):
try:
proof, y = spec.compute_kzg_proof(blob, z)
output = (encode_hex(proof), encode_hex(y))
except Exception:
output = None

# assert exception is thrown
assert output == None

yield (
"data",
"data",
{
"input": {
"blob": encode_hex(blob),
"z": encode_hex(z),
},
"output": output,
},
)

return (the_test, f"test_compute_kzg_proof_case_invalid_z_{z_index}")


for z_index in range(len(INVALID_FIELD_ELEMENTS)):
_compute_kzg_proof_case_invalid_z(z_index)
Loading