@@ -47,8 +47,27 @@ def _test_correctness_roundtrip(
4747 #
4848 # Verification must fail if the message is tampered with.
4949 tampered_message = b"\x43 " * scheme .config .MESSAGE_LENGTH
50- is_invalid_msg = scheme .verify (pk , test_epoch , tampered_message , signature )
51- assert not is_invalid_msg , "Verification succeeded for a tampered message"
50+
51+ # With small test parameters (test configuration), there's a small chance that
52+ # the tampered message produces the same codeword as the original due to
53+ # modular reduction collision.
54+ #
55+ # In that case, verification will succeed, which is expected behavior for identical codewords.
56+ #
57+ # We detect this by checking if both messages encode to the same codeword.
58+ original_codeword = scheme .encoder .encode (pk .parameter , message , signature .rho , test_epoch )
59+ tampered_codeword = scheme .encoder .encode (
60+ pk .parameter , tampered_message , signature .rho , test_epoch
61+ )
62+
63+ if tampered_codeword != original_codeword :
64+ # Different codewords: verification must fail
65+ is_invalid_msg = scheme .verify (pk , test_epoch , tampered_message , signature )
66+ assert not is_invalid_msg , "Verification succeeded for a tampered message"
67+ else :
68+ # Codeword collision: verification succeeds (expected with small test parameters)
69+ is_collision_valid = scheme .verify (pk , test_epoch , tampered_message , signature )
70+ assert is_collision_valid , "Verification failed despite identical codewords"
5271
5372 # Verification must fail if the epoch is incorrect.
5473 if num_active_epochs > 1 :
0 commit comments