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;
49 uint32_t result = (lo << (32U - shift)) | hi;
52 bool lo_in_range =
gt.gt(
static_cast<uint32_t
>(1) << shift, lo);
53 BB_ASSERT(lo_in_range,
"Low Value in ROR out of range");
54 return MemoryValue::from<uint32_t>(result);
72 uint32_t input = x.
as<uint32_t>();
74 uint32_t lo = input & ((
static_cast<uint32_t
>(1) << shift) - 1);
75 uint32_t hi = input >> shift;
78 bool lo_in_range =
gt.gt(
static_cast<uint32_t
>(1) << shift, lo);
79 BB_ASSERT(lo_in_range,
"Low Value in SHR out of range");
81 return MemoryValue::from<uint32_t>(hi);
96 for (
const auto&
value : values) {
100 uint32_t lo =
static_cast<uint32_t
>(
sum);
101 uint32_t hi =
static_cast<uint32_t
>(
sum >> 32);
105 gt.gt(
static_cast<uint64_t
>(1) << 32,
static_cast<uint64_t
>(lo));
108 BB_ASSERT(lo_in_range,
"Low value in MODULO_SUM out of range");
109 BB_ASSERT(hi < 256,
"High value in MODULO_SUM out of range");
110 return MemoryValue::from<uint32_t>(lo);
141 uint16_t space_id =
memory.get_space_id();
145 state.fill(MemoryValue::from<FF>(0));
159 if (state_addr_out_of_range || input_addr_out_of_range || output_addr_out_of_range) {
165 for (uint32_t i = 0; i < 8; ++i) {
166 state[i] =
memory.get(state_addr + i);
176 for (uint32_t i = 0; i < 16; ++i) {
177 input.emplace_back(
memory.get(input_addr + i));
188 for (
size_t i = 0; i < 16; ++i) {
193 for (
size_t i = 16; i < 64; ++i) {
200 w[i] =
modulo_sum({ { w[i - 16], w[i - 7], s0, s1 } });
214 for (
size_t i = 0; i < 64; ++i) {
226 e =
modulo_sum({ { d, prev_h, S1, ch, MemoryValue::from<uint32_t>(ROUND_CONSTANTS[i]), w[i] } });
231 a =
modulo_sum({ { prev_h, S1, ch, MemoryValue::from<uint32_t>(ROUND_CONSTANTS[i]), w[i], S0, maj } });
242 for (uint32_t i = 0; i < 8; ++i) {
243 memory.set(output_addr + i, output[i]);
246 events.emit({ .execution_clk = execution_clk,
247 .space_id = space_id,
248 .state_addr = state_addr,
249 .input_addr = input_addr,
250 .output_addr = output_addr,
257 output.fill(MemoryValue::from<FF>(0));
258 events.emit({ .execution_clk = execution_clk,
259 .space_id = space_id,
260 .state_addr = state_addr,
261 .input_addr = input_addr,
262 .output_addr = output_addr,
#define BB_ASSERT(expression,...)
#define AVM_HIGHEST_MEM_ADDRESS
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 decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept