Skip to content

Commit

Permalink
Almost there
Browse files Browse the repository at this point in the history
  • Loading branch information
omaralvarez committed Oct 28, 2016
1 parent 94b0603 commit 141468c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 64 deletions.
4 changes: 2 additions & 2 deletions src/libstratum/ZcashStratum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ void static ZcashMinerThread(ZcashMiner* miner, int size, int pos, GPUConfig con
crypto_generichash_blake2b_state curr_state;
curr_state = state;
auto bNonce = ArithToUint256(nonce);
crypto_generichash_blake2b_update(&curr_state,
/*crypto_generichash_blake2b_update(&curr_state,
bNonce.begin(),
bNonce.size());
bNonce.size());*/

// (x_1, x_2, ...) = A(I, V, n, k)
LogPrint("pow", "Running Equihash solver with nNonce = %s\n",
Expand Down
2 changes: 1 addition & 1 deletion src/libzogminer/cl_zogminer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#undef min
#undef max

#define DEBUG
//#define DEBUG

using namespace std;

Expand Down
71 changes: 14 additions & 57 deletions src/libzogminer/gpusolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "gpusolver.h"
#include "util.h"
#include "primitives/block.h"
#include "arith_uint256.h"

#define DEBUG

Expand Down Expand Up @@ -208,63 +209,19 @@ bool GPUSolver::GPUSolve200_9(uint8_t *header, size_t header_len, uint64_t nonce
std::vector<unsigned char> sol_char = GetMinimalFromIndices(index_vector, DIGITBITS);
#ifdef DEBUG
bool isValid;
CBlock pblock;
/* uint64_t *nonce_ptr;
assert(header_len == ZCASH_BLOCK_HEADER_LEN ||
header_len == ZCASH_BLOCK_HEADER_LEN - ZCASH_NONCE_LEN);
nonce_ptr = (uint64_t *)(header + ZCASH_BLOCK_HEADER_LEN - ZCASH_NONCE_LEN);
if (header_len == ZCASH_BLOCK_HEADER_LEN - ZCASH_NONCE_LEN)
memset(nonce_ptr, 0, ZCASH_NONCE_LEN);
// add the nonce
*nonce_ptr += nonce;
//printf("\nSolving nonce %s\n", s_hexdump(nonce_ptr, ZCASH_NONCE_LEN));
crypto_generichash_blake2b_update(&base_state,
pblock.nNonce.begin(),
ZCASH_NONCE_LEN);
*/


blake2b_state_t blake;
cl::Buffer buf_blake_st;
uint32_t sol_found = 0;
size_t local_ws = 64;
size_t global_ws;
uint64_t *nonce_ptr;
assert(header_len == ZCASH_BLOCK_HEADER_LEN ||
header_len == ZCASH_BLOCK_HEADER_LEN - ZCASH_NONCE_LEN);
nonce_ptr = (uint64_t *)(header + ZCASH_BLOCK_HEADER_LEN - ZCASH_NONCE_LEN);
if (header_len == ZCASH_BLOCK_HEADER_LEN - ZCASH_NONCE_LEN)
memset(nonce_ptr, 0, ZCASH_NONCE_LEN);
//add the nonce
*nonce_ptr += nonce;

crypto_generichash_blake2b_update(&base_state,
(unsigned char*)s_hexdump(nonce_ptr, ZCASH_NONCE_LEN),
pblock.nNonce.size());

//printf("\nSolving nonce %s\n", s_hexdump(nonce_ptr, ZCASH_NONCE_LEN));

zcash_blake2b_init(&blake, ZCASH_HASH_LEN, PARAM_N, PARAM_K);
zcash_blake2b_update(&blake, header, 128, 0);



EhIsValidSolution(200, 9, base_state, sol_char, isValid);
std::cout << "is valid: " << isValid << '\n';
if (!isValid) {
//If we find invalid solution bail, it cannot be a valid POW
std::cout << "Invalid solution found!" << std::endl;
return false;
} else {
std::cout << "Valid solution found!" << std::endl;
}
uint256 nNonce = ArithToUint256(nonce);
crypto_generichash_blake2b_update(&base_state,
nNonce.begin(),
nNonce.size());
EhIsValidSolution(200, 9, base_state, sol_char, isValid);
std::cout << "is valid: " << isValid << '\n';
if (!isValid) {
//If we find invalid solution bail, it cannot be a valid POW
std::cout << "Invalid solution found!" << std::endl;
//return false;
} else {
std::cout << "Valid solution found!" << std::endl;
}
#endif
if (validBlock(sol_char)) {
// If we find a POW solution, do not try other solutions
Expand Down
4 changes: 2 additions & 2 deletions src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,9 +525,9 @@ void static BitcoinMiner(CWallet *pwallet, GPUConfig conf)
// H(I||V||...
crypto_generichash_blake2b_state curr_state;
curr_state = state;
crypto_generichash_blake2b_update(&curr_state,
/*crypto_generichash_blake2b_update(&curr_state,
pblock->nNonce.begin(),
pblock->nNonce.size());
pblock->nNonce.size());*/

// (x_1, x_2, ...) = A(I, V, n, k)
LogPrint("pow", "Running Equihash solver with nNonce = %s\n",
Expand Down
4 changes: 2 additions & 2 deletions src/standaloneminer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void test_mine(int n, int k, uint32_t d, GPUConfig conf)

uint64_t nn= 0;
//TODO Free
uint8_t * header = (uint8_t *) calloc(128, sizeof(uint8_t));
uint8_t * header = (uint8_t *) calloc(ZCASH_BLOCK_HEADER_LEN, sizeof(uint8_t));


while (true) {
Expand Down Expand Up @@ -183,7 +183,7 @@ void test_mine(int n, int k, uint32_t d, GPUConfig conf)
if(!conf.useGPU)
foundBlock = EhOptimisedSolve(n, k, curr_state, validBlock, cancelled);
else
foundBlock = solver->run(n, k, header, ZCASH_BLOCK_HEADER_LEN, nn++, validBlock, cancelledGPU, curr_state);
foundBlock = solver->run(n, k, header, ZCASH_BLOCK_HEADER_LEN - ZCASH_NONCE_LEN, nn++, validBlock, cancelledGPU, curr_state);
uint64_t solve_end = rdtsc();
LogPrint("cycles", "Solver took %2.2f Mcycles\n\n",
(double)(solve_end - solve_start) / (1UL << 20));
Expand Down

0 comments on commit 141468c

Please sign in to comment.