starchyfort

Untitled

Jul 13th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.72 KB | None | 0 0
  1.  
  2. ... init precedes this ..
  3.  
  4.     cudaMemcpy(d_solution[theDevice], h_message[theDevice], 8, cudaMemcpyHostToDevice);   // sizeof(uint64_t), 8 bytes
  5.  
  6.     anyError = cudaDeviceSynchronize();
  7.     if (anyError != cudaSuccess)
  8.         printf("Kernel launch error (device %d): %s \n\n", theDevice, cudaGetErrorString(anyError));
  9.     //Sleep(0.35);
  10.  
  11.     cnt[theDevice] += numThreads;               // stride via theCounter a.k.a. `cnt`
  12.     printable_hashrate_cnt[theDevice] += numThreads;
  13.  
  14.     // consider moving this inside the if() statement below (FIXME/TODO)
  15.     cudaMemcpy(h_message[theDevice], d_solution[theDevice], 8, cudaMemcpyDeviceToHost);       // 8 bytes, was sizeof(uint64_t)
  16.     if (*h_message[theDevice] != UINT64_MAX)
  17.     {
  18.        
  19.         ...
  20.  
  21.         memcpy(&solution[theDevice][12], h_message[theDevice], 8);                              // 8 bytes, was sizeof(
  22.  
  23.     }
  24.  
  25. string Comm_VerifySolutionOnCPU()
  26. {
  27.  
  28.  
  29. #define SPH_KECCAK_64 1
  30. #include "sph_keccak.h"
  31. typedef std::array<uint8_t, 32u> hash_t;
  32. typedef std::array<uint8_t, 84u> message_t;
  33.  
  34. auto keccak256test(std::string const mesgParam) -> std::string const
  35. {
  36.     message_t               theMesg;
  37.     preHexToBytes(mesgParam, theMesg);  // checks for 0x, unneeded really, testing only
  38.  
  39.     sph_keccak256_context   ctx;
  40.     sph_keccak256_init(&ctx);
  41.     sph_keccak256(&ctx, theMesg.data(), theMesg.size());
  42.     hash_t out;
  43.     sph_keccak256_close(&ctx, out.data());
  44.  
  45.     return Different_BytesToString(out);
  46. }
  47.  
  48. void
  49.     string const            str_solution = uint8t_array_toHexString (solution[solutionFoundOnDevice], 32); // was &solution[0]
  50.     string const            str_hash_prefix = uint8t_array_toHexString (hash_prefix, 52); // 52 bytes
  51.  
  52.     printf("Comm_VerifySolutionOnCPU():\n");
  53.     printf("-str_solution = %s \n", str_solution.c_str());
  54.     printf("-str_hash_prefix = %s \n\n", str_hash_prefix.c_str());
  55.  
  56.     // more declarations
  57.     BigUnsigned             digest_bignum = 0;                              // bignum for the digest we're about to compute
  58.     hash_t                  digest_hash = { 0 };                            // hash_t is an array of uint8_t 32 long
  59.     string                  digest_string = "";
  60.  
  61.     printf("performing keccak256 on hashprefix+solution ...\n");
  62.     cout << "message to keccak256() is " << str_hash_prefix + str_solution << endl;
  63.  
  64.     string scratchString_Digest = keccak256test(str_hash_prefix + str_solution);
  65.     cout << "sph-keccak result is  " << scratchString_Digest << endl << endl;
  66.  
  67.     cout << "mining target is " << gBig_MiningTarget << endl;
  68.  
  69.     digest_bignum = BigUnsignedInABase(scratchString_Digest, 16);       // convert string to base-16 bignum (since it's a hex string)
  70.     if (digest_bignum <= gBig_MiningTarget)
  71.     {
  72.         printf("comms_pool.cpp: digest -passed- CPU verification!\n");
  73.         return scratchString_Digest;
  74.     }
  75.     else
  76.     {
  77.         printf("comms_pool.cpp: solution failed CPU verification. d'oh!\n\n");
  78.         return "veriferror";
  79.     }
Advertisement
Add Comment
Please, Sign In to add comment