#include "miner.h" #include "hodl-gate.h" #include "hodl_uint256.h" #include "hodl_arith_uint256.h" #include "block.h" #include #include "tinyformat.h" #include #include "hash.h" #include #include #include #define BEGIN(a) ((char*)&(a)) #define END(a) ((char*)&((&(a))[1])) #define PSUEDORANDOM_DATA_SIZE 30 //2^30 = 1GB #define PSUEDORANDOM_DATA_CHUNK_SIZE 6 //2^6 = 64 bytes //must be same as SHA512_DIGEST_LENGTH 64 #define L2CACHE_TARGET 12 // 2^12 = 4096 bytes #define AES_ITERATIONS 15 void SHA512Filler(char *mainMemoryPsuedoRandomData, int threadNumber, uint256 midHash){ //Generate psuedo random data to store in main memory uint32_t chunks=(1<<(PSUEDORANDOM_DATA_SIZE-PSUEDORANDOM_DATA_CHUNK_SIZE)); //2^(30-6) = 16 mil uint32_t chunkSize=(1<<(PSUEDORANDOM_DATA_CHUNK_SIZE)); //2^6 = 64 bytes unsigned char hash_tmp[sizeof(midHash)]; memcpy((char*)&hash_tmp[0], (char*)&midHash, sizeof(midHash) ); uint32_t* index = (uint32_t*)hash_tmp; // uint32_t chunksToProcess=chunks/totalThreads; uint32_t chunksToProcess = chunks / opt_n_threads; uint32_t startChunk=threadNumber*chunksToProcess; for( uint32_t i = startChunk; i < startChunk+chunksToProcess; i++){ //This changes the first character of hash_tmp *index = i; SHA512((unsigned char*)hash_tmp, sizeof(hash_tmp), (unsigned char*)&(mainMemoryPsuedoRandomData[i*chunkSize])); } } extern "C" // max_nonce is not used by this function int scanhash_hodl( int threadNumber, struct work* work, uint32_t max_nonce, uint64_t *hashes_done ) { unsigned char *mainMemoryPsuedoRandomData = hodl_scratchbuf; uint32_t *pdata = work->data; uint32_t *ptarget = work->target; //retreive target std::stringstream s; for (int i = 7; i>=0; i--) s << strprintf("%08x", ptarget[i]); //retreive preveios hash std::stringstream p; for (int i = 0; i < 8; i++) p << strprintf("%08x", swab32(pdata[8 - i])); //retreive merkleroot std::stringstream m; for (int i = 0; i < 8; i++) m << strprintf("%08x", swab32(pdata[16 - i])); CBlock pblock; pblock.SetNull(); pblock.nVersion=swab32(pdata[0]); pblock.nNonce=swab32(pdata[19]); pblock.nTime=swab32(pdata[17]); pblock.nBits=swab32(pdata[18]); pblock.hashPrevBlock=uint256S(p.str()); pblock.hashMerkleRoot=uint256S(m.str()); uint256 hashTarget=uint256S(s.str()); int collisions=0; uint256 hash; //Begin AES Search //Allocate temporary memory uint32_t cacheMemorySize = (1<