34template <
size_t rate,
size_t capacity,
size_t t,
typename Permutation,
typename Builder>
class FieldSponge {
61 for (
size_t i = 0; i < rate; ++i) {
74 for (
size_t i = 0; i < rate; ++i) {
80 for (
size_t i = 0; i < rate; ++i) {
86 for (
size_t i = rate; i < t; i++) {
127 for (
size_t i = 0; i < rate; ++i) {
128 cache[i] = new_output_elements[i];
150 template <
size_t out_len>
153 size_t in_len = input.size();
157 for (
size_t i = 0; i < in_len; ++i) {
158 BB_ASSERT_EQ(input[i].witness_index == IS_CONSTANT,
false,
"Sponge inputs should not be stdlib constants.");
163 for (
size_t i = 0; i < out_len; ++i) {
169 for (
const auto& elem : sponge.
cache) {
170 if (elem.witness_index != IS_CONSTANT) {
171 builder.update_used_witnesses(elem.witness_index);
180 return hash_internal<1>(
builder, input)[0];
#define BB_ASSERT_EQ(actual, expected,...)
Implements the circuit form of a cryptographic sponge over prime fields. Implements the sponge specif...
std::array< field_t, t > state
std::array< field_t, rate > cache
static field_t hash_internal(Builder &builder, std::span< const field_t > input)
std::array< field_t, rate > perform_duplex()
void absorb(const field_t &input)
Mode
Defines what phase of the sponge algorithm we are in.
static std::array< field_t, out_len > hash_internal(Builder &builder, std::span< const field_t > input)
Use the sponge to hash an input string.
FieldSponge(Builder &builder_, field_t domain_iv=0)
static State permutation(Builder *builder, const State &input)
Circuit form of Poseidon2 permutation from https://eprint.iacr.org/2023/323.
static witness_t create_constant_witness(Builder *parent_context, const bb::fr &in)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept