bitcoin-nfts / bitcoin-colors

A sample NFT collection that shows the strong connection between Stacks and Bitcoin.
6 stars 2 forks source link

Number of substrings based on hash #34

Closed whoabuddy closed 1 year ago

whoabuddy commented 1 year ago

The current implementation splits the SHA-1 hash of the address into substrings based on the number of traits.

By increasing the number of traits from 2 to 8 in Bitcoin Colors (4 quadrants with foreground/background), the hashed address is divided into 8 strings with 4 characters each.

Address: bc1q962j6tf9hyxeuhj9e3u0zhgn6dqjcrlz9cljmr
Address hash: d11e86eee54f5a6042f54261a7b2b71812679263
Substring 0: d11e - 0.816864013671875
...
Substring 7: b718 - 0.7152099609375

Is there any concern over the size of the substring? Looks like an easy change could be modifying the hash algorithm, e.g.

SHA-256:

Address: bc1q962j6tf9hyxeuhj9e3u0zhgn6dqjcrlz9cljmr
Address hash: 3c39f3bc4b8dadfd1fda36065084a6b8f8d443f38b9bad2b166930e7ec51ba37
Substring 0: 3c39f3bc - 0.23525927867740393
...
Substring 7: ec51ba37 - 0.9231220611836761

SHA-512:

Address: bc1q962j6tf9hyxeuhj9e3u0zhgn6dqjcrlz9cljmr
Address hash: 3dc5ad652dccbc986add9b41922d578478bca4d4df799ec5f5d70267a9efed64c1c7bc88c8a1ce7e6ee608095bb9dd57651093d1650f78c081af59c6f30ead1f
Substring 0: 3dc5ad652dccbc98 - 0.24129756660640828
...
Substring 7: 81af59c6f30ead1f - 0.5065818892208493

Should we use SHA-256 or SHA-512 instead which produces a longer string to manipulate for the traits?

whoabuddy commented 1 year ago

@Jamil curious your thoughts here?

whoabuddy commented 1 year ago

I opened a PR to change the value, but the more I think about it, it might be worth using sha512 so we have the larger string to split up. That removes the possibility of running into the limit later if things do change with the traits (or if more traits are added via something like #35).

Testing out the differences in Python between all three algos shows performance is pretty similar. Oddly enough it seems to work fastest for me with sha512 as well.

Curious how that will translate across languages but Clarity does have a SHA-512 function.

Operation Algorithm Time
single address sha1 0m0.649s
single address sha256 0m0.681s
single address sha512 0m0.652s
test 8000 addr sha1 1m0.970s
test 8000 addr sha256 1m0.578s
test 8000 addr sha512 0m58.884s