Skip to content

Latest commit

 

History

History
97 lines (71 loc) · 2.48 KB

File metadata and controls

97 lines (71 loc) · 2.48 KB

← Back to Instruction Set: Quick Reference

SHA256COMPRESSION

SHA-256 compression

Opcode 0x40

M[outputOffset:outputOffset+8] = sha256compress(/*state=*/M[stateOffset:stateOffset+8], /*inputs=*/M[inputsOffset:inputsOffset+16])

Details

Computes the SHA-256 compression function on an 8-word state and 16-word input block. State and inputs must be Uint32. Outputs 8 Uint32 words.

Gas Costs

Component Value Scales with
L2 Base 12288 -
DA Base 0 -
L2 Addressing 3 3 L2 gas per indirect memory offset
3 L2 gas per relative memory offset

* See Gas Metering for details on how gas costs are computed and applied.

Operands

Name Type Description
outputOffset Memory offset Memory offset where the 8-word output state will be written
stateOffset Memory offset Memory offset of the 8-word SHA-256 state
inputsOffset Memory offset Memory offset of the 16-word input block

Wire Formats

See Wire Format page for an explanation of wire format variants and opcode naming (e.g., why ADD_8 vs ADD_16).

SHA256COMPRESSION (Opcode 0x40):

---
title: "SHA256COMPRESSION"
config:
  packet:
    bitsPerRow: 64
---
packet-beta
0-7: "Opcode (0x40)"
8-15: "Addressing modes"
16-31: "Operand: outputOffset"
32-47: "Operand: stateOffset"
48-63: "Operand: inputsOffset"
Loading

Addressing Modes

See Addressing page for a detailed explanation.

8-bit bitmask: 2 bits per memory offset operand (indirect flag + relative flag)

Memory offset operands (outputOffset, stateOffset, inputsOffset) are encoded as follows:

---
title: "Addressing Mode Bitmask"
config:
  packet:
    bitWidth: 128
    bitsPerRow: 8
---
packet-beta
  0: "outputOffset is indirect"
  1: "outputOffset is relative"
  2: "stateOffset is indirect"
  3: "stateOffset is relative"
  4: "inputsOffset is indirect"
  5: "inputsOffset is relative"
  6: "Unused"
  7: "Unused"
Loading

Tag Checks

  • T[stateOffset:stateOffset+8] == UINT32
  • T[inputsOffset:inputsOffset+16] == UINT32

Tag Updates

  • T[outputOffset:outputOffset+8] = UINT32

Error Conditions

  • INVALID_TAG: State or inputs are not Uint32
  • MEMORY_ACCESS_OUT_OF_RANGE: Memory offset operand exceeds addressable memory

← Back to Instruction Set: Quick Reference