public bool VerifyShare(LbryStratum.Work work, UInt32 aNonce, string result) { var hashSHA256 = HashLib.HashFactory.Crypto.CreateSHA256(); var hashSHA512 = HashLib.HashFactory.Crypto.CreateSHA512(); var hashRIPEMD160 = HashLib.HashFactory.Crypto.CreateRIPEMD160(); byte[] input = work.Blob; input[108] = (byte)((aNonce >> 24) & 0xff); input[109] = (byte)((aNonce >> 16) & 0xff); input[110] = (byte)((aNonce >> 8) & 0xff); input[111] = (byte)((aNonce >> 0) & 0xff); byte[] inputSwapped = new byte[112]; for (int i = 0; i < 28; i++) { inputSwapped[4 * i + 0] = input[4 * i + 3]; inputSwapped[4 * i + 1] = input[4 * i + 2]; inputSwapped[4 * i + 2] = input[4 * i + 1]; inputSwapped[4 * i + 3] = input[4 * i + 0]; } byte[] hash0 = hashSHA256.ComputeBytes(inputSwapped).GetBytes(); hash0 = hashSHA256.ComputeBytes(hash0).GetBytes(); hash0 = hashSHA512.ComputeBytes(hash0).GetBytes(); byte[] hash1 = new byte[32]; byte[] hash2 = new byte[32]; Buffer.BlockCopy(hash0, 0, hash1, 0, 32); Buffer.BlockCopy(hash0, 32, hash2, 0, 32); hash1 = hashRIPEMD160.ComputeBytes(hash1).GetBytes(); hash2 = hashRIPEMD160.ComputeBytes(hash2).GetBytes(); hash0 = new byte[40]; Buffer.BlockCopy(hash1, 0, hash0, 0, 20); Buffer.BlockCopy(hash2, 0, hash0, 20, 20); hash0 = hashSHA256.ComputeBytes(hash0).GetBytes(); hash0 = hashSHA256.ComputeBytes(hash0).GetBytes(); string hash0String = Utilities.ByteArrayToString(hash0); //MainForm.Logger("result: " + result); //MainForm.Logger("hash0: " + hash0String); return(result == hash0String); }
public void Submit(OpenCLDevice aDevice, LbryStratum.Work work, UInt32 aNonce, string result) { if (Stopped) { return; } if (!VerifyShare(work, aNonce, result)) { MainForm.Logger("Error in computation has been detected (Lbry)."); return; // TODO } try { mMutex.WaitOne(5000); } catch (Exception) { } RegisterDeviceWithShare(aDevice); try { String stringNonce = (String.Format("{3:x2}{2:x2}{1:x2}{0:x2}", ((aNonce >> 0) & 0xff), ((aNonce >> 8) & 0xff), ((aNonce >> 16) & 0xff), ((aNonce >> 24) & 0xff))); String message = JsonConvert.SerializeObject(new Dictionary <string, Object> { { "id", mJsonRPCMessageID++ }, { "method", "mining.submit" }, { "params", new List <string> { Username, work.Job.ID, work.LocalExtranonceString, work.Job.NTime, stringNonce } } }); WriteLine(message); MainForm.Logger("Device #" + aDevice.DeviceIndex + " submitted a share."); //MainForm.Logger("message: " + message); } catch (Exception ex) { MainForm.Logger("Failed to submit share: " + ex.Message); try { mMutex.ReleaseMutex(); } catch (Exception) { } Reconnect(); } try { mMutex.ReleaseMutex(); } catch (Exception) { } }