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

Poseidon primitive #41

Merged
merged 15 commits into from
Mar 25, 2021
Merged

Poseidon primitive #41

merged 15 commits into from
Mar 25, 2021

Conversation

str4d
Copy link
Contributor

@str4d str4d commented Mar 11, 2021

The Orchard specification defines PoseidonHash in the simplest way as 𝑓([𝑥, 𝑦, 265])[0], but this PR implements the duplex sponge explicitly to make the sponge construction clear.

This PR includes the following specification for Poseidon-128:

  • S-box: x5
  • t = 3
  • RF = 8
  • RP = 58 (one more than the equivalent standard specification).
  • PoseidonHash(𝑥, 𝑦) =𝑓([𝑥, 𝑦, 265])[0] (using 0-based indexing).

Closes #37.

@str4d str4d marked this pull request as ready for review March 11, 2021 17:48
src/primitives/poseidon.rs Outdated Show resolved Hide resolved
@str4d str4d added this to the Core Sprint 2021-10 milestone Mar 11, 2021
@codecov-io
Copy link

codecov-io commented Mar 13, 2021

Codecov Report

Merging #41 (df83dbd) into main (35da179) will increase coverage by 29.70%.
The diff coverage is 84.55%.

Impacted file tree graph

@@             Coverage Diff             @@
##             main      #41       +/-   ##
===========================================
+ Coverage   46.66%   76.36%   +29.70%     
===========================================
  Files           5        9        +4     
  Lines          75      347      +272     
===========================================
+ Hits           35      265      +230     
- Misses         40       82       +42     
Impacted Files Coverage Δ
src/primitives/poseidon/nullifier.rs 75.00% <75.00%> (ø)
src/primitives/poseidon.rs 79.68% <79.68%> (ø)
src/primitives/poseidon/grain.rs 91.04% <91.04%> (ø)
src/primitives/poseidon/mds.rs 97.56% <97.56%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 35da179...df83dbd. Read the comment docs.

src/primitives/poseidon.rs Outdated Show resolved Hide resolved
src/primitives/poseidon.rs Outdated Show resolved Hide resolved
@str4d str4d force-pushed the poseidon-primitive branch from ccbe17e to 43b521d Compare March 16, 2021 00:09
@str4d str4d changed the base branch from main to key-components March 16, 2021 00:09
@str4d
Copy link
Contributor Author

str4d commented Mar 16, 2021

Rebased on #40.

@str4d str4d linked an issue Mar 16, 2021 that may be closed by this pull request
Base automatically changed from key-components to main March 18, 2021 00:44
str4d and others added 15 commits March 18, 2021 16:37
These are generated using v1.1 of the reference implementation.
We don't currently require SboxType::Inv, so let's simplify for now.
Poseidon specifications are now all concrete, and only generation of
constants at runtime requires an instance of the specification.
We reuse this type for the per-round round constants, and rows of the
MDS, to provide some type-level same-length guarantees. Once we can use
const generics, these will all be replaced by [F; Spec::ARITY].
This removes the need for specifying the rate at runtime, and removes
the remaining heap allocations from Duplex::absorb and Duplex::squeeze.
I'm using range loops explicitly to make certain logic clearer.
Domain separation is implemented as specified in the Poseidon paper.
We only require constant-input-length hashing.
For Orchard, we want a Poseidon instance with a width of 3 field
elements and an output of one field element. The Poseidon instances
defined in the Poseidon paper have their output size equal to their
capacity size; with a capacity of 1 and pallas::Base as the field,
Poseidon-128 has the corresponding security level.

We do deviate from the paper's instance by adding a single partial
round, which makes the circuit easier to implement in Halo 2.
We now hard-code the Poseidon round constants and MDS for the Poseidon
specification used for Orchard nullifiers, as produced by the reference
implementation, and test that our constant generation can recreate them.
To match the paper more closely (arity specifically refers to Merkle
tree instantiations).
@str4d str4d force-pushed the poseidon-primitive branch from 43b521d to 1ceb603 Compare March 18, 2021 03:47
@str4d str4d changed the base branch from main to pasta-curves March 18, 2021 03:47
Base automatically changed from pasta-curves to main March 18, 2021 19:35
}
}

// $ sage generate_parameters_grain.sage 1 0 255 3 8 58 0x40000000000000000000000000000000224698fc094cf91b992d30ed00000001
Copy link
Contributor

Choose a reason for hiding this comment

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

I did not check these constants.

@therealyingtong therealyingtong self-requested a review March 25, 2021 05:07
@str4d str4d merged commit ee2bfa7 into main Mar 25, 2021
@str4d str4d deleted the poseidon-primitive branch March 25, 2021 18:36
@str4d str4d restored the poseidon-primitive branch March 25, 2021 18:42
@str4d str4d deleted the poseidon-primitive branch March 25, 2021 18:44
@str4d str4d restored the poseidon-primitive branch March 25, 2021 23:49
@str4d str4d deleted the poseidon-primitive branch March 25, 2021 23:49
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.

Implement Poseidon outside the circuit
5 participants