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 2 commits into
base: main
Choose a base branch
from
Draft

Precompile for Poseidon2 BabyBear #1807

wants to merge 2 commits into from

Conversation

lvella
Copy link
Member

@lvella lvella commented Sep 16, 2024

No description provided.

array::zip(state, c, |state, c| (state' - c) * (1-LAST) = 0);

// In the last row, the first OUTPUT_SIZE elements of the state should equal output
array::zip(output, state, |output, state| LASTBLOCK * (output - state) = 0);
Copy link
Member

@chriseth chriseth Sep 19, 2024

Choose a reason for hiding this comment

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

Please apply this fix accordingly, otherwise it will break once #1806 is merged:
12ffb9f

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).

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