@@ -99,3 +99,64 @@ def test_permutation_vector(
9999 assert output_state == expected_output , (
100100 f"Permutation output for width { params .width } did not match."
101101 )
102+
103+
104+ class TestPoseidon1ParamsValidation :
105+ """Tests for Poseidon1Params validation."""
106+
107+ def test_invalid_mds_first_row_length (self ) -> None :
108+ """Raises error when mds_first_row length doesn't match width."""
109+ with pytest .raises (ValueError , match = "Length of mds_first_row must equal width" ):
110+ Poseidon1Params (
111+ width = 3 ,
112+ rounds_f = 8 ,
113+ rounds_p = 20 ,
114+ mds_first_row = [Fp (1 ), Fp (2 )],
115+ round_constants = [Fp (1 )] * 84 ,
116+ )
117+
118+ def test_invalid_round_constants_count (self ) -> None :
119+ """Raises error when round_constants count is incorrect."""
120+ with pytest .raises (ValueError , match = "Incorrect number of round constants" ):
121+ Poseidon1Params (
122+ width = 3 ,
123+ rounds_f = 8 ,
124+ rounds_p = 20 ,
125+ mds_first_row = [Fp (1 ), Fp (2 ), Fp (3 )],
126+ round_constants = [Fp (1 )] * 20 ,
127+ )
128+
129+
130+ class TestPoseidon1Engine :
131+ """Tests for Poseidon1 engine."""
132+
133+ def test_permute_wrong_state_length_too_short (self ) -> None :
134+ """Raises error when input state is too short."""
135+ engine = Poseidon1 (PARAMS_16 )
136+ with pytest .raises (ValueError , match = "Input state must have length 16" ):
137+ engine .permute ([Fp (1 )] * 10 )
138+
139+ def test_permute_wrong_state_length_too_long (self ) -> None :
140+ """Raises error when input state is too long."""
141+ engine = Poseidon1 (PARAMS_16 )
142+ with pytest .raises (ValueError , match = "Input state must have length 16" ):
143+ engine .permute ([Fp (1 )] * 20 )
144+
145+ def test_permute_determinism (self ) -> None :
146+ """Same input produces same output."""
147+ engine = Poseidon1 (PARAMS_16 )
148+ state = [Fp (value = i ) for i in range (16 )]
149+
150+ output1 = engine .permute (state )
151+ output2 = engine .permute (state )
152+
153+ assert output1 == output2
154+
155+ def test_permute_output_differs_from_input (self ) -> None :
156+ """Permutation changes the state."""
157+ engine = Poseidon1 (PARAMS_16 )
158+ state = [Fp (value = i ) for i in range (16 )]
159+
160+ output = engine .permute (state )
161+
162+ assert output != state
0 commit comments