Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
bb::stdlib::hash_utils Namespace Reference

Functions

template<typename Builder >
field_t< Builderadd_normalize_unsafe (const field_t< Builder > &a, const field_t< Builder > &b, size_t overflow_bits)
 Compute (a + b) mod 2^32 with circuit constraints.
 

Function Documentation

◆ add_normalize_unsafe()

template<typename Builder >
field_t< Builder > bb::stdlib::hash_utils::add_normalize_unsafe ( const field_t< Builder > &  a,
const field_t< Builder > &  b,
size_t  overflow_bits 
)

Compute (a + b) mod 2^32 with circuit constraints.

Given two field_t elements a and b, this function computes ((a + b) % 2^{32}). The overflow is constrained to fit within overflow_bits bits.

Constrains: result = a + b - overflow * 2^32, where overflow is range-checked to overflow_bits.

Parameters
aFirst 32-bit operand (should be constrained externally).
bSecond 32-bit operand (should be constrained externally).
overflow_bitsNumber of bits for overflow range constraint. Must accommodate max(a + b) / 2^32. For two 32-bit inputs, 1 bit suffices. For accumulated sums, use appropriately larger values.
Warning
Marked unsafe since the result is not explicitly range-constrained herein. If such range constraints are required, the caller must ensure they are applied, e.g. explicitly via create_range_constraint() or implicitly via downstream lookup tables that enforce the range.

Definition at line 32 of file hash_utils.hpp.