Minh Doan
0e34dcf448
|
6 years ago | |
---|---|---|
.. | ||
LICENSE | 6 years ago | |
README.md | 6 years ago | |
api.go | 6 years ago | |
api_test.go | 6 years ago | |
example_test.go | 6 years ago | |
sha2bday.go | 6 years ago |
README.md
go-pow
go-pow
is a simple Go package to add (asymmetric) Proof of Work to your service.
To create a Proof-of-Work request (with difficulty 5), use pow.NewRequest
:
req := pow.NewRequest(5, someRandomNonce)
This returns a string like sha2bday-5-c29tZSByYW5kb20gbm9uY2U
,
which can be passed on to the client.
The client fulfils the proof of work by running pow.Fulfil
:
proof, _ := pow.Fulfil(req, []byte("some bound data"))
The client returns the proof (in this case AAAAAAAAAAMAAAAAAAAADgAAAAAAAAAb
)
to the server, which can check it is indeed a valid proof of work, by running:
ok, _ := pow.Check(req, proof, []byte("some bound data"))
Notes
-
There should be at least sufficient randomness in either the
nonce
passed toNewRequest
or thedata
passed toFulfil
andCheck
. Thus it is fine to use the same bounddata
for every client, if every client get a differentnonce
in its proof-of-work request. It is also fine to use the samenonce
in the proof-of-work request, if every client is (by the encapsulating protocol) forced to use different bounddata
. -
The work to fulfil a request scales exponentially in the difficulty parameter. The work to check it proof is correct remains constant:
Check on Difficulty=5 500000 2544 ns/op Check on Difficulty=10 500000 2561 ns/op Check on Difficulty=15 500000 2549 ns/op Check on Difficulty=20 500000 2525 ns/op Fulfil on Difficulty=5 100000 15725 ns/op Fulfil on Difficulty=10 30000 46808 ns/op Fulfil on Difficulty=15 2000 955606 ns/op Fulfil on Difficulty=20 200 6887722 ns/op
To do
- Support for equihash would be nice.
- Port to Python, Java, Javascript, ...
- Parallelize.