This is a concept implementation of a proof-of-work (PoW) algorithm proposal for Monero (but it's usable for any PoW cryptocurrency). Credits to @hyc for the original idea to use random javascript execution to achieve ASIC resistance.
The primary general-purpose hash function used by RandomJS is Blake2b with output size of 256 bits. This hash function was chosen for 3 primary reasons:
In the description below, Blake2b(X)
and Blake2b(K,X)
refer to the plain and keyed variant of Blake2b, respectively (both with 256-bit output length). N >= 0
is a configurable parameter.
H
.K = Blake2b(H)
.P
using K
as the seed.A = Blake2b(K, P)
.P
and capture its output Q
.B = Blake2b(K, Q)
.A
and B
differ, go back to step 1.B
.R = (A XOR B)
.PoW = Blake2b(K, R)
.PoW
doesn't meet the difficulty target, go back to step 1.H, R
as the result to be included in the block.Finding and verifying a solution takes on average 3×2N+1 Blake2b hash calculations, 2N random javascript program generations and 2N javascript executions.
Input: H, R
from the received block.
K = Blake2b(H)
.PoW = Blake2b(K, R)
.PoW
doesn't meet the difficulty target, discard the block.P
using K
as the seed.A = Blake2b(K, P)
.A
and R
differ, discard the block.A
.P
and capture its output Q
.B = Blake2b(K, Q)
.R != (A XOR B)
, discard the block.Verifying a valid solution requires 4 Blake2b hash calculations, one random program generation and one javascript execution.
In case of an DoS attack attempt, just 2 Blake2b hash calculations are required to discard the block. Otherwise an attacker needs to calculate substantial number of Blake2b hashes (equal to the current block difficulty) to force the verifying party to run the relatively costly (~few milliseconds) javascript generation and execution procedure.
The generator is documented in generator.md.
RandomJS is currently using the XS engine, which is a small and efficient implementatation developed for use in embedded devices.
See build.md.
Support the development of RandomJS by donating.
XMR:
4B9nWtGhZfAWsTxWujPDGoWfVpJvADxkxJJTmMQp3zk98n8PdLkEKXA5g7FEUjB8JPPHdP959WDWMem3FPDTK2JUU1UbVHo