Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
hash_utils.hpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: Complete, auditors: [Luke], commit: dd03c4a23ab067274b4964cacb36d1545f73fb14}
3// external_1: { status: not started, auditors: [], commit: }
4// external_2: { status: not started, auditors: [], commit: }
5// =====================
6
7#pragma once
8
11
13
31template <typename Builder>
33{
36
37 Builder* ctx = a.get_context() ? a.get_context() : b.get_context();
38
39 uint256_t sum = a.get_value() + b.get_value();
40 uint256_t normalized_sum = static_cast<uint32_t>(sum.data[0]); // lower 32 bits
41
42 if (a.is_constant() && b.is_constant()) {
43 return field_pt(ctx, normalized_sum);
44 }
45
46 fr overflow_value = fr((sum - normalized_sum) >> 32);
47 field_pt overflow = witness_pt(ctx, overflow_value);
48
49 field_pt result = a.add_two(b, overflow * field_pt(ctx, -fr(1ULL << 32ULL)));
50 overflow.create_range_constraint(overflow_bits);
51 return result;
52}
53
54} // namespace bb::stdlib::hash_utils
void create_range_constraint(size_t num_bits, std::string const &msg="field_t::range_constraint") const
Let x = *this.normalize(), constrain x.v < 2^{num_bits}.
Definition field.cpp:919
FF a
FF b
stdlib::witness_t< bb::UltraCircuitBuilder > witness_pt
stdlib::field_t< UltraCircuitBuilder > field_pt
field_t< Builder > 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.
field< Bn254FrParams > fr
Definition fr.hpp:155
Inner sum(Cont< Inner, Args... > const &in)
Definition container.hpp:70