Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Circuit version of hash_pad #101

Merged
merged 1 commit into from
May 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions plonky2/src/hash/hashing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ use crate::plonk::circuit_builder::CircuitBuilder;
use crate::plonk::config::AlgebraicHasher;

impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
/// Pad the message using the `pad10*1` rule, then hash it.
///
/// This is circuit version of
/// [`crate::plonk::config::Hasher::hash_pad`]
pub fn hash_pad<H: AlgebraicHasher<F>>(&mut self, inputs: Vec<Target>) -> HashOutTarget {
let mut padded_input = inputs;
padded_input.push(self.one());
while (padded_input.len() + 1) % H::Permutation::RATE != 0 {
padded_input.push(self.zero());
}
padded_input.push(self.one());
self.hash_n_to_hash_no_pad::<H>(padded_input)
}
pub fn hash_or_noop<H: AlgebraicHasher<F>>(&mut self, inputs: Vec<Target>) -> HashOutTarget {
let zero = self.zero();
if inputs.len() <= NUM_HASH_OUT_ELTS {
Expand Down