|
Barretenberg
The ZK-SNARK library at the core of Aztec
|
#include <sha256_trace.hpp>
Public Member Functions | |
| 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. | |
Static Public Attributes | |
| static const InteractionDefinition | interactions |
Private Member Functions | |
| 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. | |
| 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. | |
| 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. | |
| 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. | |
| 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. | |
| 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. | |
| 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. | |
| 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 | 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. | |
Private Attributes | |
| uint32_t | row = 1 |
Definition at line 14 of file sha256_trace.hpp.
|
private |
Perform one round of the SHA-256 compression function and insert all witness data into the trace.
Computes S0, S1, ch, maj, temp1, temp2, and the updated state for a single SHA-256 round. All intermediate values (rotations, bitwise ops, modular additions) are written to the trace.
| state | The 8-element state array [a, b, c, d, e, f, g, h] at the start of this round. |
| round_w | The message schedule word w[i] for this round. |
| round_constant | The SHA-256 round constant k[i] for this round. |
| trace | The trace container to populate. |
Definition at line 249 of file sha256_trace.cpp.
|
private |
Compute the final SHA-256 output (init_state + final_round_state mod 2^32) and write to the trace.
| out_state | The 8-element state array after the final (64th) compression round. |
| init_state | The 8-element initial hash state before compression. |
| trace | The trace container to populate with the output limb decompositions. |
Definition at line 352 of file sha256_trace.cpp.
|
private |
Compute the message schedule word w[j] for a non-input round and insert witness data into the trace.
Implements w[j] = w[j-16] + s0 + w[j-7] + s1 where s0 and s1 are computed from rotations and shifts of previous w values, with all intermediate results recorded as trace columns.
| prev_w_helpers | The 16 most recent w values (sliding window), indexed 0..15. |
| trace | The trace container to populate. |
Definition at line 188 of file sha256_trace.cpp.
|
private |
Decompose a value into high and low limbs at a given bit position and write them to the trace.
| a | The value to decompose. |
| b | The bit position at which to split (low limb has b bits). |
| col_lhs | The column for the high limb (a >> b). |
| col_rhs | The column for the low limb (a & (2^b - 1)). |
| trace | The trace container to populate. |
Definition at line 119 of file sha256_trace.cpp.
| void bb::avm2::tracegen::Sha256TraceBuilder::process | ( | const simulation::EventEmitterInterface< simulation::Sha256CompressionEvent >::Container & | events, |
| TraceContainer & | trace | ||
| ) |
Process the SHA-256 compression events and populate the relevant columns in the trace.
Events are emitted in the following flavors:
| events | Container of Sha256CompressionEvent to process. |
| trace | The trace container to populate. |
Definition at line 381 of file sha256_trace.cpp.
|
private |
Perform a 32-bit right rotation and insert the result and rhs limb into the trace.
Only the rotation result and the low limb (rhs) are written. The high limb (lhs) is algebraically eliminated in PIL via the combined rotation constraint: X = Y * 2^a - rhs * (2^32 - 1)
| val | The 32-bit value to rotate. |
| shift | The number of bits to rotate right. |
| col_result | The column for the rotation result. |
| col_rhs | The column for the low limb of the decomposition (range-checked in PIL). |
| trace | The trace container to populate. |
val << (32 - shift) becomes a left shift by 32. This is an internal helper; all callers use fixed SHA-256 rotation amounts (2, 6, 7, 11, 13, 17, 18, 19, 22, 25), so this precondition is always satisfied. Definition at line 146 of file sha256_trace.cpp.
|
private |
Set the 16 message-schedule helper columns (w0..w15) at the current row.
| prev_w_helpers | The 16 previous w helper values for this round. |
| trace | The trace container to populate. |
Definition at line 76 of file sha256_trace.cpp.
|
private |
Set the 8 initial-state columns (init_a..init_h) at the current row.
| init_state | The 8 initial hash state values (propagated unchanged across all rows). |
| trace | The trace container to populate. |
Definition at line 100 of file sha256_trace.cpp.
|
private |
Set the 8 round-state columns (a..h) at the current row.
| state | The 8 state values for this round. |
| trace | The trace container to populate. |
Definition at line 88 of file sha256_trace.cpp.
|
private |
Perform a 32-bit right shift and insert the limb decomposition into the trace.
The shift result is the high limb (col_lhs = val >> shift), written by into_limbs_with_witness.
| val | The 32-bit value to shift. |
| shift | The number of bits to shift right. |
| col_lhs | The column for the high limb of the decomposition (shift result). |
| col_rhs | The column for the low limb of the decomposition (discarded bits). |
| trace | The trace container to populate. |
Definition at line 170 of file sha256_trace.cpp.
|
static |
Definition at line 19 of file sha256_trace.hpp.
|
private |
Definition at line 22 of file sha256_trace.hpp.