Skip to content

Commit

Permalink
Merge pull request #10 from amin63moradi/main
Browse files Browse the repository at this point in the history
fix low difficulty bug
  • Loading branch information
mhssamadani committed Feb 1, 2021
2 parents 0982cdc + d09ec67 commit f1608b9
Show file tree
Hide file tree
Showing 5 changed files with 421 additions and 29 deletions.
69 changes: 69 additions & 0 deletions secp256k1/include/cpuAutolykos.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#pragma once

#include "definitions.h"
#include "easylogging++.h"



#include <curl/curl.h>
#include <inttypes.h>
#include <iostream>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <atomic>
#include <chrono>
#include <mutex>
#include <thread>
#include <vector>
#include <random>


#include "cryptography.h"
#include "conversion.h"
#include "definitions.h"
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/bn.h>
#include <openssl/ec.h>
#include <openssl/pem.h>
#include <openssl/evp.h>
#include <openssl/sha.h>
#include <openssl/hmac.h>
#include <openssl/opensslv.h>
#include <random>


class AutolykosAlg
{
public:
unsigned long long CONST_MESS[CONST_MES_SIZE_8 / 8];

AutolykosAlg();
~AutolykosAlg();
int m_iAlgVer;
void Blake2b256(const char * in, const int len, uint8_t * output, char * outstr);
void GenIdex(const char * in, const int len, uint32_t* index);
void hashFn(const char * in, const int len, uint8_t * output);
bool RunAlg(
uint8_t *B_mes,
uint8_t *nonce,
uint8_t *bPool,
uint8_t *height
);

private:
char *m_str = NULL;
char *bound_str = NULL;
uint8_t *m_n;
uint8_t *p_w_m_n;
uint8_t *Hinput;
char *n_str;
char *h_str;
};

Binary file added secp256k1/miner.exe
Binary file not shown.
61 changes: 34 additions & 27 deletions secp256k1/src/autolykos.cu
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "../include/request.h"
#include "../include/httpapi.h"
#include "../include/queue.h"
#include "../include/cpuAutolykos.h"
#include <ctype.h>
#include <cuda.h>
#include <curl/curl.h>
Expand Down Expand Up @@ -63,11 +64,9 @@ void SenderThread(info_t * info, BlockQueue<MinerShare>* shQueue)
while(true)
{
MinerShare share = shQueue->get();
char logstr[2048];

LOG(INFO) << "Some GPU found and trying to POST a share: " ;
PostPuzzleSolution(info->to, (uint8_t*)&share.nonce);

LOG(INFO) << "Some GPU found and trying to POST a share: " ;
PostPuzzleSolution(info->to, (uint8_t*)&share.nonce);


}

Expand All @@ -79,14 +78,15 @@ void SenderThread(info_t * info, BlockQueue<MinerShare>* shQueue)
////////////////////////////////////////////////////////////////////////////////
void MinerThread(const int totalGPUCards, int deviceId, info_t * info, std::vector<double>* hashrates, std::vector<int>* tstamps, BlockQueue<MinerShare>* shQueue)
{
AutolykosAlg solVerifier;

CUDA_CALL(cudaSetDevice(deviceId));
cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync);
char threadName[20];
sprintf(threadName, "GPU %i miner", deviceId);
el::Helpers::setThreadName(threadName);

state_t state = STATE_KEYGEN;
char logstr[1000];

//========================================================================//
// Host memory allocation
Expand Down Expand Up @@ -194,10 +194,8 @@ void MinerThread(const int totalGPUCards, int deviceId, info_t * info, std::vect
//========================================================================//
// Autolykos puzzle cycle
//========================================================================//
uint32_t ind = 0;
uint64_t base = 0;
uint64_t EndNonce = 0;

uint64_t EndNonce = 0;
uint32_t height = 0;


Expand Down Expand Up @@ -357,38 +355,49 @@ void MinerThread(const int totalGPUCards, int deviceId, info_t * info, std::vect


int i = 0;
while (indices_h[i] && (i < 16/*MAX_SOLS*/))
while (indices_h[i] && (i < 16/*MAX_SOLS*/) && (blockId == info->blockId.load()) )
{
if(!info->stratumMode && i != 0)
{
break ;
}

*((uint64_t *)nonce) = base + indices_h[i] - 1;
uint64_t endNonceT;
memcpy(&endNonceT , info->extraNonceEnd , sizeof(uint64_t));
if ( (*((uint64_t *)nonce)) <= endNonceT )
{

MinerShare share(*((uint64_t *)nonce));
shQueue->put(share);


if (!info->stratumMode)
{
state = STATE_KEYGEN;
//end_jobs.fetch_add(1, std::memory_order_relaxed);
break;

}
//LOG(INFO) << "sol check i: " << i << " sol index: "<< indices_h[i];
bool checksol = solVerifier.RunAlg(info->mes,nonce,info->bound,info->Hblock);
if (checksol)
{
MinerShare share(*((uint64_t *)nonce));
shQueue->put(share);


if (!info->stratumMode)
{
state = STATE_KEYGEN;
//end_jobs.fetch_add(1, std::memory_order_relaxed);
break;
}
}
else
{
LOG(INFO) << " problem in verify solution, nonce: " << *((uint64_t *)nonce);
}

}
else
{
//LOG(INFO) << "nonce greater than end nonce, nonce: " << *((uint64_t *)nonce) << " endNonce: " << endNonceT;
LOG(INFO) << "nonce greater than end nonce, nonce: " << *((uint64_t *)nonce) << " endNonce: " << endNonceT;
}
i++;
}

memset(indices_h,0,MAX_SOLS*sizeof(uint32_t));
CUDA_CALL(cudaMemset(
indices_d, 0, sizeof(uint32_t)
indices_d, 0, MAX_SOLS*sizeof(uint32_t)
));
CUDA_CALL(cudaMemset(count_d,0,sizeof(uint32_t)));

Expand Down Expand Up @@ -420,9 +429,7 @@ int main(int argc, char ** argv)

el::Helpers::setThreadName("main thread");

char logstr[1000];



//========================================================================//
// Check GPU availability
//========================================================================//
Expand Down

0 comments on commit f1608b9

Please sign in to comment.