Thanks, we should make those more explicit.
The 7
is just part of a possible formula for 3.5
, without * 7
, for 0.5
:
For standard transactions, the maximum density is approximately
0.5
hash digest iterations per spending input byte; for block validation, the maximum density is approximately3.5
hash digest iterations per spending input byte. See Rationale: Selection of Hashing Limit and Rationale: Use of Input-Length Based Densities.Given the spending input’s unlocking bytecode length (A.K.A.
scriptSig
), hash digest iteration limits may be calculated with the following C functions:int max_standard_iterations (int unlocking_bytecode_length) { return (41 + unlocking_bytecode_length) / 2; } int max_consensus_iterations (int unlocking_bytecode_length) { return ((41 + unlocking_bytecode_length) * 7) / 2; }
And the hash digest iteration formula is (I believe) the most efficient way to calculate what goes on inside all of our hash functions:
Note on 64-Byte Message Block Size
Each VM-supported hashing algorithm – RIPEMD-160, SHA-1, and SHA-256 – uses a Merkle–Damgård construction with a
block size
of 512 bits (64 bytes), so the number of message blocks/digest iterations required for every message size is equal among all VM-supported hashing functions.
I just double checked it with a few different LLMs, but would appreciate others confirming if that formula is ideal. (Of course, it’s technically possible for implementations to add a counter rather than use this formula, but it’s somewhat less likely they’d want to modify their hashing implementation to add an internal counter.)
We could probably also clarify that note to be more explicit about the 8
and + 1
accounting for padding. Maybe:
Explanation of Digest Iteration Formula
Each VM-supported hashing algorithm – RIPEMD-160, SHA-1, and SHA-256 – uses a Merkle–Damgård construction with a 512-bit (64-byte) message block length, so the number of message blocks/digest iterations required for every message length is equal among all VM-supported hashing functions. The specified formula correctly accounts for padding: hashed messages are padded with a
1
bit, followed by enough0
bits and a 64-bit (8-byte) message length to produce a padded message with a length that is a multiple of 512 bits. Note that even small messages require at least one hash digest iteration, and an additional hash digest iteration is required for each additional 512-bit message block in the padded message.
How’s that explanation?