Skip to content

Commit 8427ad5

Browse files
authored
test: fix signature SSZ test vectors and remove irrelevant tests (#437)
1 parent 79a347b commit 8427ad5

File tree

1 file changed

+14
-150
lines changed

1 file changed

+14
-150
lines changed

tests/consensus/devnet/ssz/test_xmss_containers.py

Lines changed: 14 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,20 @@
22

33
import pytest
44
from consensus_testing import SSZTestFiller
5+
from consensus_testing.keys import create_dummy_signature, get_shared_key_manager
56

7+
from lean_spec.subspecs.containers import ValidatorIndex
68
from lean_spec.subspecs.containers.attestation import AggregationBits
79
from lean_spec.subspecs.containers.slot import Slot
810
from lean_spec.subspecs.koalabear import Fp
9-
from lean_spec.subspecs.xmss import PublicKey, SecretKey, Signature
11+
from lean_spec.subspecs.xmss import PublicKey
1012
from lean_spec.subspecs.xmss.aggregation import AggregatedSignatureProof
11-
from lean_spec.subspecs.xmss.subtree import HashSubTree
1213
from lean_spec.subspecs.xmss.types import (
1314
HASH_DIGEST_LENGTH,
14-
HashDigestList,
1515
HashDigestVector,
16-
HashTreeLayer,
17-
HashTreeLayers,
18-
HashTreeOpening,
1916
Parameter,
20-
PRFKey,
2117
)
22-
from lean_spec.types import Boolean, ByteListMiB, Uint64
18+
from lean_spec.types import Boolean, ByteListMiB, Bytes32
2319

2420
pytestmark = pytest.mark.valid_until("Devnet")
2521

@@ -48,151 +44,19 @@ def test_public_key_zero(ssz: SSZTestFiller) -> None:
4844

4945
# --- Signature ---
5046

51-
# Empty path: path=[], rho=zeros, hashes=[]
52-
SIGNATURE_EMPTY_PATH = bytes.fromhex(
53-
"24000000000000000000000000000000000000000000000000000000000000002800000004000000"
54-
)
55-
56-
# With siblings: path=[zero, zero], rho=zeros, hashes=[zero]
57-
SIGNATURE_WITH_SIBLINGS = bytes.fromhex(
58-
"24000000000000000000000000000000000000000000000000000000000000006800000004000000"
59-
"0000000000000000000000000000000000000000000000000000000000000000"
60-
"0000000000000000000000000000000000000000000000000000000000000000"
61-
"0000000000000000000000000000000000000000000000000000000000000000"
62-
)
63-
64-
65-
def test_signature_empty_path(ssz: SSZTestFiller) -> None:
66-
"""SSZ roundtrip for Signature with empty authentication path."""
67-
ssz(type_name="Signature", value=Signature.decode_bytes(SIGNATURE_EMPTY_PATH))
68-
69-
70-
def test_signature_with_siblings(ssz: SSZTestFiller) -> None:
71-
"""SSZ roundtrip for Signature with authentication path siblings."""
72-
ssz(type_name="Signature", value=Signature.decode_bytes(SIGNATURE_WITH_SIBLINGS))
73-
74-
75-
# --- SecretKey ---
76-
77-
78-
def test_secret_key_minimal(ssz: SSZTestFiller) -> None:
79-
"""SSZ roundtrip for SecretKey with minimal values."""
80-
empty_subtree = HashSubTree(
81-
depth=Uint64(4),
82-
lowest_layer=Uint64(0),
83-
layers=HashTreeLayers(data=[]),
84-
)
85-
ssz(
86-
type_name="SecretKey",
87-
value=SecretKey(
88-
prf_key=PRFKey.zero(),
89-
parameter=_zero_parameter(),
90-
activation_slot=Slot(0),
91-
num_active_slots=Uint64(1),
92-
top_tree=empty_subtree,
93-
left_bottom_tree_index=Uint64(0),
94-
left_bottom_tree=empty_subtree,
95-
right_bottom_tree=empty_subtree,
96-
),
97-
)
98-
99-
100-
# --- HashTreeOpening ---
101-
102-
103-
def test_hash_tree_opening_empty(ssz: SSZTestFiller) -> None:
104-
"""SSZ roundtrip for HashTreeOpening with no siblings."""
105-
ssz(
106-
type_name="HashTreeOpening",
107-
value=HashTreeOpening(siblings=HashDigestList(data=[])),
108-
)
109-
110-
111-
def test_hash_tree_opening_single(ssz: SSZTestFiller) -> None:
112-
"""SSZ roundtrip for HashTreeOpening with single sibling."""
113-
ssz(
114-
type_name="HashTreeOpening",
115-
value=HashTreeOpening(siblings=HashDigestList(data=[_zero_hash_digest_vector()])),
116-
)
117-
118-
119-
def test_hash_tree_opening_multiple(ssz: SSZTestFiller) -> None:
120-
"""SSZ roundtrip for HashTreeOpening with multiple siblings."""
121-
ssz(
122-
type_name="HashTreeOpening",
123-
value=HashTreeOpening(
124-
siblings=HashDigestList(
125-
data=[
126-
_zero_hash_digest_vector(),
127-
_zero_hash_digest_vector(),
128-
_zero_hash_digest_vector(),
129-
]
130-
)
131-
),
132-
)
133-
134-
135-
# --- HashTreeLayer ---
136-
137-
138-
def test_hash_tree_layer_empty(ssz: SSZTestFiller) -> None:
139-
"""SSZ roundtrip for HashTreeLayer with no nodes."""
140-
ssz(
141-
type_name="HashTreeLayer",
142-
value=HashTreeLayer(start_index=Uint64(0), nodes=HashDigestList(data=[])),
143-
)
14447

145-
146-
def test_hash_tree_layer_single(ssz: SSZTestFiller) -> None:
147-
"""SSZ roundtrip for HashTreeLayer with single node."""
148-
ssz(
149-
type_name="HashTreeLayer",
150-
value=HashTreeLayer(
151-
start_index=Uint64(0),
152-
nodes=HashDigestList(data=[_zero_hash_digest_vector()]),
153-
),
154-
)
48+
def test_signature_zero(ssz: SSZTestFiller) -> None:
49+
"""SSZ roundtrip for Signature with zero values."""
50+
ssz(type_name="Signature", value=create_dummy_signature())
15551

15652

157-
def test_hash_tree_layer_multiple(ssz: SSZTestFiller) -> None:
158-
"""SSZ roundtrip for HashTreeLayer with multiple nodes."""
159-
ssz(
160-
type_name="HashTreeLayer",
161-
value=HashTreeLayer(
162-
start_index=Uint64(4),
163-
nodes=HashDigestList(data=[_zero_hash_digest_vector(), _zero_hash_digest_vector()]),
164-
),
165-
)
166-
167-
168-
# --- HashSubTree ---
169-
170-
171-
def test_hash_subtree_empty(ssz: SSZTestFiller) -> None:
172-
"""SSZ roundtrip for HashSubTree with no layers."""
173-
ssz(
174-
type_name="HashSubTree",
175-
value=HashSubTree(depth=Uint64(4), lowest_layer=Uint64(0), layers=HashTreeLayers(data=[])),
176-
)
177-
178-
179-
def test_hash_subtree_with_layers(ssz: SSZTestFiller) -> None:
180-
"""SSZ roundtrip for HashSubTree with layers."""
181-
ssz(
182-
type_name="HashSubTree",
183-
value=HashSubTree(
184-
depth=Uint64(4),
185-
lowest_layer=Uint64(0),
186-
layers=HashTreeLayers(
187-
data=[
188-
HashTreeLayer(
189-
start_index=Uint64(0),
190-
nodes=HashDigestList(data=[_zero_hash_digest_vector()]),
191-
)
192-
]
193-
),
194-
),
195-
)
53+
def test_signature_actual(ssz: SSZTestFiller) -> None:
54+
"""SSZ roundtrip for a cryptographically valid Signature produced by signing."""
55+
key_manager = get_shared_key_manager()
56+
scheme = key_manager.scheme
57+
_, sk = key_manager.keys[ValidatorIndex(0)]
58+
signature = scheme.sign(sk, Slot(0), Bytes32(b"\x42" * 32))
59+
ssz(type_name="Signature", value=signature)
19660

19761

19862
# --- AggregatedSignatureProof ---

0 commit comments

Comments
 (0)