Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b3c83e2
adds base libraries for gpu mining
AgeManning Oct 29, 2016
96f36ba
name changes and makefile addition
AgeManning Oct 29, 2016
cf889c6
gpu miner init
nginnever Oct 29, 2016
e7f28ba
changed name of silentarmy compiled header
AgeManning Oct 29, 2016
c09636d
opencl work
nginnever Oct 29, 2016
5e35125
correct name change
AgeManning Oct 29, 2016
49ce2f0
Merge branch 'master' of https://github.com/nginnever/zcash
AgeManning Oct 29, 2016
482f3d8
modified names and added gpu support in init.cpp
AgeManning Oct 29, 2016
014efb3
builf fail
nginnever Oct 29, 2016
56b41ab
small changes to miner.cpp for building
AgeManning Oct 29, 2016
93bd2ff
correcting build issues
AgeManning Oct 29, 2016
18fbcb7
modying build
AgeManning Oct 29, 2016
d4a0631
build issues
AgeManning Oct 29, 2016
821e8c1
solo working, very slowly
nginnever Oct 29, 2016
050a47a
solver doesn't hang, invalid sols
nginnever Oct 29, 2016
3339745
solo mining on single card and basic infrastructure for multi gpu sup…
AgeManning Oct 29, 2016
3764d38
fixing threading issues
AgeManning Oct 30, 2016
76767f9
correcting nonce issues
AgeManning Oct 30, 2016
08ada7f
fix for -equihashsolver=tromp option
AgeManning Oct 30, 2016
b8f3459
192 bit nonce fix and block validation fix
omaralvarez Oct 30, 2016
af9fa73
Fixed use of genproclimit per GPU in miner.cpp
hellcatz Oct 30, 2016
1e8921a
Allow -GPU and -G options
omaralvarez Oct 30, 2016
f454d9c
Fixed mem leak
omaralvarez Oct 30, 2016
a1c037c
Merge pull request #1 from nginnever/multi-solo
nginnever Oct 30, 2016
07ddb14
Added GPU thread count memory limits. The max number of threads up to…
hellcatz Oct 30, 2016
4d91deb
temporary print fix
nginnever Oct 31, 2016
6420d2f
Merge pull request #3 from nginnever/multi-solo
nginnever Oct 31, 2016
2f3a4bd
updated silentarmy kernel. Support for GCN1 cards.
AgeManning Oct 31, 2016
f8ee44f
Update README.md
nginnever Nov 7, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Zcash 1.0.0
Zcash 1.0.0 (This is not up to date with zcash master)
===========

What is Zcash?
Expand Down
9 changes: 6 additions & 3 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ AC_ARG_ENABLE([glibc-back-compat],

AC_ARG_WITH([protoc-bindir],[AS_HELP_STRING([--with-protoc-bindir=BIN_DIR],[specify protoc bin path])], [protoc_bin_path=$withval], [])

# Enable debug
# Enable debug
AC_ARG_ENABLE([debug],
[AS_HELP_STRING([--enable-debug],
[use debug compiler flags and macros (default is no)])],
Expand All @@ -163,11 +163,11 @@ if test "x$enable_debug" = xyes; then
if test "x$GCC" = xyes; then
CFLAGS="-g3 -O0 -DDEBUG"
fi

if test "x$GXX" = xyes; then
CXXFLAGS="-g3 -O0 -DDEBUG"
fi
fi
fi

## TODO: Remove these hard-coded paths and flags. They are here for the sake of
## compatibility with the legacy buildsystem.
Expand Down Expand Up @@ -731,6 +731,7 @@ AC_CHECK_HEADER([libsnark/gadgetlib1/gadget.hpp],,AC_MSG_ERROR(libsnark headers
AC_CHECK_LIB([snark],[main],LIBSNARK_LIBS=-lsnark, [AC_MSG_ERROR(libsnark missing)], [-lgmpxx])

LIBZCASH_LIBS="-lsnark -lgmp -lgmpxx -lboost_system-mt -lcrypto -lsodium -fopenmp"
LIBGPUSOLVER_LIBS="-lOpenCL"

CXXFLAGS_TEMP="$CXXFLAGS"
LIBS_TEMP="$LIBS"
Expand Down Expand Up @@ -917,6 +918,8 @@ AC_SUBST(GMP_LIBS)
AC_SUBST(GMPXX_LIBS)
AC_SUBST(LIBSNARK_LIBS)
AC_SUBST(LIBZCASH_LIBS)
AC_SUBST(LIBGPUSOLVER_LIBS)

AC_CONFIG_FILES([Makefile src/Makefile share/setup.nsi share/qt/Info.plist src/test/buildenv.py])
AC_CONFIG_FILES([qa/pull-tester/run-bitcoind-for-test.sh],[chmod +x qa/pull-tester/run-bitcoind-for-test.sh])
AC_CONFIG_FILES([qa/pull-tester/tests-config.sh],[chmod +x qa/pull-tester/tests-config.sh])
Expand Down
38 changes: 34 additions & 4 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ LIBBITCOIN_UNIVALUE=univalue/libbitcoin_univalue.a
LIBBITCOINQT=qt/libbitcoinqt.a
LIBSECP256K1=secp256k1/libsecp256k1.la
LIBZCASH=libzcash.a
LIBGPUSOLVER=libgpusolver.a

$(LIBSECP256K1): $(wildcard secp256k1/src/*) $(wildcard secp256k1/include/*)
$(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C $(@D) $(@F)
Expand All @@ -45,7 +46,9 @@ EXTRA_LIBRARIES = \
univalue/libbitcoin_univalue.a \
libbitcoin_server.a \
libbitcoin_cli.a \
libzcash.a
libzcash.a \
libgpusolver.a

if ENABLE_WALLET
BITCOIN_INCLUDES += $(BDB_CPPFLAGS)
EXTRA_LIBRARIES += libbitcoin_wallet.a
Expand Down Expand Up @@ -80,6 +83,15 @@ LIBZCASH_H = \
zcash/util.h \
zcash/Zcash.h

LIBGPUSOLVER_H = \
libgpusolver/libgpusolver.h \
libgpusolver/gpuconfig.h \
libgpusolver/kernels/silentarmy.h \
libgpusolver/libclwrapper.h \
libgpusolver/cl.hpp \
libgpusolver/blake.h \
libgpusolver/param.h

.PHONY: FORCE check-symbols check-security
# bitcoin core #
BITCOIN_CORE_H = \
Expand Down Expand Up @@ -226,7 +238,8 @@ libbitcoin_server_a_SOURCES = \
validationinterface.cpp \
$(JSON_H) \
$(BITCOIN_CORE_H) \
$(LIBZCASH_H)
$(LIBZCASH_H) \
$(LIBGPUSOLVER_H)

# wallet: shared between bitcoind and bitcoin-qt, but only linked
# when wallet enabled
Expand Down Expand Up @@ -364,7 +377,8 @@ zcashd_LDADD = \
$(LIBZCASH) \
$(LIBLEVELDB) \
$(LIBMEMENV) \
$(LIBSECP256K1)
$(LIBSECP256K1) \
$(LIBGPUSOLVER)

if ENABLE_WALLET
zcashd_LDADD += libbitcoin_wallet.a
Expand All @@ -378,7 +392,9 @@ zcashd_LDADD += \
$(MINIUPNPC_LIBS) \
$(LIBZCASH) \
$(LIBBITCOIN_CRYPTO) \
$(LIBZCASH_LIBS)
$(LIBZCASH_LIBS) \
$(LIBGPUSOLVER) \
$(LIBGPUSOLVER_LIBS)
#

# bitcoin-cli binary #
Expand Down Expand Up @@ -448,6 +464,20 @@ libzcash_a_LDFLAGS = $(HARDENED_LDFLAGS)

libzcash_a_CPPFLAGS += -DMONTGOMERY_OUTPUT

libgpusolver_a_SOURCES = \
libgpusolver/libgpusolver.cpp \
libgpusolver/libclwrapper.cpp \
libgpusolver/blake.cpp

libgpusolver_a_CPPFLAGS = -DMULTICORE -fopenmp -fPIC -DBINARY_OUTPUT -DCURVE_ALT_BN128 -DBOOST_SPIRIT_THREADSAFE -DHAVE_BUILD_INFO -D__STDC_FORMAT_MACROS $(HARDENED_CPPFLAGS) -pipe -O1 -g -Wstack-protector -fstack-protector-all -fPIE -fvisibility=hidden

libgpusolver_a_CXXFLAGS = $(HARDENED_CXXFLAGS) -fwrapv -fno-strict-aliasing

libgpusolver_a_LDFLAGS = $(HARDENED_LDFLAGS) -lOpenCL

libgpusolver_a_CPPFLAGS += -DMONTGOMERY_OUTPUT


# zcashconsensus library #
if BUILD_BITCOIN_LIBS
include_HEADERS = script/zcashconsensus.h
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile.gtest.include
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ if ENABLE_WALLET
zcash_gtest_LDADD += $(LIBBITCOIN_WALLET)
endif

zcash_gtest_LDADD += $(LIBZCASH_CONSENSUS) $(BDB_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(MINIUPNPC_LIBS) $(LIBZCASH) $(LIBZCASH_LIBS)
zcash_gtest_LDADD += $(LIBZCASH_CONSENSUS) $(BDB_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(MINIUPNPC_LIBS) $(LIBZCASH) $(LIBZCASH_LIBS) $(LIBGPUSOLVER) $(LIBGPUSOLVER_LIBS)

zcash_gtest_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) -static

Expand Down
2 changes: 1 addition & 1 deletion src/Makefile.test.include
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ if ENABLE_WALLET
test_test_bitcoin_LDADD += $(LIBBITCOIN_WALLET)
endif

test_test_bitcoin_LDADD += $(LIBZCASH_CONSENSUS) $(BDB_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(MINIUPNPC_LIBS) $(LIBZCASH) $(LIBZCASH_LIBS)
test_test_bitcoin_LDADD += $(LIBZCASH_CONSENSUS) $(BDB_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(MINIUPNPC_LIBS) $(LIBZCASH) $(LIBZCASH_LIBS) $(LIBGPUSOLVER) $(LIBGPUSOLVER_LIBS) $(LIBGPUSOLVER) $(LIBGPUSOLVER_LIBS)
test_test_bitcoin_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) -static

nodist_test_test_bitcoin_SOURCES = $(GENERATED_TEST_FILES)
Expand Down
22 changes: 21 additions & 1 deletion src/Makefile.zcash.include
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
bin_PROGRAMS += \
zcash/GenerateParams
zcash/GenerateParams

# tool for generating our public parameters
zcash_GenerateParams_SOURCES = zcash/GenerateParams.cpp
Expand All @@ -9,3 +9,23 @@ zcash_GenerateParams_LDADD = \
$(LIBBITCOIN_UTIL) \
$(LIBBITCOIN_CRYPTO) \
$(LIBZCASH_LIBS)

zcash_miner_SOURCES = \
libstratum/StratumClient.cpp \
libstratum/StratumClient.h \
libstratum/ZcashStratum.cpp \
libstratum/ZcashStratum.h \
standaloneminer.cpp
zcash_miner_CPPFLAGS = $(BITCOIN_INCLUDES)
zcash_miner_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
zcash_miner_LDADD = \
$(LIBBITCOIN_COMMON) \
$(LIBBITCOIN_CRYPTO) \
$(LIBBITCOIN_UTIL) \
$(LIBSECP256K1) \
$(BOOST_LIBS) \
$(CRYPTO_LIBS) \
$(LIBZCASH) \
$(LIBZCASH_LIBS) \
$(LIBGPUSOLVER) \
$(LIBGPUSOLVER_LIBS)
23 changes: 17 additions & 6 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include <openssl/crypto.h>

#include "libsnark/common/profiling.hpp"
#include "libgpusolver/gpuconfig.h"

using namespace std;

Expand Down Expand Up @@ -361,7 +362,7 @@ std::string HelpMessage(HelpMessageMode mode)
strUsage += HelpMessageOpt("-walletnotify=<cmd>", _("Execute command when a wallet transaction changes (%s in cmd is replaced by TxID)"));
strUsage += HelpMessageOpt("-zapwallettxes=<mode>", _("Delete all wallet transactions and only recover those parts of the blockchain through -rescan on startup") +
" " + _("(1 = keep tx meta data e.g. account owner and payment request information, 2 = drop tx meta data)"));

#endif

strUsage += HelpMessageGroup(_("Debugging/Testing options:"));
Expand All @@ -385,6 +386,10 @@ std::string HelpMessage(HelpMessageMode mode)
strUsage += HelpMessageOpt("-gen", strprintf(_("Generate coins (default: %u)"), 0));
strUsage += HelpMessageOpt("-genproclimit=<n>", strprintf(_("Set the number of threads for coin generation if enabled (-1 = all cores, default: %d)"), 1));
strUsage += HelpMessageOpt("-equihashsolver=<name>", _("Specify the Equihash solver to be used if enabled (default: \"default\")"));
strUsage += HelpMessageOpt("-G", _("Enable GPU mining (default: false)"));
strUsage += HelpMessageOpt("-device=<id>", _("If -G is enabled this specifies the GPU device number to use (default: 0)"));
strUsage += HelpMessageOpt("-allgpu", _("If -G is enabled this will mine on all available GPU devices (default: false)"));
strUsage += HelpMessageOpt("-forcenolimit", _("Do not limit thread count per GPU by memory limits. (default: false)"));
#endif
strUsage += HelpMessageOpt("-help-debug", _("Show all debugging options (usage: --help -help-debug)"));
strUsage += HelpMessageOpt("-logips", strprintf(_("Include IP addresses in debug output (default: %u)"), 0));
Expand Down Expand Up @@ -1014,15 +1019,15 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)

std::string warningString;
std::string errorString;

if (!CWallet::Verify(strWalletFile, warningString, errorString))
return false;

if (!warningString.empty())
InitWarning(warningString);
if (!errorString.empty())
return InitError(warningString);

} // (!fDisableWallet)
#endif // ENABLE_WALLET
// ********************************************************* Step 6: network initialization
Expand Down Expand Up @@ -1492,8 +1497,14 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)

#ifdef ENABLE_WALLET
// Generate coins in the background
if (pwalletMain)
GenerateBitcoins(GetBoolArg("-gen", false), pwalletMain, GetArg("-genproclimit", 1));
if (pwalletMain){
GPUConfig conf;
conf.useGPU = GetBoolArg("-G", false) || GetBoolArg("-GPU", false);
conf.selGPU = GetArg("-deviceid", 0);
conf.allGPU = GetBoolArg("-allgpu", 0);
conf.forceGenProcLimit = GetBoolArg("-forcenolimit", false);
GenerateBitcoins(GetBoolArg("-gen", false), pwalletMain, GetArg("-genproclimit", 1),conf);
}
#endif

// ********************************************************* Step 11: finished
Expand Down
104 changes: 104 additions & 0 deletions src/libgpusolver/blake.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#include <stdint.h>
#include <string.h>
#include <assert.h>
#include "blake.h"

static const uint32_t blake2b_block_len = 128;
static const uint32_t blake2b_rounds = 12;
static const uint64_t blake2b_iv[8] =
{
0x6a09e667f3bcc908ULL, 0xbb67ae8584caa73bULL,
0x3c6ef372fe94f82bULL, 0xa54ff53a5f1d36f1ULL,
0x510e527fade682d1ULL, 0x9b05688c2b3e6c1fULL,
0x1f83d9abfb41bd6bULL, 0x5be0cd19137e2179ULL,
};
static const uint8_t blake2b_sigma[12][16] =
{
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
{ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
{ 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 },
{ 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 },
{ 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 },
{ 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 },
{ 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 },
{ 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 },
{ 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 },
{ 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0 },
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
{ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
};

/*
** Init the state according to Zcash parameters.
*/
void zcash_blake2b_init(blake2b_state_t *st, uint8_t hash_len,
uint32_t n, uint32_t k)
{
assert(n > k);
assert(hash_len <= 64);
st->h[0] = blake2b_iv[0] ^ (0x01010000 | hash_len);
for (uint32_t i = 1; i <= 5; i++)
st->h[i] = blake2b_iv[i];
st->h[6] = blake2b_iv[6] ^ *(uint64_t *)"ZcashPoW";
st->h[7] = blake2b_iv[7] ^ (((uint64_t)k << 32) | n);
st->bytes = 0;
}

static uint64_t rotr64(uint64_t a, uint8_t bits)
{
return (a >> bits) | (a << (64 - bits));
}

static void mix(uint64_t *va, uint64_t *vb, uint64_t *vc, uint64_t *vd,
uint64_t x, uint64_t y)
{
*va = (*va + *vb + x);
*vd = rotr64(*vd ^ *va, 32);
*vc = (*vc + *vd);
*vb = rotr64(*vb ^ *vc, 24);
*va = (*va + *vb + y);
*vd = rotr64(*vd ^ *va, 16);
*vc = (*vc + *vd);
*vb = rotr64(*vb ^ *vc, 63);
}

/*
** Process either a full message block or the final partial block.
** Note that v[13] is not XOR'd because st->bytes is assumed to never overflow.
**
** _msg pointer to message (must be zero-padded to 128 bytes if final block)
** msg_len must be 128 (<= 128 allowed only for final partial block)
** is_final indicate if this is the final block
*/
void zcash_blake2b_update(blake2b_state_t *st, const uint8_t *_msg,
uint32_t msg_len, uint32_t is_final)
{
const uint64_t *m = (const uint64_t *)_msg;
uint64_t v[16];
assert(msg_len <= 128);
assert(st->bytes <= UINT64_MAX - msg_len);
memcpy(v + 0, st->h, 8 * sizeof (*v));
memcpy(v + 8, blake2b_iv, 8 * sizeof (*v));
v[12] ^= (st->bytes += msg_len);
v[14] ^= is_final ? -1 : 0;
for (uint32_t round = 0; round < blake2b_rounds; round++)
{
const uint8_t *s = blake2b_sigma[round];
mix(v + 0, v + 4, v + 8, v + 12, m[s[0]], m[s[1]]);
mix(v + 1, v + 5, v + 9, v + 13, m[s[2]], m[s[3]]);
mix(v + 2, v + 6, v + 10, v + 14, m[s[4]], m[s[5]]);
mix(v + 3, v + 7, v + 11, v + 15, m[s[6]], m[s[7]]);
mix(v + 0, v + 5, v + 10, v + 15, m[s[8]], m[s[9]]);
mix(v + 1, v + 6, v + 11, v + 12, m[s[10]], m[s[11]]);
mix(v + 2, v + 7, v + 8, v + 13, m[s[12]], m[s[13]]);
mix(v + 3, v + 4, v + 9, v + 14, m[s[14]], m[s[15]]);
}
for (uint32_t i = 0; i < 8; i++)
st->h[i] ^= v[i] ^ v[i + 8];
}

void zcash_blake2b_final(blake2b_state_t *st, uint8_t *out, uint8_t outlen)
{
assert(outlen <= 64);
memcpy(out, st->h, outlen);
}
10 changes: 10 additions & 0 deletions src/libgpusolver/blake.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
typedef struct blake2b_state_s
{
uint64_t h[8];
uint64_t bytes;
} blake2b_state_t;
void zcash_blake2b_init(blake2b_state_t *st, uint8_t hash_len,
uint32_t n, uint32_t k);
void zcash_blake2b_update(blake2b_state_t *st, const uint8_t *_msg,
uint32_t msg_len, uint32_t is_final);
void zcash_blake2b_final(blake2b_state_t *st, uint8_t *out, uint8_t outlen);
Loading