Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Precompile for Poseidon2 BabyBear #1807

Draft
wants to merge 23 commits into
base: incr_addr
Choose a base branch
from
Draft

Precompile for Poseidon2 BabyBear #1807

wants to merge 23 commits into from

Conversation

lvella
Copy link
Member

@lvella lvella commented Sep 16, 2024

No description provided.

PARTIAL * (a[i] - x7[i]) + x7[i]
});

// The MDS matrix
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be shared across the different poseidon implementations?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because the power you use for the S-Box depends on the field. But 7 is used both by BabyBear and Goldilocks.

pol constant PARTIAL = [0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0]*;

// The round constants
pol constant C_0 = [0xb585f766f2144405, 0x86287821f722c881, 0xe9fa634a21de0082, 0x92a756e67e2b9413, 0x3cc3f892184df408, 0x7131aa45268d7d8c, 0x99ad1aab0814283b, 0xeb84f608da56ef48, 0x7159cd30c3ac118e, 0xdcef0797c2b69ec7, 0xd0762cbc8ca6570c, 0x30a4680593258387, 0x15a16a8a8322d458, 0x5a3f1bb1c53a9645, 0x775005982d74d7f7, 0xf9cc95c22b4c1fcc, 0xc49366bb25e8513, 0xdd611f1000c17442, 0x2ff876fa5ef97c4, 0x3d06c8bd1514e2d9, 0xe89cd854d5d01d33, 0xece5a71e0cfedc75, 0x90004c1371b893c5, 0xde122bebe9a39368, 0x4d61e56a525d225a, 0x1478d361dbbf9fac, 0x475cd3205a3bdcde, 0xe70201e960cb78b8, 0x7be5b9ffda905e1c, 0xf3c12fe54d5c653b, 0x0]*;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can these be shared across the different poseidon implementations?

Copy link
Member Author

@lvella lvella Sep 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because the number of rounds depends on the state length, which depends on the field size. Also these constants don't fit in BabyBear (they are just a copy of Goldilocks impl).


// External round MDS matrix
let MDS = [
[4, 6, 2, 2, 2, 3, 1, 1, 2, 3, 1, 1, 2, 3, 1, 1],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we please avoid copying these magic constants across 4-5 files?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are not. The only other place most of these constants appear is inside plonky3 rust code.

The best I can do is, after merging this branch with the poseidon_bb one, place a fraction of the big list of random numbers that is common between the two of them in a separate file, as they are the output of the same deterministic RNG.

@lvella lvella changed the base branch from main to incr_addr October 22, 2024 18:47
@lvella
Copy link
Member Author

lvella commented Oct 23, 2024

Blocked on #1933.

@lvella lvella requested a review from chriseth October 23, 2024 15:25
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.

2 participants