Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
sha256_constraint.cpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: Complete, auditors: [Luke], commit: }
3// external_1: { status: not started, auditors: [], commit: }
4// external_2: { status: not started, auditors: [], commit: }
5// =====================
6
10
11namespace acir_format {
12
13template <typename Builder>
15{
17
18 std::array<field_ct, 8> hash_inputs; // previous (or initial) hash state
19 std::array<field_ct, 16> inputs; // message block to compress
20
21 // Get the witness assignment for each witness index.
22 // It is assumed that the caller (Noir) separately constrains all 24 inputs (8 hash state + 16 message words) to 32
23 // bits, e.g. via instantiating them as u32 types.
24 for (auto [input, witness_or_constant] : zip_view(inputs, constraint.inputs)) {
25 input = to_field_ct(witness_or_constant, builder);
26 }
27 for (auto [hash_input, witness_or_constant] : zip_view(hash_inputs, constraint.hash_values)) {
28 hash_input = to_field_ct(witness_or_constant, builder);
29 }
30
31 // Compute sha256 compression
33
34 // Constrain outputs to match expected witness indices
35 for (auto [output, result_idx] : zip_view(output_state, constraint.result)) {
36 field_ct result_witness = field_ct::from_witness_index(&builder, result_idx);
37 output.assert_equal(result_witness);
38 }
39}
40
42 const Sha256Compression& constraint);
44 const Sha256Compression& constraint);
45
46} // namespace acir_format
static std::array< field_ct, 8 > sha256_block(const std::array< field_ct, 8 > &h_init, const std::array< field_ct, 16 > &input)
Apply the SHA-256 compression function to a single 512-bit message block.
Definition sha256.cpp:383
static field_t from_witness_index(Builder *ctx, uint32_t witness_index)
Definition field.cpp:63
AluTraceBuilder builder
Definition alu.test.cpp:124
AvmProvingInputs inputs
template void create_sha256_compression_constraints< bb::MegaCircuitBuilder >(bb::MegaCircuitBuilder &builder, const Sha256Compression &constraint)
void create_sha256_compression_constraints(Builder &builder, const Sha256Compression &constraint)
template void create_sha256_compression_constraints< bb::UltraCircuitBuilder >(bb::UltraCircuitBuilder &builder, const Sha256Compression &constraint)
bb::stdlib::field_t< Builder > to_field_ct(const WitnessOrConstant< typename Builder::FF > &input, Builder &builder)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
std::array< WitnessOrConstant< bb::fr >, 8 > hash_values
std::array< uint32_t, 8 > result
std::array< WitnessOrConstant< bb::fr >, 16 > inputs