snarkvm_algorithms::crypto_hash::poseidon

Struct PoseidonSponge

Source
pub struct PoseidonSponge<F: PrimeField, const RATE: usize, const CAPACITY: usize> {
    pub mode: DuplexSpongeMode,
    /* private fields */
}
Expand description

A duplex sponge based using the Poseidon permutation.

This implementation of Poseidon is entirely from Fractal’s implementation in COS20 with small syntax changes.

Fields§

§mode: DuplexSpongeMode

Current mode (whether its absorbing or squeezing)

Implementations§

Source§

impl<F: PrimeField, const RATE: usize> PoseidonSponge<F, RATE, 1>

Source

pub fn compress_elements<TargetField: PrimeField, I: Iterator<Item = (F, F)>>( &self, src_limbs: Peekable<I>, ty: OptimizationType, ) -> Vec<F>

Compress every two elements if possible. Provides a vector of (limb, num_of_additions), both of which are F.

Source

pub fn get_limbs_representations<TargetField: PrimeField>( elem: &TargetField, optimization_type: OptimizationType, ) -> SmallVec<[F; 10]>

Convert a TargetField element into limbs (not constraints) This is an internal function that would be reused by a number of other functions

Source

pub fn get_limbs_representations_from_big_integer<TargetField: PrimeField>( elem: &<TargetField as PrimeField>::BigInteger, optimization_type: OptimizationType, ) -> SmallVec<[F; 10]>

Obtain the limbs directly from a big int

Source

pub fn push_elements_to_sponge<TargetField: PrimeField>( &mut self, src: impl IntoIterator<Item = TargetField>, ty: OptimizationType, )

Push elements to sponge, treated in the non-native field representations.

Source

pub fn get_bits(&mut self, num_bits: usize) -> Vec<bool>

obtain random bits from hashchain. not guaranteed to be uniformly distributed, should only be used in certain situations.

Source

pub fn get_fe<TargetField: PrimeField>( &mut self, num_elements: usize, outputs_short_elements: bool, ) -> SmallVec<[TargetField; 10]>

obtain random field elements from hashchain. not guaranteed to be uniformly distributed, should only be used in certain situations.

Trait Implementations§

Source§

impl<F: PrimeField, const RATE: usize> AlgebraicSponge<F, RATE> for PoseidonSponge<F, RATE, 1>

Source§

fn absorb_native_field_elements<T: ToConstraintField<F>>( &mut self, elements: &[T], )

Takes in field elements.

Source§

fn absorb_nonnative_field_elements<Target: PrimeField>( &mut self, elements: impl IntoIterator<Item = Target>, )

Takes in field elements.

Source§

fn squeeze_short_nonnative_field_elements<Target: PrimeField>( &mut self, num: usize, ) -> SmallVec<[Target; 10]>

Takes out field elements of 168 bits.

Source§

type Parameters = Arc<PoseidonParameters<F, RATE, 1>>

Parameters used by the sponge.
Source§

fn sample_parameters() -> Self::Parameters

Source§

fn new_with_parameters(parameters: &Self::Parameters) -> Self

Initialize a new instance of the sponge.
Source§

fn squeeze_nonnative_field_elements<Target: PrimeField>( &mut self, num: usize, ) -> SmallVec<[Target; 10]>

Takes out field elements.
Source§

fn squeeze_native_field_elements( &mut self, num_elements: usize, ) -> SmallVec<[F; 10]>

Takes in field elements.
Source§

fn new() -> Self

Initialize a new instance of the sponge.
Source§

fn absorb_bytes(&mut self, elements: &[u8])

Takes in bytes.
Source§

fn squeeze_short_nonnative_field_element<Target: PrimeField>( &mut self, ) -> Target

Takes out a field element of 168 bits.
Source§

impl<F: Clone + PrimeField, const RATE: usize, const CAPACITY: usize> Clone for PoseidonSponge<F, RATE, CAPACITY>

Source§

fn clone(&self) -> PoseidonSponge<F, RATE, CAPACITY>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<F: Debug + PrimeField, const RATE: usize, const CAPACITY: usize> Debug for PoseidonSponge<F, RATE, CAPACITY>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<F, const RATE: usize, const CAPACITY: usize> Freeze for PoseidonSponge<F, RATE, CAPACITY>
where F: Freeze,

§

impl<F, const RATE: usize, const CAPACITY: usize> RefUnwindSafe for PoseidonSponge<F, RATE, CAPACITY>
where F: RefUnwindSafe,

§

impl<F, const RATE: usize, const CAPACITY: usize> Send for PoseidonSponge<F, RATE, CAPACITY>

§

impl<F, const RATE: usize, const CAPACITY: usize> Sync for PoseidonSponge<F, RATE, CAPACITY>

§

impl<F, const RATE: usize, const CAPACITY: usize> Unpin for PoseidonSponge<F, RATE, CAPACITY>
where F: Unpin,

§

impl<F, const RATE: usize, const CAPACITY: usize> UnwindSafe for PoseidonSponge<F, RATE, CAPACITY>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize = _

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V