khovratovich / equihash Goto Github PK
View Code? Open in Web Editor NEWEquihash: memory-hard PoW with fast verification
License: Creative Commons Zero v1.0 Universal
Equihash: memory-hard PoW with fast verification
License: Creative Commons Zero v1.0 Universal
A small feature request:
$ git diff > equihash.diff
$ cat equihash.diff
diff --git a/Source/C++11/Makefile b/Source/C++11/Makefile
index 48dd431..d26d9d4 100644
--- a/Source/C++11/Makefile
+++ b/Source/C++11/Makefile
@@ -1,3 +1,3 @@
#paeq64 optimized
all:
- g++ -m64 -maes -mavx -O3 -std=c++11 "pow.cc" "pow-test.cc" "./blake/blake2b.cpp" -o equihash
+ $(CXX) -m64 -maes -mavx -O3 -std=c++11 $(CXXFLAGS) "pow.cc" "pow-test.cc" "./blake/blake2b.cpp" -o equihash
Now things work on OS X with a modern GCC/MacPorts compiler:
$ uname -a
Darwin riemann.local 12.6.0 Darwin Kernel Version 12.6.0: Wed Mar 18 16:23:48 PDT 2015; root:xnu-2050.48.19~1/RELEASE_X86_64 x86_64
$ CXX=/opt/local/bin/g++-mp-5 CXXFLAGS="-Wa,-q" make
/opt/local/bin/g++-mp-5 -m64 -maes -mavx -O3 -std=c++11 -Wa,-q "pow.cc" "pow-test.cc" "./blake/blake2b.cpp" -o equihash
$
$ time ./equihash -n 120 -k 5 -s 3
N: 120
K: 5
SEED: 3 3 3 3
Memory: 102400KiB
Testing nonce 2
Filling 2900.88 Mcycles
Resolving 3059.88 Mcycles
Resolving 2848.09 Mcycles
Resolving 2651.73 Mcycles
Resolving 2394.58 Mcycles
Resolving 1418.71 Mcycles
Time spent for n=120 k=5 102400 KiB: 15274.12 Mcycles
Solution found:
47e0c 52478 1afd2 1e6c5c d27b8 1ce199 1ac442 1e663c e3081 e3a5e 8cfea 1ef496 a4268 104c14 1b987e 1bf135 85696 fd07d 8938d 18961c 12f68 bb139 1980dc 1a5928 1b23c8 1cbca9 39831 15955c 72ac1 1a5ed1 18887 1cf8c8
real 0m6.907s
user 0m6.219s
sys 0m0.655s
And a modern Clang/MacPorts compiler:
$ CXX=/opt/local/bin/clang++-mp-3.7 CXXFLAGS="-stdlib=libc++" make
/opt/local/bin/clang++-mp-3.7 -m64 -maes -mavx -O3 -std=c++11 -stdlib=libc++ "pow.cc" "pow-test.cc" "./blake/blake2b.cpp" -o equihash
pow-test.cc:102:43: warning: format specifies type 'unsigned long long' but the
argument has type 'unsigned long' [-Wformat]
...%" PRIu64 "KiB\n", ((((uint32_t)1) << (n / (k + 1)))*LIST_LENGTH*k*sizeof(uint32_t)) / (1UL << 10));
~~~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
$
$ time ./equihash -n 120 -k 5 -s 3
N: 120
K: 5
SEED: 3 3 3 3
Memory: 102400KiB
Testing nonce 2
Filling 3059.53 Mcycles
Resolving 3449.75 Mcycles
Resolving 2931.11 Mcycles
Resolving 2861.60 Mcycles
Resolving 2593.74 Mcycles
Resolving 1488.25 Mcycles
Time spent for n=120 k=5 102400 KiB: 16384.22 Mcycles
Solution found:
47e0c 52478 1afd2 1e6c5c d27b8 1ce199 1ac442 1e663c e3081 e3a5e 8cfea 1ef496 a4268 104c14 1b987e 1bf135 85696 fd07d 8938d 18961c 12f68 bb139 1980dc 1a5928 1b23c8 1cbca9 39831 15955c 72ac1 1a5ed1 18887 1cf8c8
real 0m7.379s
user 0m6.708s
sys 0m0.633s
And Fedora 24/i686:
$ CXXFLAGS="-m32" make
g++ -m64 -maes -mavx -O3 -std=c++11 -m32 "pow.cc" "pow-test.cc" "./blake/blake2b.cpp" -o equihash
$
$ time ./equihash -n 120 -k 5 -s 3
N: 120
K: 5
SEED: 3 3 3 3
Memory: 17179971584KiB
Testing nonce 2
Filling 3796.96 Mcycles
Resolving 3672.62 Mcycles
Resolving 2116.09 Mcycles
Resolving 1837.04 Mcycles
Resolving 1500.28 Mcycles
Resolving 548.57 Mcycles
Time spent for n=120 k=5 102400 KiB: 13472.68 Mcycles
Solution found:
47e0c 52478 1afd2 1e6c5c d27b8 1ce199 1ac442 1e663c e3081 e3a5e 8cfea 1ef496 a4268 104c14 1b987e 1bf135 85696 fd07d 8938d 18961c 12f68 bb139 1980dc 1a5928 1b23c8 1cbca9 39831 15955c 72ac1 1a5ed1 18887 1cf8c8
real 0m5.948s
user 0m3.826s
sys 0m2.069s
from the paper, n=144, k=5, should require 704 MB of memory, but the code does something terrifying on my linux box here. it says it will take 1.56GB, and then goes on to take somewhere between 5 and 6 GB of memory. also, due to how memory is handled/requested, this crashes my other computer (with only 8GB of memory, maybe it's running out of swap):
./equihash -n 144 -k 5 -s 1234 & while true; do free -m; sleep 1; done
N: 144
K: 5
SEED: 1234 1234 1234 1234
Memory: 1638400KiB
Testing nonce 2
total used free shared buff/cache available
Mem: 15970 2660 10793 611 2517 12327
Swap: 4095 3 4092
total used free shared buff/cache available
Mem: 15970 3341 10111 611 2517 11646
Swap: 4095 3 4092
total used free shared buff/cache available
Mem: 15970 4028 9424 611 2517 10959
Swap: 4095 3 4092
total used free shared buff/cache available
Mem: 15970 4723 8730 611 2517 10264
Swap: 4095 3 4092
total used free shared buff/cache available
Mem: 15970 5409 8043 611 2517 9578
Swap: 4095 3 4092
total used free shared buff/cache available
Mem: 15970 6118 7335 611 2517 8869
Swap: 4095 3 4092
total used free shared buff/cache available
Mem: 15970 6845 6607 611 2517 8141
Swap: 4095 3 4092
total used free shared buff/cache available
Mem: 15970 7577 5875 611 2517 7410
Swap: 4095 3 4092
total used free shared buff/cache available
Mem: 15970 8311 5142 611 2517 6676
Swap: 4095 3 4092
total used free shared buff/cache available
Mem: 15970 8496 4957 611 2517 6491
Swap: 4095 3 4092
total used free shared buff/cache available
Mem: 15970 8496 4957 611 2517 6491
Swap: 4095 3 4092
total used free shared buff/cache available
Mem: 15970 8495 4957 611 2517 6492
Swap: 4095 3 4092
I want to adapt this algorithm in order to implement a ZCash miner. However, analysing the code I have some doubts about how XOR is computed in the various steps of the algorithm.
In function void Equihash::FillMemory(uint32_t length)
hashes are generated in the following way:
Lines 67 to 79 in 4140bd6
Why, at row 74, only the most significant n/(k + 1) bits of buf[j]
are stored and why the remaining 32-n/(k+1) bits are not considered?
In function void Equihash::ResolveCollisions(bool store)
tuples' blocks are XORed generating a new tupleList. Neveretheless, in this way, if I have correctly understood, in each step of the algorithm, every n/(k+1) bits are not considered sequentially.
I try to make an example:
k=9, n=200
On each step I'm interested in the next 20 bits i.e. bits from 0 to 19 on first step, 0 to 39 on second etc.
In this algorithm it seems to me that in the first step are considered bits from 0 to 19, 32 to 52 on second etc because the shift register operation cut off the bits from 20 to 31
@khovratovich
Not, sure if I can phrase my query right. I'm not that technical into C ++, just wondering how can we implement and integrate equihash algo into our mining application? Any hint, guide or reference will be appreciated to achieve this.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.