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

Add GrainLFRS and PrimeField trait to Poseidon #51

Merged
merged 4 commits into from
Sep 27, 2022
Merged

Conversation

s1fr0
Copy link
Contributor

@s1fr0 s1fr0 commented Sep 26, 2022

Implements the first two steps of #50.

@s1fr0 s1fr0 added the track:zerokit Zerokit track (Applied ZK/Explorations) label Sep 26, 2022
@s1fr0 s1fr0 requested a review from oskarth September 26, 2022 11:06
@s1fr0 s1fr0 self-assigned this Sep 26, 2022
Copy link
Contributor

@oskarth oskarth left a comment

Choose a reason for hiding this comment

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

We need to audit this code at some point...

I can't give good review, but seems... reasonable?

We would like to have a self-contained poseidon module that works natively with arkworks traits, so that round parameters and constants are generated directly from the field characteristic and not hard-coded as now are. This will further enable current and future zerokit modules that use it to access the same Poseidon implementation.

Can you elaborate a bit on a specific example task that becomes easier to do with this? Can't quite picture it right now.

@s1fr0
Copy link
Contributor Author

s1fr0 commented Sep 27, 2022

The two main advantages I see are: i) re-use the same implementation across different modules (and if we need to change/improve something we do it in just one place); ii) be able to instantiate Poseidon on different curves/scalar fields (in case we need to increase the security level to >=128 bits).

Another minor advantage: don't mess-up in copy/pasting/verifying round constants (especially when using different curves).

@oskarth
Copy link
Contributor

oskarth commented Sep 27, 2022

The first point seems orthogonal to the adding of traits (unless I missed something?), but agree with the second point!

Copy link
Contributor

@oskarth oskarth left a comment

Choose a reason for hiding this comment

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

LGTM assuming tested with nwaku e.g.

@s1fr0
Copy link
Contributor Author

s1fr0 commented Sep 27, 2022

I think usage gets clearer in #53 and https://github.com/vacp2p/zerokit/blob/e4767328cda90464fcf8ab299d2488c3671895d8/rln/src/poseidon_hash.rs, i.e. when this implementation is moved to a separate module that accepts traits. Then in your module, e.g. rln, it is enough to instantiate a static poseidon by passing the curve scalar field and (only for now) the round parameters. Constants will then be generated accordingly to the field and round parameters and poseidon would then be ready within your module. Without traits this would not be possible.

@s1fr0
Copy link
Contributor Author

s1fr0 commented Sep 27, 2022

Successfully tested with nwaku. Will merge

@s1fr0 s1fr0 merged commit c42fcfe into master Sep 27, 2022
@s1fr0 s1fr0 deleted the add-lfsr-poseidon branch September 27, 2022 15:18
@s1fr0 s1fr0 linked an issue Sep 28, 2022 that may be closed by this pull request
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
track:zerokit Zerokit track (Applied ZK/Explorations)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generate Poseidon round parameters and constants
3 participants