Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
sha256_trace.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4#include <cstdint>
5
11
12namespace bb::avm2::tracegen {
13
14class Sha256TraceBuilder final {
15 public:
18
20
21 private:
22 uint32_t row = 1; // Start from 1 to avoid the precomputed row.
23
25 const uint64_t, const uint8_t b, Column col_lhs, Column col_rhs, TraceContainer& trace) const;
26 uint32_t ror_with_witness(
27 const uint32_t val, const uint8_t shift, Column col_result, Column col_rhs, TraceContainer& trace) const;
28 uint32_t shr_with_witness(
29 const uint32_t val, const uint8_t shift, Column col_lhs, Column col_rhs, TraceContainer& trace) const;
30 uint32_t compute_w_with_witness(const std::array<uint32_t, 16>& prev_w_helpers, TraceContainer& trace) const;
31 std::array<uint32_t, 8> compute_compression_with_witness(const std::array<uint32_t, 8>& state,
32 uint32_t round_w,
33 uint32_t round_constant,
34 TraceContainer& trace) const;
35 void set_helper_cols(const std::array<uint32_t, 16>& prev_w_helpers, TraceContainer& trace) const;
36 void set_init_state_cols(const std::array<uint32_t, 8>& init_state, TraceContainer& trace) const;
37 void set_state_cols(const std::array<uint32_t, 8>& state, TraceContainer& trace) const;
38 void compute_sha256_output(const std::array<uint32_t, 8>& out_state,
39 const std::array<uint32_t, 8>& init_state,
40 TraceContainer& trace) const;
41};
42
43} // namespace bb::avm2::tracegen
void process(const simulation::EventEmitterInterface< simulation::Sha256CompressionEvent >::Container &events, TraceContainer &trace)
Process the SHA-256 compression events and populate the relevant columns in the trace.
uint32_t ror_with_witness(const uint32_t val, const uint8_t shift, Column col_result, Column col_rhs, TraceContainer &trace) const
Perform a 32-bit right rotation and insert the result and rhs limb into the trace.
void set_state_cols(const std::array< uint32_t, 8 > &state, TraceContainer &trace) const
Set the 8 round-state columns (a..h) at the current row.
void set_helper_cols(const std::array< uint32_t, 16 > &prev_w_helpers, TraceContainer &trace) const
Set the 16 message-schedule helper columns (w0..w15) at the current row.
uint32_t compute_w_with_witness(const std::array< uint32_t, 16 > &prev_w_helpers, TraceContainer &trace) const
Compute the message schedule word w[j] for a non-input round and insert witness data into the trace.
static const InteractionDefinition interactions
uint32_t shr_with_witness(const uint32_t val, const uint8_t shift, Column col_lhs, Column col_rhs, TraceContainer &trace) const
Perform a 32-bit right shift and insert the limb decomposition into the trace.
void compute_sha256_output(const std::array< uint32_t, 8 > &out_state, const std::array< uint32_t, 8 > &init_state, TraceContainer &trace) const
Compute the final SHA-256 output (init_state + final_round_state mod 2^32) and write to the trace.
void into_limbs_with_witness(const uint64_t, const uint8_t b, Column col_lhs, Column col_rhs, TraceContainer &trace) const
Decompose a value into high and low limbs at a given bit position and write them to the trace.
void set_init_state_cols(const std::array< uint32_t, 8 > &init_state, TraceContainer &trace) const
Set the 8 initial-state columns (init_a..init_h) at the current row.
std::array< uint32_t, 8 > compute_compression_with_witness(const std::array< uint32_t, 8 > &state, uint32_t round_w, uint32_t round_constant, TraceContainer &trace) const
Perform one round of the SHA-256 compression function and insert all witness data into the trace.
TestTraceContainer trace
FF b
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13