mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-05 15:23:06 +00:00
35 lines
1.2 KiB
Rust
35 lines
1.2 KiB
Rust
use std::convert::TryInto;
|
|
|
|
use crate::field::extension_field::Extendable;
|
|
use crate::field::field_types::RichField;
|
|
use crate::gates::gmimc::GMiMCGate;
|
|
use crate::gates::poseidon::PoseidonGate;
|
|
use crate::hash::gmimc::GMiMC;
|
|
use crate::hash::hashing::SPONGE_WIDTH;
|
|
use crate::hash::poseidon::Poseidon;
|
|
use crate::iop::target::{BoolTarget, Target};
|
|
use crate::iop::wire::Wire;
|
|
use crate::plonk::circuit_builder::CircuitBuilder;
|
|
use crate::plonk::config::AlgebraicHasher;
|
|
|
|
impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
|
pub fn permute<H: AlgebraicHasher<F>>(
|
|
&mut self,
|
|
inputs: [Target; SPONGE_WIDTH],
|
|
) -> [Target; SPONGE_WIDTH] {
|
|
// We don't want to swap any inputs, so set that wire to 0.
|
|
let _false = self._false();
|
|
self.permute_swapped::<H>(inputs, _false)
|
|
}
|
|
|
|
/// Conditionally swap two chunks of the inputs (useful in verifying Merkle proofs), then apply
|
|
/// a cryptographic permutation.
|
|
pub(crate) fn permute_swapped<H: AlgebraicHasher<F>>(
|
|
&mut self,
|
|
inputs: [Target; SPONGE_WIDTH],
|
|
swap: BoolTarget,
|
|
) -> [Target; SPONGE_WIDTH] {
|
|
H::permute_swapped(inputs, swap, self)
|
|
}
|
|
}
|