Skip to main content

binius_hash/
compress.rs

1// Copyright 2024-2025 Irreducible Inc.
2// Copyright (c) 2024 The Plonky3 Authors
3
4//! These interfaces are taken from
5//! [p3_symmetric](https://github.com/Plonky3/Plonky3/blob/main/symmetric/src/compression.rs) in
6//! [Plonky3].
7//!
8//! Plonky3 is dual-licensed under MIT OR Apache 2.0. We use it under Apache 2.0.
9//!
10//! [Plonky3]: <https://github.com/plonky3/plonky3>
11
12/// An `N`-to-1 compression function used to build the inner nodes of a hash tree.
13///
14/// It folds `N` values into a single value of the same type, so it can be applied level by level:
15/// the children of an inner node are compressed to produce that node.
16pub trait CompressionFunction<T, const N: usize>: Clone {
17	/// Maps the `N` inputs down to a single output of the same type.
18	///
19	/// In a hash tree this folds the `N` child node values into their parent node value.
20	fn compress(&self, input: [T; N]) -> T;
21}