Skip to content

Commit acc4699

Browse files
committed
fix comment
1 parent 18d43d5 commit acc4699

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

src/lean_spec/subspecs/poseidon2/permutation.py

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -68,35 +68,27 @@ def check_vector_length(self) -> "Poseidon2Params":
6868
return self
6969

7070

71-
def _generate_round_constants(params: Poseidon2Params) -> List[Fp]:
71+
def _generate_spec_test_round_constants(params: Poseidon2Params) -> List[Fp]:
7272
"""
73-
Generates a deterministic list of round constants for the permutation.
73+
Generates a deterministic list of round constants for testing the spec.
7474
75-
Round constants are added in each round to break symmetries and prevent
76-
attacks like slide or interpolation attacks.
75+
!!! WARNING !!!
76+
This function produces a simple, predictable sequence of integers for the
77+
sole purpose of testing the permutation's algebraic structure. Production
78+
implementations MUST use constants generated from a secure,
79+
unpredictable source.
7780
7881
Args:
7982
params: The object defining the permutation's configuration.
8083
8184
Returns:
82-
A list of Fp elements to be used as round constants.
85+
A list of Fp elements to be used as round constants for tests.
8386
"""
8487
# The total number of constants needed for the entire permutation.
85-
#
86-
# This is the sum of constants for all full rounds and all partial rounds.
87-
# - Full rounds require `width` constants each
88-
# (one for each state element).
89-
# - Partial rounds require 1 constant each
90-
# (for the first state element).
9188
total_constants = (params.rounds_f * params.width) + params.rounds_p
9289

93-
# For the specification, we generate the constants as a deterministic d
94-
# sequence of integers.
95-
#
96-
# This is sufficient to define the algorithm's mechanics.
97-
#
98-
# Real-world implementations would use constants generated from a secure,
99-
# pseudo-random source.
90+
# For the specification, we generate the constants as a deterministic
91+
# sequence of integers. This is sufficient to define the mechanics.
10092
return [Fp(value=i) for i in range(total_constants)]
10193

10294

@@ -295,7 +287,7 @@ def permute(state: List[Fp], params: Poseidon2Params) -> List[Fp]:
295287
raise ValueError(f"Input state must have length {params.width}")
296288

297289
# Generate the deterministic round constants for this parameter set.
298-
round_constants = _generate_round_constants(params)
290+
round_constants = _generate_spec_test_round_constants(params)
299291
# The number of full rounds is split between the beginning and end.
300292
half_rounds_f = params.rounds_f // 2
301293
# Initialize index for accessing the flat list of round constants.

0 commit comments

Comments
 (0)