Skip to content

cryptography: replace Poseidon2 by Poseidon1#456

Open
tcoratger wants to merge 2 commits intoleanEthereum:mainfrom
tcoratger:poseidon11
Open

cryptography: replace Poseidon2 by Poseidon1#456
tcoratger wants to merge 2 commits intoleanEthereum:mainfrom
tcoratger:poseidon11

Conversation

@tcoratger
Copy link
Collaborator

🗒️ Description

Checked against the following Rust tests in Plonky3:

    /// Reference test vectors for leanSpec Python implementation.
    ///
    /// Run with: `cargo test -p p3-koala-bear test_poseidon1_leanspec_reference`
    ///
    /// These vectors are used in the leanSpec Python tests
    /// (tests/lean_spec/subspecs/poseidon1/test_permutation.py).
    /// If this test passes, the Python implementation should produce identical output.
    #[test]
    fn test_poseidon1_leanspec_reference_width_16() {
        let perm = default_koalabear_poseidon1_16();

        // Input: [0, 1, 2, ..., 15]
        let mut state: [F; 16] =
            F::new_array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]);

        perm.permute_mut(&mut state);

        // These expected values must match the Python test vectors exactly.
        let expected: [F; 16] = F::new_array([
            610090613, 935319874, 1893335292, 796792199, 356405232, 552237741, 55134556,
            1215104204, 1823723405, 1133298033, 1780633798, 1453946561, 710069176, 1128629550,
            1917333254, 1175481618,
        ]);
        assert_eq!(state, expected, "Width-16 reference vector mismatch");
    }

    #[test]
    fn test_poseidon1_leanspec_reference_width_24() {
        let perm = default_koalabear_poseidon1_24();

        // Input: [0, 1, 2, ..., 23]
        let mut state: [F; 24] = F::new_array([
            0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
            23,
        ]);

        perm.permute_mut(&mut state);

        // These expected values must match the Python test vectors exactly.
        let expected: [F; 24] = F::new_array([
            511672087, 215882318, 237782537, 740528428, 712760904, 54615367, 751514671, 110231969,
            1905276435, 992525666, 918312360, 18628693, 749929200, 1916418953, 691276896,
            1112901727, 1163558623, 882867603, 673396520, 1480278156, 1402044758, 1693467175,
            1766273044, 433841551,
        ]);
        assert_eq!(state, expected, "Width-24 reference vector mismatch");
    }

🔗 Related Issues or PRs

✅ Checklist

  • Ran tox checks to avoid unnecessary CI fails:
    uvx tox
  • Considered adding appropriate tests for the changes.
  • Considered updating the online docs in the ./docs/ directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant