-
Notifications
You must be signed in to change notification settings - Fork 37
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
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
ccbe17e
to
43b521d
Compare
Rebased on #40. |
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).
43b521d
to
1ceb603
Compare
} | ||
} | ||
|
||
// $ sage generate_parameters_grain.sage 1 0 255 3 8 58 0x40000000000000000000000000000000224698fc094cf91b992d30ed00000001 |
There was a problem hiding this comment.
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.
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:
Closes #37.