Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

explicitly note source of magic numbers in Hashing Limit section #29

Closed
emergent-reasons opened this issue Sep 7, 2024 · 3 comments
Closed

Comments

@emergent-reasons
Copy link
Contributor

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.

@emergent-reasons
Copy link
Contributor Author

emergent-reasons commented Sep 7, 2024

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)

@bitjson
Copy link
Owner

bitjson commented Sep 25, 2024

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 !

@bitjson bitjson closed this as completed Sep 25, 2024
@emergent-reasons
Copy link
Contributor Author

emergent-reasons commented Sep 26, 2024

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 +

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants