halo2/src/circuit/gadget/poseidon.rs

30 lines
810 B
Rust

//! Gadget and chips for the Poseidon algebraic hash function.
use std::fmt;
use halo2::{
arithmetic::FieldExt,
circuit::{Chip, Layouter},
plonk::Error,
};
mod pow5t3;
pub use pow5t3::{Pow5T3Chip, Pow5T3Config};
use crate::primitives::poseidon::{Spec, State};
/// The set of circuit instructions required to use the Poseidon permutation.
pub trait PoseidonInstructions<F: FieldExt, S: Spec<F, T, RATE>, const T: usize, const RATE: usize>:
Chip<F>
{
/// Variable representing the word over which the Poseidon permutation operates.
type Word: fmt::Debug;
/// Applies the Poseidon permutation to the given state.
fn permute(
&self,
layouter: &mut impl Layouter<F>,
initial_state: &State<Self::Word, T>,
) -> Result<State<Self::Word, T>, Error>;
}