Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
25 changes: 17 additions & 8 deletions packages/testing/src/consensus_testing/pytest_plugins/filler.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
from consensus_testing.crypto_mode import AggregationProver, CryptoMode
from consensus_testing.forks import FORKS_BY_NAME
from consensus_testing.keys import DEFAULT_MAX_SLOT, XmssKeyManager
from consensus_testing.test_fixtures import FIXTURE_FORMATS, FixtureInfo
from consensus_testing.test_fixtures import (
FIXTURE_FORMATS,
PROOF_FAILURE_REJECTION_REASONS,
FixtureInfo,
ProofSetting,
)
from lean_spec.spec.forks import Slot, ValidatorIndex
from lean_spec.spec.ssz import Bytes32

Expand Down Expand Up @@ -450,15 +455,19 @@ def fill_and_collect(**spec_fields: Any) -> Any:
else:
generated_fixture = test_spec.generate()

# - 0 mocked,
# - 1 real and must verify,
# - 2 real and must fail verification.
# A mocked proof is never verified.
# A real proof must fail only when the rejection is itself a proof failure.
# A non-crypto rejection (such as an unknown parent) still carries a valid proof.
expected_rejection = test_spec.expected_rejection
if mock_prover:
proof_setting = 0
elif test_spec.expected_rejection is not None:
proof_setting = 2
proof_setting = ProofSetting.MOCKED
elif (
expected_rejection is not None
and expected_rejection.reason in PROOF_FAILURE_REJECTION_REASONS
):
proof_setting = ProofSetting.REAL_AND_INVALID
else:
proof_setting = 1
proof_setting = ProofSetting.REAL_AND_VALID

filled_fixture = generated_fixture.with_info(
info=FixtureInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

from consensus_testing.test_fixtures.api_endpoint import ApiEndpointFixture, ApiEndpointTest
from consensus_testing.test_fixtures.base import (
PROOF_FAILURE_REJECTION_REASONS,
BaseConsensusFixture,
BaseTestSpec,
ExpectedRejection,
FixtureInfo,
ProofSetting,
)
from consensus_testing.test_fixtures.fork_choice import ForkChoiceFixture, ForkChoiceTest
from consensus_testing.test_fixtures.gossipsub_handler import (
Expand Down Expand Up @@ -159,6 +161,8 @@
"BaseTestSpec",
"ExpectedRejection",
"FixtureInfo",
"ProofSetting",
"PROOF_FAILURE_REJECTION_REASONS",
"StateTransitionFixture",
"StateTransitionTest",
"ForkChoiceFixture",
Expand Down
30 changes: 22 additions & 8 deletions packages/testing/src/consensus_testing/test_fixtures/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import hashlib
import json
from abc import abstractmethod
from enum import IntEnum
from functools import cached_property
from typing import Any, ClassVar, Self

Expand Down Expand Up @@ -58,6 +59,25 @@ class ExpectedRejection(StrictBaseModel):
"""


class ProofSetting(IntEnum):
"""Aggregation proof regime emitted with each fixture."""

MOCKED = 0
"""The proof is mocked and must not be verified."""

REAL_AND_VALID = 1
"""The proof is real and must verify."""

REAL_AND_INVALID = 2
"""The proof is real and must fail verification."""


PROOF_FAILURE_REJECTION_REASONS: frozenset[RejectionReason] = frozenset(
{RejectionReason.INVALID_SIGNATURE, RejectionReason.INVALID_BLOCK_PROOF}
)
"""Rejection reasons whose direct cause is the aggregation proof failing to verify."""


class BaseConsensusFixture(CamelModel):
"""
Base class for all consensus test fixtures.
Expand Down Expand Up @@ -93,14 +113,8 @@ class BaseConsensusFixture(CamelModel):
This is the field clients assert against.
"""

proof_setting: int = 0
"""
Aggregation proof regime, mirroring eth2's bls_setting.

- 0 means the proof is mocked and must not be verified.
- 1 means the proof is real and must verify.
- 2 means the proof is real and must fail verification.
"""
proof_setting: ProofSetting = ProofSetting.MOCKED
"""Aggregation proof regime, emitted as an integer; each value documents its own meaning."""

def with_info(self, info: FixtureInfo, network: str) -> Self:
"""
Expand Down
Loading