Skip to content

Commit

Permalink
Add CryptographicSpongeExt to enable access to "gadget" version of …
Browse files Browse the repository at this point in the history
…a `Sponge` (arkworks-rs#24)

* Add `CryptographicSpongeExt` to enable easy access to "gadget" version of a `Sponge`

* Update CHANGELOG

* Rename trait

* Update CHANGELOG

* Format
  • Loading branch information
Pratyush authored Jul 29, 2021
1 parent 55401d5 commit c9f7d24
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

- [\#22](https://github.com/arkworks-rs/sponge/pull/22) Add traits and derivations for default Poseidon parameters.

- [\#24](https://github.com/arkworks-rs/sponge/pull/24) Add `SpongeWithGadget` trait that enables getting the gadget version of a sponge.

### Improvements

### Bug fixes
Expand Down
7 changes: 7 additions & 0 deletions src/constraints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ pub fn bits_le_to_nonnative<'a, F: PrimeField, CF: PrimeField>(
Ok(output)
}

/// Enables simple access to the "gadget" version of the sponge.
/// Simplifies trait bounds in downstream generic code.
pub trait SpongeWithGadget<CF: PrimeField>: CryptographicSponge {
/// The gadget version of `Self`.
type Var: CryptographicSpongeVar<CF, Self>;
}

/// The interface for a cryptographic sponge constraints on field `CF`.
/// A sponge can `absorb` or take in inputs and later `squeeze` or output bytes or field elements.
/// The outputs are dependent on previous `absorb` and `squeeze` calls.
Expand Down
6 changes: 5 additions & 1 deletion src/poseidon/constraints.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::constraints::AbsorbGadget;
use crate::constraints::CryptographicSpongeVar;
use crate::constraints::{CryptographicSpongeVar, SpongeWithGadget};
use crate::poseidon::{PoseidonParameters, PoseidonSponge};
use crate::DuplexSpongeMode;
use ark_ff::{FpParameters, PrimeField};
Expand Down Expand Up @@ -30,6 +30,10 @@ pub struct PoseidonSpongeVar<F: PrimeField> {
pub mode: DuplexSpongeMode,
}

impl<F: PrimeField> SpongeWithGadget<F> for PoseidonSponge<F> {
type Var = PoseidonSpongeVar<F>;
}

impl<F: PrimeField> PoseidonSpongeVar<F> {
#[tracing::instrument(target = "r1cs", skip(self))]
fn apply_s_box(
Expand Down

0 comments on commit c9f7d24

Please sign in to comment.