#include <sha256.hpp>
Definition at line 17 of file sha256.hpp.
◆ Sha256()
◆ compression()
Execute the SHA-256 compression function: read state and input from memory, compress, and write output.
Events are emitted in the following flavors:
- Normal execution: all fields populated (state, input of 16 elements, computed output).
- Error (address out of range, invalid state tag, or invalid input tag): state is partially populated (up to the point of failure), input contains elements read before the error, output is zeroed.
In all cases the event is emitted before re-throwing the exception.
- Parameters
-
| memory | The memory interface to read state/input from and write output to. |
| state_addr | The starting address of the 8-element hash state in memory. |
| input_addr | The starting address of the 16-element hash input in memory. |
| output_addr | The starting address where the 8-element output will be written. |
- Exceptions
-
Implements bb::avm2::simulation::Sha256Interface.
Definition at line 135 of file sha256.cpp.
◆ modulo_sum()
Sum a span of U32 MemoryValues and return the result modulo 2^32.
- Parameters
-
| values | A span of MemoryValue elements, each expected to hold a uint32_t. |
- Returns
- The sum reduced modulo 2^32, wrapped in a MemoryValue.
- Precondition
- Every element in values must be tagged as U32. This is an internal helper; all callers (sha256_compress) guarantee the precondition by validating tags before invoking this function. The cast exception is therefore never thrown in practice.
- Note
- Asserts that both the low and high 32-bit halves of the 64-bit sum are in range.
Definition at line 93 of file sha256.cpp.
◆ ror()
Perform a 32-bit right rotation on a MemoryValue.
- Parameters
-
| x | The value to rotate (must hold a uint32_t). |
| shift | The number of bits to rotate right (must be non-zero and < 32). |
- Returns
- The rotated 32-bit result wrapped in a MemoryValue.
- Precondition
- x must be tagged as U32. This is an internal helper; all callers (sha256_compress) guarantee the precondition by validating tags before invoking this function. The cast exception is therefore never thrown in practice.
-
shift must satisfy 0 < shift < 32. A shift >= 32 causes undefined behavior per the C++ standard for 32-bit operands. A shift == 0 also causes undefined behavior because the reconstruction
lo << (32 - shift) becomes a left shift by 32. All callers use fixed SHA-256 rotation amounts (2, 6, 7, 11, 13, 17, 18, 19, 22, 25), so this precondition is always satisfied.
- Note
- Asserts that the lower bits extracted during decomposition are in range (lo < 2^shift).
Definition at line 43 of file sha256.cpp.
◆ shr()
Perform a 32-bit right shift on a MemoryValue.
- Parameters
-
| x | The value to shift (must hold a uint32_t). |
| shift | The number of bits to shift right (only 3 and 10 are used in SHA-256). |
- Returns
- The shifted 32-bit result wrapped in a MemoryValue.
- Precondition
- x must be tagged as U32. This is an internal helper; all callers (sha256_compress) guarantee the precondition by validating tags before invoking this function. The cast exception is therefore never thrown in practice.
-
shift must satisfy shift < 32. A shift >= 32 would cause undefined behavior per the C++ standard for 32-bit operands. All callers use fixed SHA-256 shift amounts (3, 10), so this precondition is always satisfied.
- Note
- Asserts that the lower bits extracted during decomposition are in range (lo < 2^shift).
Definition at line 70 of file sha256.cpp.
◆ bitwise
◆ events
◆ execution_id_manager
◆ gt
The documentation for this class was generated from the following files:
- src/barretenberg/vm2/simulation/gadgets/sha256.hpp
- src/barretenberg/vm2/simulation/gadgets/sha256.cpp