-
Notifications
You must be signed in to change notification settings - Fork 15
Split permutation from sponge construction #30
base: master
Are you sure you want to change the base?
Conversation
Work towards #29; this doesn't touch the constraint system implementation yet, in order to be able to get design feedback on the software part. - The `poseidon::PoseidonParameters` struct is renamed to `poseidon::Parameters` but otherwise remains unchanged. - The `poseidon::PoseidonSpongeState` struct is renamed to `poseidon::State` and redefined to hold just the state itself, as well as the parameters needed to run the permutation. It exposes a `permute(&mut self)` method, `rate()` and `capacity()` accessors, as well as `Index`, `IndexMut`, `AsRef`, and `AsMut` impls that allow access to the state. - The `poseidon::PoseidonSponge` struct is renamed to `poseidon::Sponge` and holds a `State` and a `DuplexSpongeMode`. In other words, it consists of the state, together with the extra data tracking how that state is being used to implement a higher-level duplex construction. - The `CryptographicSponge` trait is changed so that `new()` takes an owned, `Self::Parameters`, not a borrowed one. This allows the caller to decide where to copy data, instead of forcing the sponge implementation to clone internally. Or, a `CryptographicSponge` implementation could declare the associated `Parameters` type to be some shared type (like an `Arc` wrapper) that avoids the need to copy at all. - The `SpongeExt` trait that allows converting back and forth between a state and a sponge is deleted; it's not safe to pass between abstraction layers that way.
This uses the API changes from: - https://github.com/arkworks-rs/sponge/issues/29 - arkworks-rs/sponge#30 to avoid working through the Arkworks sponge interface, and do hashing using the permutation directly.
This uses the API changes from: - https://github.com/arkworks-rs/sponge/issues/29 - arkworks-rs/sponge#30 to avoid working through the Arkworks sponge interface, and do hashing using the permutation directly.
This uses the API changes from: - https://github.com/arkworks-rs/sponge/issues/29 - arkworks-rs/sponge#30 to avoid working through the Arkworks sponge interface, and do hashing using the permutation directly.
This uses the API changes from: - https://github.com/arkworks-rs/sponge/issues/29 - arkworks-rs/sponge#30 to avoid working through the Arkworks sponge interface, and do hashing using the permutation directly.
(A rendered copy of the docs is available here: https://rustdoc.penumbra.zone/main/ark_sponge/poseidon/index.html) |
The changes look great so far, though I'm not the most qualified to review this stuff; @ValarDragon and @weikengchen are more familiar with this code. Also, is there something specific that you'd like to get feedback on? |
|
||
/// Parameters describing a Poseidon instance. | ||
#[derive(Clone, Debug)] | ||
pub struct Parameters<F: PrimeField> { |
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.
So to clarify, these are Parameters
for the underlying permutation, right? They don't have anything to do with the sponge, beyond the rate and capacity, right? If you could add a comment clarifying that, it would be great. Thanks!
Co-authored-by: Pratyush Mishra <pratyushmishra@berkeley.edu>
Yeah, the main thing is whether this general approach seems good, before doing the work of also updating the constraint implementations. |
Hey, just bumping this -- if this approach seems good I can also apply it to the constraint implementations. |
Feel free to apply to the constraints implementations. |
Work towards arkworks-rs/crypto-primitives#93; this doesn't touch the constraint system implementation yet,
in order to be able to get design feedback on the software part.
The
poseidon::PoseidonParameters
struct is renamed toposeidon::Parameters
but otherwise remains unchanged.
The
poseidon::PoseidonSpongeState
struct is renamed toposeidon::State
and redefined to hold just the state itself, as well as the parameters needed
to run the permutation. It exposes a
permute(&mut self)
method,rate()
andcapacity()
accessors, as well asIndex
,IndexMut
,AsRef
, andAsMut
impls that allow access to the state.
The
poseidon::PoseidonSponge
struct is renamed toposeidon::Sponge
andholds a
State
and aDuplexSpongeMode
. In other words, it consists of thestate, together with the extra data tracking how that state is being used to
implement a higher-level duplex construction.
The
CryptographicSponge
trait is changed so thatnew()
takes an owned,Self::Parameters
, not a borrowed one. This allows the caller to decidewhere to copy data, instead of forcing the sponge implementation to clone
internally. Or, a
CryptographicSponge
implementation could declare theassociated
Parameters
type to be some shared type (like anArc
wrapper)that avoids the need to copy at all.
The
SpongeExt
trait that allows converting back and forth between a stateand a sponge is deleted; it's not safe to pass between abstraction layers
that way.
Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.
[ ] Wrote unit testsPending
section inCHANGELOG.md
Files changed
in the Github PR explorer