Bitcoin Forum

Bitcoin => Project Development => Topic started by: weex on January 21, 2016, 02:27:51 AM



Title: Best choice of hashcash function today
Post by: weex on January 21, 2016, 02:27:51 AM
I want to make it reasonably hard to spam a new network that will operate via signed documents. I'm thinking of including a nonce in the document and setting a difficulty target but my question is, what hash function would you choose today for an anti-spam application. I'd like to target it at about 10-20 seconds of hashing on a modern laptop or desktop but it would suck to hear that some ASIC can do it in 1 sec or 10ms. Thoughts?


Title: Re: Best choice of hashcash function today
Post by: achow101 on January 21, 2016, 02:42:13 AM
This is the same dilemma altcoin devs have with choosing good ASIC-resistant hash algos  :D

You could use just SHA256 (not SHA256d which is used in Bitcoin mining ASICs) but it is a relatively fast function so it may not be applicable. Set the difficulty high enough and it could work.

Or you can use other slower algorithms like whirlpool. Or you can use memory intensive algorithms like scrypt (but not scrypt since scrypt ASICs exist). Those options will make ASICs harder to work so they are more ASIC resistant than SHA2 algorithms.


Title: Re: Best choice of hashcash function today
Post by: weex on January 21, 2016, 09:07:43 AM
Played around with scrypt a little bit. Only changed the 16384 default to 32768 but I'm not sure if that's enough of a change from what scrypt ASICs do to be effective. In any case, ran this with the 0x04ffff.... target to get

Code:
import scrypt
import time
from bitcoin.core import x, b2x

start = time.time()
count = 1
if __name__ == '__main__':
    h1 = scrypt.hash(str(time.time()), 'random salt', 32768, 8, 1, 16)
    while 1:
        h1 = scrypt.hash(h1, 'random salt', 32768, 8, 1, 16)
        count += 1
        if h1 < x('04ffffffffffffffffffffffffffffff'):
            print(b2x(h1), time.time() - start, count)

Code:
$ python dochashcash.py
('0054d812ff175cbe77652ecbf2a9bb89', 2.9400529861450195, 29)
('001a28b31c37f50dc28ff98c98823cdf', 8.692596912384033, 85)
('0413606381ecb582ef1557484d8e00fc', 9.584491968154907, 94)
('00859f4ed4cd3f3e741a8662e6286cc1', 16.008608102798462, 156)
('03834f8386fd6d84ed1f28f3e509e2d1', 19.082252979278564, 187)
('011061508daa0a82c6484090142ef9de', 20.083352088928223, 197)
('01617152783622a3b8fa0f2098344d6a', 28.243431091308594, 275)
('018c126d001906ddeaaf3af9622947b8', 75.0232720375061, 728)