You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

比特币区块头SHA256哈希填充规则及剩余48字节计算问询

Great question—this ties together standard SHA-256 mechanics with how Bitcoin uses them for block validation. Let’s break this down step by step:

Bitcoin Block Header SHA-256 Padding Scheme

Bitcoin doesn’t invent a custom padding method here—it strictly follows the standard SHA-256 padding rules laid out in the FIPS 180-4 specification. The process works like this for any input, including the 80-byte block header:

  • First, append a single 1 bit to the end of the raw block header data.
  • Next, add as many 0 bits as needed so that the total length of the data (before adding the final length field) is exactly 448 bits modulo 512. This leaves exactly 64 bits of space to store the original input’s length.
  • Finally, append a 64-bit big-endian integer that represents the original input length in bits.

Where the 48 Bytes of Padding Come From

You’re correct that the block header is 80 bytes (640 bits), and SHA-256 requires inputs to be multiples of 512 bits (64 bytes) after padding. Let’s do the math to unpack the 48-byte padding:

  1. Start with the raw block header: 80 bytes = 640 bits.
  2. After adding the mandatory 1 bit, we have 641 bits of data.
  3. We need the length after adding zeros to hit 448 bits modulo 512. Let’s calculate the number of zeros needed:
    • 641 divided by 512 leaves a remainder of 129 bits.
    • To get to 448 bits (the target modulo 512), we need 448 - 129 = 319 additional 0 bits.
  4. Then we add the 64-bit length field (which is 8 bytes) to record the original 640-bit length.
  5. Total padding bits: 1 (the initial 1 bit) + 319 zeros + 64 length bits = 384 bits.
  6. Convert that to bytes: 384 ÷ 8 = 48 bytes.

When you combine the original 80-byte header with this 48-byte padding, you get a 128-byte (1024-bit) input—exactly two 512-bit blocks, which is the required input size for SHA-256’s internal processing.

One quick extra note: Bitcoin uses double SHA-256 (SHA256(SHA256(block_header))) for block hashes. The padding happens separately for each hash pass, but the first pass uses the 80+48 byte input we just walked through.

内容的提问来源于stack exchange,提问作者user170174

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 04:22:28