Skip to content

Commit

Permalink
Resolve conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
phamnhatminh1292001 committed Aug 12, 2024
1 parent eda5abc commit 052328d
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions zkmemory/src/poseidon/poseidon_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
//! Merkle tree and Verkle tree opening proofs.
extern crate alloc;
use alloc::{fmt, vec::Vec};
use alloc::vec::Vec;
use core::{fmt::Debug, iter, marker::PhantomData};
use ff::{Field, PrimeField};

/// The type of a square matrix of size T
pub(crate) type Mtrx<F, const T: usize> = [[F; T]; T];

/// The trait for specifying the hash parameters
pub trait Spec<F: Field + PrimeField, const T: usize, const R: usize>: fmt::Debug {
pub trait Spec<F: Field + PrimeField, const T: usize, const R: usize> {
/// The number of full rounds for Poseidon hash.
fn full_rounds() -> usize;

Expand All @@ -32,7 +32,7 @@ pub trait Spec<F: Field + PrimeField, const T: usize, const R: usize>: fmt::Debu

/// The trait for specifying the domain of messages
pub trait Domain<F: Field + PrimeField, const R: usize> {
/// Iterator that outputs padding field elements.
/// Iterator that outputs padding Field+PrimeField elements.
type Padding: IntoIterator<Item = F>;

/// The initial capacity element, encoding this domain.
Expand All @@ -42,11 +42,11 @@ pub trait Domain<F: Field + PrimeField, const R: usize> {
fn padding(input_len: usize) -> Self::Padding;
}

#[derive(Clone)]
/// The number of messages to be hashed
#[derive(Clone)]
pub struct ConstantLength<const L: usize>;

impl<F: PrimeField, const R: usize, const L: usize> Domain<F, R> for ConstantLength<L> {
impl<F: Field + PrimeField, const R: usize, const L: usize> Domain<F, R> for ConstantLength<L> {
type Padding = iter::Take<iter::Repeat<F>>;

fn initial_capacity_element() -> F {
Expand All @@ -62,10 +62,11 @@ impl<F: PrimeField, const R: usize, const L: usize> Domain<F, R> for ConstantLen

/// The state of the `Sponge`.
pub trait SpongeMode {}

impl<F, const R: usize> SpongeMode for Absorbing<F, R> {}
impl<F, const R: usize> SpongeMode for Squeezing<F, R> {}

impl<F: fmt::Debug, const R: usize> Absorbing<F, R> {
impl<F: Debug, const R: usize> Absorbing<F, R> {
pub(crate) fn init_with(val: F) -> Self {
Self(
iter::once(Some(val))
Expand All @@ -78,17 +79,14 @@ impl<F: fmt::Debug, const R: usize> Absorbing<F, R> {
}

/// The absorbing state of the `Sponge`.
#[derive(Clone, Debug)]
pub struct Absorbing<F, const R: usize>(pub(crate) [Option<F>; R]);

/// The squeezing state of the `Sponge`.
#[derive(Clone, Debug)]
pub struct Squeezing<F, const R: usize>(pub(crate) [Option<F>; R]);

/// The type used to hold permutation state.
pub(crate) type State<F, const T: usize> = [F; T];

#[derive(Clone)]
/// A Poseidon sponge.
pub(crate) struct Sponge<
F: Field + PrimeField,
Expand Down Expand Up @@ -263,7 +261,6 @@ impl<F: Field + PrimeField, S: Spec<F, T, R>, const T: usize, const R: usize>
}
}

#[derive(Clone)]
/// A Poseidon hash function, built around a sponge.
pub struct Hash<
F: Field + PrimeField,
Expand Down Expand Up @@ -306,7 +303,7 @@ impl<F: Field + PrimeField, S: Spec<F, T, R>, const T: usize, const R: usize, co
use crate::poseidon::poseidon_constants::{MDS, MDS_INV, ROUND_CONSTANTS};
use halo2curves::pasta::Fp;
/// Generate specific constants for testing the poseidon hash
#[derive(Clone, Debug)]
#[derive(Clone)]
pub struct OrchardNullifier;

impl Spec<Fp, 3, 2> for OrchardNullifier {
Expand All @@ -329,6 +326,7 @@ impl Spec<Fp, 3, 2> for OrchardNullifier {

#[cfg(test)]
mod tests {

use super::*;
use halo2curves::pasta::pallas::Base;
#[test]
Expand Down

0 comments on commit 052328d

Please sign in to comment.