Skip to content

Commit 3205db8

Browse files
committed
docs: update docs
1 parent 97e8de1 commit 3205db8

File tree

6 files changed

+211
-215
lines changed

6 files changed

+211
-215
lines changed

packages/testing/src/consensus_testing/test_types/block_spec.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,13 @@ class BlockSpec(CamelModel):
100100

101101
valid_signature: bool = True
102102
"""
103-
If False, the proposer attestation will be given a dummy/invalid signature.
103+
Flag whether the proposer's signature in generated block should be valid.
104104
105105
Used for testing that verification properly rejects invalid block signatures.
106106
When False, a structurally valid but cryptographically invalid signature
107107
(all zeros) will be generated for the proposer attestation instead of a
108108
proper XMSS signature.
109109
110-
Default is True (valid signatures).
110+
Defaults to True (valid signature).
111+
If False, the proposer attestation will be given a dummy/invalid signature.
111112
"""

packages/testing/src/consensus_testing/test_types/signed_attestation_spec.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,12 @@ class SignedAttestationSpec(CamelModel):
3838

3939
valid_signature: bool = True
4040
"""
41-
If False, this attestation will be given a dummy/invalid signature.
41+
Flag whether the generated attestation signature should be valid.
4242
43-
Used for testing that verification properly rejects invalid signatures.
43+
Used for testing that verification properly rejects invalid attestation signatures.
4444
When False, a structurally valid but cryptographically invalid signature
45-
(all zeros) will be generated instead of a proper XMSS signature.
45+
(all zeros) will be generated for the attestation instead of a proper XMSS signature.
46+
47+
Defaults to True (valid signature).
48+
If False, the attestation will be given a dummy/invalid signature.
4649
"""

src/lean_spec/subspecs/koalabear/field.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,29 +105,28 @@ def __get_pydantic_core_schema__(
105105
cls, source_type: Any, handler: GetCoreSchemaHandler
106106
) -> core_schema.CoreSchema:
107107
"""
108-
Hook into Pydantic's validation system.
108+
Hook into Pydantic's validation system for strict field element validation.
109109
110-
This schema defines how to handle the Fp field element type:
111-
1. If the input is already an Fp instance, accept it.
112-
2. Otherwise, validate the input as an integer within [0, P)
113-
and then instantiate Fp.
114-
3. For serialization (e.g., to JSON), convert to a plain int.
110+
This schema ensures that only values in the range [0, P) are accepted
111+
during Pydantic model validation.
115112
"""
116113
# Validator that takes an integer and returns an Fp instance
117114
from_int_validator = core_schema.no_info_plain_validator_function(cls)
118115

119-
# Schema that first validates the input as an int, then calls our validator
116+
# Schema that first validates the input as an int in the range [0, P),
117+
# then calls our validator
120118
python_schema = core_schema.chain_schema(
121119
[core_schema.int_schema(ge=0, lt=P, strict=True), from_int_validator]
122120
)
123121

124122
return core_schema.union_schema(
125123
[
126-
# Case 1: The value is already the correct type
124+
# Case 1: The value is already our field element type
127125
core_schema.is_instance_schema(cls),
128-
# Case 2: The value needs to be parsed and validated
126+
# Case 2: The value is a standard int and needs to be parsed and validated
129127
python_schema,
130128
],
129+
# For serialization (e.g., to JSON), convert the instance back to a plain int.
131130
serialization=core_schema.plain_serializer_function_ser_schema(
132131
lambda x: x.value, return_schema=core_schema.int_schema()
133132
),

tests/consensus/devnet/verify_signature/test_basic_signature.py

Lines changed: 0 additions & 201 deletions
This file was deleted.
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
"""Invalid signature verification tests"""
2+
3+
import pytest
4+
from consensus_testing import (
5+
BlockSpec,
6+
VerifySignatureTestFiller,
7+
SignedAttestationSpec,
8+
generate_pre_state,
9+
)
10+
11+
from lean_spec.subspecs.containers.slot import Slot
12+
from lean_spec.types import Uint64
13+
14+
pytestmark = pytest.mark.valid_until("Devnet")
15+
16+
17+
def test_invalid_signature(
18+
verify_signature_test: VerifySignatureTestFiller,
19+
) -> None:
20+
"""
21+
Test that invalid signatures are properly rejected during verification.
22+
23+
Scenario
24+
--------
25+
- Single block at slot 1
26+
- Proposer attestation has an invalid signature
27+
- No additional attestations (only proposer attestation)
28+
29+
Expected Behavior
30+
-----------------
31+
1. Proposer's signature in SignedBlockWithAttestation is rejected
32+
33+
Why This Matters
34+
----------------
35+
This test verifies the negative case:
36+
- Signature verification actually validates cryptographic correctness
37+
not just structural correctness.
38+
- Invalid signatures are caught, not silently accepted
39+
"""
40+
verify_signature_test(
41+
anchor_state=generate_pre_state(num_validators=1),
42+
block=BlockSpec(
43+
slot=Slot(1),
44+
attestations=[],
45+
valid_signature=False,
46+
),
47+
expect_exception=AssertionError,
48+
)
49+
50+
def test_mixed_valid_invalid_signatures(
51+
verify_signature_test: VerifySignatureTestFiller,
52+
) -> None:
53+
"""
54+
Test that signature verification catches invalid signatures among valid ones.
55+
56+
Scenario
57+
--------
58+
- Single block at slot 1
59+
- Proposer attestation from validator 1
60+
- 2 non-proposer attestations from validators 0 and 2
61+
- Total: 3 signatures, middle attestation (validator 2) has an invalid signature
62+
63+
Expected Behavior
64+
-----------------
65+
1. The SignedBlockWithAttestation is rejected due to 1 invalid signature
66+
67+
Why This Matters
68+
----------------
69+
This test verifies that signature verification:
70+
- Checks every signature individually, not just the first or last
71+
- Cannot be bypassed by surrounding invalid signatures with valid ones
72+
- Properly fails even when some signatures are valid
73+
- Validates all attestations in the block
74+
"""
75+
verify_signature_test(
76+
anchor_state=generate_pre_state(num_validators=3),
77+
block=BlockSpec(
78+
slot=Slot(1),
79+
attestations=[
80+
SignedAttestationSpec(
81+
validator_id=Uint64(0),
82+
slot=Slot(1),
83+
target_slot=Slot(0),
84+
target_root_label="genesis",
85+
),
86+
SignedAttestationSpec(
87+
validator_id=Uint64(2),
88+
slot=Slot(1),
89+
target_slot=Slot(0),
90+
target_root_label="genesis",
91+
valid_signature=False,
92+
),
93+
],
94+
),
95+
expect_exception=AssertionError,
96+
)

0 commit comments

Comments
 (0)