bitjson/bch-vm-limits

explicitly note source of magic numbers in Hashing Limit section

Closed this issue · 3 comments

The "Hashing Limit" section has a handful of unnamed, bare constants that I didn't find an explanation for:

  • 7: ((41 + unlocking_bytecode_length) * 7) / 2
  • 1, 8, 64: 1 + ((message_length + 8) / 64) + (is_double ? 1 : 0); (the first 1+, not the conditional)

Each of them deserves a name and/or explanation. In contrast, e.g. the numbers 41, 800 have explanations.

I can guess at or infer the source of them based on other parts of the spec, but I'm not totally confident about my inference. It should be in the spec even if it's explained here.

My guess is that 7 is a conservatively selected tuning number to match up with previous implicit limits.

1, 8 and 64 though... I dunno. I think 64 is explained in a note, but the linkage isn't explicit, at least not for someone with my level of knowledge.

Note from Calin:

  • first 1: account for hash algos doing magic shit on 1 64-byte chunk anyway to "finalize" the hash algo
  • 8 - hash algos do some weird padding where they embed a length in the last 8 bytes.. so that needs to be accounted for...
  • 64 - just all hash algos use 64 byte blocks so the final number you want is "how many blocks did i process"? so the 64 is the divisor.. (ER: this is what I suspected from the note, but the link between the magic number and the explanation is ambiguous)

The algorithm is also now detailed in Explanation of Digest Iteration Formula: https://github.com/bitjson/bch-vm-limits#digest-iteration-count. Thanks @emergent-reasons !

The linkages are still not clear to me. To the point that I tried to write a normal-human readable explanation and wasn't totally confident about what I tried to write. For example for 64, do a ctrl-f and imagine the reader doesn't know everything in full detail. There are a handful of 64's spread all over the place. Which one is it? None of them? One of them? A few?

Same for the 1 +