{"eip":7797,"title":"Double speed for hash_tree_root","description":"Double the performance of hash_tree_root by customizing SHA-256","authors":["Etan Kissling (@etan-status)"],"status":"Stagnant","type":"Standards Track","category":"Core","created":"2024-10-23","discussionsTo":"https://ethereum-magicians.org/t/eip-7797-double-speed-for-hash-tree-root/21447","repo":"EIPs","label":"EIP-7797","officialUrl":"https://eips.ethereum.org/EIPS/eip-7797","sourceUrl":"https://github.com/ethereum/EIPs/blob/master/EIPS/eip-7797.md","url":"https://eips.huatuo.xyz/eip-7797/","tldr":{"en":"Proposes a consensus-layer hash variant, SHA-256-512, that skips SHA-256's padding block for the fixed 64-byte inputs of SSZ hash_tree_root, roughly halving hashing work for beacon state roots.","ja":"コンセンサスレイヤーのハッシュ派生である SHA-256-512 を提案する。SSZ の hash_tree_root が扱う固定 64 バイト入力に対して SHA-256 のパディングブロックを省き、ビーコンステートルートのハッシュ計算量をおよそ半分にする。","ko":"SSZ hash_tree_root의 고정 64바이트 입력에 대해 SHA-256의 패딩 블록을 건너뛰어, 비콘 상태 루트의 해시 작업량을 대략 절반으로 줄이는 합의 계층 해시 변형 SHA-256-512를 제안한다.","zh":"提出一种共识层哈希变体 SHA-256-512，对于 SSZ hash_tree_root 的固定 64 字节输入，跳过 SHA-256 的填充块，使信标状态根的哈希计算量大约减半。"},"tags":["consensus","ssz","sha256","hashing","performance"],"explainers":{"en":{"lang":"en","tldr":"Proposes a consensus-layer hash variant, SHA-256-512, that skips SHA-256's padding block for the fixed 64-byte inputs of SSZ hash_tree_root, roughly halving hashing work for beacon state roots.","tags":["consensus","ssz","sha256","hashing","performance"],"related":[7495,7916],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-7797/","markdown":"## What problem does it solve?\n\nThe consensus layer identifies every object (blocks, the beacon state, attestations…) by its SSZ `hash_tree_root`: data is split into 32-byte chunks and pairs of chunks are hashed together, level by level, until one root is left. With well over a million validators this is a major CPU cost. The author measures the state-root step at about 25 % of CPU time on the Holesky testnet, even with caching and hardware-accelerated SHA-256.\n\nEvery hash in that tree has the same input: exactly two 32-byte chunks, 512 bits. Standard SHA-256 still pads that input, which creates a **second 512-bit block** whose contents are always the same. Half the work is spent compressing a block that carries no information.\n\n## How it works\n\n- Define **SHA-256-512**: SHA-256 with the preprocessing (padding) step removed, accepting only inputs of exactly 512 bits. The input is processed as one SHA-256 message block, giving one compression call instead of two.\n- For each composite SSZ type in use, clients add a twin type that merkleizes with SHA-256-512. From the activating fork on, the new types should be preferred.\n- Serialization, generalized indices and field meanings do not change; only the hash values do.\n- Historical objects, and things like signing roots over pre-fork data or `BeaconState.latest_block_header`, may need to be re-hashed with the original SHA-256 to recover their old roots. `DepositData` and `VoluntaryExit` may keep regular SHA-256.\n- Hardware acceleration still applies, since it implements the block compression function, which is unchanged.\n\n## Sample code\n\nPseudocode for hashing two child nodes:\n\n```python\nIV = SHA256_INITIAL_STATE  # the standard 8 x 32-bit words\n\ndef sha256_merkle(left: bytes, right: bytes) -\u003e bytes:\n    # today: 64-byte input + fixed padding block = 2 compressions\n    return hashlib.sha256(left + right).digest()\n\ndef sha256_512(left: bytes, right: bytes) -\u003e bytes:\n    assert len(left) == len(right) == 32\n    state = sha256_compress(IV, left + right)  # 1 compression, no padding\n    return state_to_bytes(state)\n```\n\nThe fixed padding block that SHA-256-512 drops (bytes 0x40 to 0x7F):\n\n```text\n80 00 00 ... 00 | 00 00 00 00 00 00 02 00   # 0x80 marker, zeros, bit length = 512\n```\n\n## Things to know\n\n- Status is **Stagnant**: it is not scheduled for any fork.\n- Contracts and light clients that verify beacon-chain proofs (for example through the beacon block root) would need updating and would have to choose the right hash for each fork's data.\n- SHA-256-512 output for some 512-bit inputs equals regular SHA-256 of a shorter message, so it **must not be used outside SSZ merkleization**. Within SSZ this is safe because SSZ never hashes anything other than 512-bit inputs.\n- The author argues this also prepares the ground for a future switch to a ZK-friendly hash, because the places where historical hashing must be kept would already be identified.\n"},"ja":{"lang":"ja","tldr":"コンセンサスレイヤーのハッシュ派生である SHA-256-512 を提案する。SSZ の hash_tree_root が扱う固定 64 バイト入力に対して SHA-256 のパディングブロックを省き、ビーコンステートルートのハッシュ計算量をおよそ半分にする。","tags":["consensus","ssz","sha256","hashing","performance"],"related":[7495,7916],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-7797/","markdown":"## 何を解決するのか\n\nコンセンサスレイヤーは、あらゆるオブジェクト（ブロック、ビーコンステート、アテステーションなど）を SSZ の `hash_tree_root` で識別します。データは 32 バイトのチャンクに分割され、チャンクのペアが、ルートが 1 つになるまで階層ごとにハッシュされます。バリデーターが 100 万をはるかに超える現在、これは大きな CPU コストです。著者は、キャッシュとハードウェアアクセラレーション付き SHA-256 を使っても、Holesky テストネットでステートルートの計算が CPU 時間の約 25 % を占めると測定しています。\n\nこのツリーのすべてのハッシュは同じ入力、つまりちょうど 2 つの 32 バイトチャンク（512 ビット）を持ちます。標準の SHA-256 はこの入力にもパディングを施すため、内容が常に同じ**2 つ目の 512 ビットブロック**が生じます。情報を持たないブロックの圧縮に、作業の半分が費やされているのです。\n\n## 仕組み\n\n- **SHA-256-512** を定義します。前処理（パディング）のステップを取り除いた SHA-256 で、ちょうど 512 ビットの入力のみを受け付けます。入力は 1 つの SHA-256 メッセージブロックとして処理され、圧縮呼び出しは 2 回ではなく 1 回です。\n- 使用される複合 SSZ 型ごとに、クライアントは SHA-256-512 でマークル化する対の型を追加します。有効化されるフォーク以降は、新しい型が優先されるべきです。\n- シリアライズ、一般化インデックス、フィールドの意味は変わりません。変わるのはハッシュ値だけです。\n- 過去のオブジェクトや、フォーク前のデータに対する署名ルート、`BeaconState.latest_block_header` などは、古いルートを復元するために元の SHA-256 で再ハッシュする必要があるかもしれません。`DepositData` と `VoluntaryExit` は通常の SHA-256 のままでかまいません。\n- ハードウェアアクセラレーションは引き続き使えます。変更されないブロック圧縮関数を実装しているためです。\n\n## サンプルコード\n\n2 つの子ノードをハッシュする擬似コード:\n\n```python\nIV = SHA256_INITIAL_STATE  # the standard 8 x 32-bit words\n\ndef sha256_merkle(left: bytes, right: bytes) -\u003e bytes:\n    # today: 64-byte input + fixed padding block = 2 compressions\n    return hashlib.sha256(left + right).digest()\n\ndef sha256_512(left: bytes, right: bytes) -\u003e bytes:\n    assert len(left) == len(right) == 32\n    state = sha256_compress(IV, left + right)  # 1 compression, no padding\n    return state_to_bytes(state)\n```\n\nSHA-256-512 が省く固定のパディングブロック（バイト 0x40 から 0x7F）:\n\n```text\n80 00 00 ... 00 | 00 00 00 00 00 00 02 00   # 0x80 marker, zeros, bit length = 512\n```\n\n## 知っておくべきこと\n\n- ステータスは **Stagnant** です。どのフォークにも予定されていません。\n- ビーコンチェーンの証明を検証するコントラクトやライトクライアント（たとえばビーコンブロックルート経由）は更新が必要で、フォークごとのデータに対して正しいハッシュを選ぶ必要があります。\n- 一部の 512 ビット入力に対する SHA-256-512 の出力は、より短いメッセージの通常の SHA-256 と等しくなるため、**SSZ のマークル化以外では使ってはなりません**。SSZ の中では、512 ビット以外の入力をハッシュしないため安全です。\n- 著者は、過去のハッシュを保持すべき箇所があらかじめ特定されるため、将来 ZK フレンドリーなハッシュへ切り替える土台にもなると主張しています。\n"},"ko":{"lang":"ko","tldr":"SSZ hash_tree_root의 고정 64바이트 입력에 대해 SHA-256의 패딩 블록을 건너뛰어, 비콘 상태 루트의 해시 작업량을 대략 절반으로 줄이는 합의 계층 해시 변형 SHA-256-512를 제안한다.","tags":["consensus","ssz","sha256","hashing","performance"],"related":[7495,7916],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-7797/","markdown":"## 어떤 문제를 해결하나요?\n\n합의 계층은 모든 객체(블록, 비콘 상태, 증명 등)를 SSZ `hash_tree_root`로 식별합니다. 데이터는 32바이트 청크로 나뉘고, 루트 하나가 남을 때까지 청크 쌍이 계층별로 해시됩니다. 검증자가 100만 명을 훌쩍 넘는 상황에서 이는 큰 CPU 비용입니다. 작성자는 캐싱과 하드웨어 가속 SHA-256을 쓰더라도 Holesky 테스트넷에서 상태 루트 단계가 CPU 시간의 약 25 %를 차지한다고 측정했습니다.\n\n이 트리의 모든 해시는 입력이 같습니다. 정확히 32바이트 청크 두 개, 512비트입니다. 표준 SHA-256은 이 입력에도 패딩을 적용해 내용이 항상 같은 **두 번째 512비트 블록**이 생깁니다. 정보가 없는 블록을 압축하는 데 작업의 절반이 쓰이는 셈입니다.\n\n## 어떻게 동작하나요?\n\n- **SHA-256-512**를 정의합니다. 전처리(패딩) 단계를 없앤 SHA-256이며 정확히 512비트 입력만 받습니다. 입력은 하나의 SHA-256 메시지 블록으로 처리되어 압축 호출이 두 번이 아닌 한 번입니다.\n- 사용 중인 각 복합 SSZ 타입에 대해, 클라이언트는 SHA-256-512로 머클화하는 쌍둥이 타입을 추가합니다. 활성화되는 포크부터는 새 타입이 우선되어야 합니다.\n- 직렬화, 일반화 인덱스, 필드 의미는 바뀌지 않으며, 바뀌는 것은 해시 값뿐입니다.\n- 과거 객체, 그리고 포크 이전 데이터에 대한 서명 루트나 `BeaconState.latest_block_header` 같은 것은 예전 루트를 복원하기 위해 원래의 SHA-256으로 다시 해시해야 할 수 있습니다. `DepositData`와 `VoluntaryExit`는 일반 SHA-256을 유지해도 됩니다.\n- 하드웨어 가속은 그대로 적용됩니다. 바뀌지 않은 블록 압축 함수를 구현한 것이기 때문입니다.\n\n## 샘플 코드\n\n두 자식 노드를 해시하는 의사 코드:\n\n```python\nIV = SHA256_INITIAL_STATE  # the standard 8 x 32-bit words\n\ndef sha256_merkle(left: bytes, right: bytes) -\u003e bytes:\n    # today: 64-byte input + fixed padding block = 2 compressions\n    return hashlib.sha256(left + right).digest()\n\ndef sha256_512(left: bytes, right: bytes) -\u003e bytes:\n    assert len(left) == len(right) == 32\n    state = sha256_compress(IV, left + right)  # 1 compression, no padding\n    return state_to_bytes(state)\n```\n\nSHA-256-512가 생략하는 고정 패딩 블록(바이트 0x40~0x7F):\n\n```text\n80 00 00 ... 00 | 00 00 00 00 00 00 02 00   # 0x80 marker, zeros, bit length = 512\n```\n\n## 알아둘 점\n\n- 상태는 **Stagnant**입니다. 어떤 포크에도 예정되어 있지 않습니다.\n- 비콘 체인 증명을 검증하는 컨트랙트와 라이트 클라이언트(예: 비콘 블록 루트를 통해)는 업데이트가 필요하며, 포크별 데이터에 맞는 해시를 골라야 합니다.\n- 일부 512비트 입력에 대한 SHA-256-512 출력은 더 짧은 메시지의 일반 SHA-256과 같아지므로 **SSZ 머클화 밖에서 사용해서는 안 됩니다**. SSZ 안에서는 512비트 입력 외에는 해시하지 않으므로 안전합니다.\n- 작성자는 과거 해시를 유지해야 하는 곳이 이미 파악되어 있을 것이므로, 앞으로 ZK 친화적인 해시로 전환하는 기반도 마련된다고 주장합니다.\n"},"zh":{"lang":"zh","tldr":"提出一种共识层哈希变体 SHA-256-512，对于 SSZ hash_tree_root 的固定 64 字节输入，跳过 SHA-256 的填充块，使信标状态根的哈希计算量大约减半。","tags":["consensus","ssz","sha256","hashing","performance"],"related":[7495,7916],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-7797/","markdown":"## 它解决什么问题？\n\n共识层通过 SSZ 的 `hash_tree_root` 标识每一个对象（区块、信标状态、证明等）：数据被切分为 32 字节的块，每两块一对逐层哈希，直到只剩一个根。在验证者远超一百万的情况下，这是一笔主要的 CPU 开销。作者测得，即便使用了缓存和硬件加速的 SHA-256，在 Holesky 测试网上，状态根这一步仍约占 CPU 时间的 25 %。\n\n这棵树中的每次哈希输入都相同：恰好两个 32 字节的块，共 512 位。标准 SHA-256 仍会对该输入进行填充，从而产生**第二个 512 位块**，其内容始终相同。一半的工作花在了压缩一个不携带任何信息的块上。\n\n## 它如何运作\n\n- 定义 **SHA-256-512**：去掉预处理（填充）步骤的 SHA-256，只接受恰好 512 位的输入。输入作为一个 SHA-256 消息块处理，只需一次压缩调用，而不是两次。\n- 对于使用中的每种复合 SSZ 类型，客户端增加一个使用 SHA-256-512 做 Merkle 化的孪生类型。从激活分叉起，应优先使用新类型。\n- 序列化、广义索引和字段含义都不变，变的只有哈希值。\n- 历史对象，以及对分叉前数据的签名根或 `BeaconState.latest_block_header` 等，可能需要用原始 SHA-256 重新哈希才能恢复其旧的根。`DepositData` 和 `VoluntaryExit` 可以继续使用常规 SHA-256。\n- 硬件加速仍然适用，因为它实现的是区块压缩函数，而该函数没有改变。\n\n## 示例代码\n\n对两个子节点进行哈希的伪代码：\n\n```python\nIV = SHA256_INITIAL_STATE  # the standard 8 x 32-bit words\n\ndef sha256_merkle(left: bytes, right: bytes) -\u003e bytes:\n    # today: 64-byte input + fixed padding block = 2 compressions\n    return hashlib.sha256(left + right).digest()\n\ndef sha256_512(left: bytes, right: bytes) -\u003e bytes:\n    assert len(left) == len(right) == 32\n    state = sha256_compress(IV, left + right)  # 1 compression, no padding\n    return state_to_bytes(state)\n```\n\nSHA-256-512 所省去的固定填充块（字节 0x40 到 0x7F）：\n\n```text\n80 00 00 ... 00 | 00 00 00 00 00 00 02 00   # 0x80 marker, zeros, bit length = 512\n```\n\n## 需要注意\n\n- 状态为 **Stagnant**：没有被安排进任何分叉。\n- 验证信标链证明的合约和轻客户端（例如通过信标区块根）需要更新，并且必须为每个分叉的数据选择正确的哈希。\n- 对于某些 512 位输入，SHA-256-512 的输出等于对一条更短消息的常规 SHA-256，因此**不得在 SSZ Merkle 化之外使用**。在 SSZ 内部这是安全的，因为 SSZ 从不对 512 位以外的输入做哈希。\n- 作者认为，这也为将来切换到对零知识证明友好的哈希铺平了道路，因为必须保留历史哈希的地方届时已经被明确标识出来。\n"}}}
