7#include "barretenberg/aztec/aztec_constants.hpp"
15constexpr std::array<uint32_t, 64> ROUND_CONSTANTS{
16 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
17 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
18 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
19 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
20 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
21 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
22 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
23 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
45 auto val = x.
as<uint32_t>();
47 uint32_t lo = val & ((
static_cast<uint32_t
>(1) <<
shift) - 1);
48 uint32_t hi = val >>
shift;
52 return MemoryValue::from<uint32_t>(
result);
70 uint32_t input = x.
as<uint32_t>();
72 uint32_t lo = input & ((
static_cast<uint32_t
>(1) <<
shift) - 1);
73 uint32_t hi = input >>
shift;
77 return MemoryValue::from<uint32_t>(hi);
92 for (
const auto&
value : values) {
96 uint32_t lo =
static_cast<uint32_t
>(
sum);
97 uint32_t hi =
static_cast<uint32_t
>(
sum >> 32);
103 BB_ASSERT(hi < 256,
"High value in MODULO_SUM out of range");
104 return MemoryValue::from<uint32_t>(lo);
135 uint16_t space_id =
memory.get_space_id();
139 state.fill(MemoryValue::from<FF>(0));
148 bool state_addr_out_of_range =
gt.gt(
static_cast<uint64_t
>(state_addr) + 7, AVM_HIGHEST_MEM_ADDRESS);
149 bool input_addr_out_of_range =
gt.gt(
static_cast<uint64_t
>(input_addr) + 15, AVM_HIGHEST_MEM_ADDRESS);
150 bool output_addr_out_of_range =
gt.gt(
static_cast<uint64_t
>(output_addr) + 7, AVM_HIGHEST_MEM_ADDRESS);
153 if (state_addr_out_of_range || input_addr_out_of_range || output_addr_out_of_range) {
159 for (uint32_t i = 0; i < 8; ++i) {
160 state[i] =
memory.get(state_addr + i);
170 for (uint32_t i = 0; i < 16; ++i) {
171 input.emplace_back(
memory.get(input_addr + i));
182 for (
size_t i = 0; i < 16; ++i) {
187 for (
size_t i = 16; i < 64; ++i) {
194 w[i] =
modulo_sum({ { w[i - 16], w[i - 7], s0, s1 } });
208 for (
size_t i = 0; i < 64; ++i) {
220 e =
modulo_sum({ { d, prev_h, S1, ch, MemoryValue::from<uint32_t>(ROUND_CONSTANTS[i]), w[i] } });
225 a =
modulo_sum({ { prev_h, S1, ch, MemoryValue::from<uint32_t>(ROUND_CONSTANTS[i]), w[i], S0, maj } });
236 for (uint32_t i = 0; i < 8; ++i) {
237 memory.set(output_addr + i, output[i]);
240 events.emit({ .execution_clk = execution_clk,
241 .space_id = space_id,
242 .state_addr = state_addr,
243 .input_addr = input_addr,
244 .output_addr = output_addr,
251 output.fill(MemoryValue::from<FF>(0));
252 events.emit({ .execution_clk = execution_clk,
253 .space_id = space_id,
254 .state_addr = state_addr,
255 .input_addr = input_addr,
256 .output_addr = output_addr,
#define BB_ASSERT(expression,...)
virtual uint32_t get_execution_id() const =0
MemoryValue modulo_sum(std::span< const MemoryValue > values)
Sum a span of U32 MemoryValues and return the result modulo 2^32.
EventEmitterInterface< Sha256CompressionEvent > & events
void compression(MemoryInterface &memory, MemoryAddress state_addr, MemoryAddress input_addr, MemoryAddress output_addr) override
Execute the SHA-256 compression function: read state and input from memory, compress,...
MemoryValue shr(const MemoryValue &x, uint8_t shift)
Perform a 32-bit right shift on a MemoryValue.
ExecutionIdGetterInterface & execution_id_manager
MemoryValue ror(const MemoryValue &x, uint8_t shift)
Perform a 32-bit right rotation on a MemoryValue.
AVM range check gadget for witness generation.
Inner sum(Cont< Inner, Args... > const &in)
constexpr ScalarIndex shift(ScalarIndex ctx, size_t d)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept