From 499981ed5227d0e66a27cf288ac7376bdadb40d3 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Sun, 20 Sep 2020 21:13:46 +0000 Subject: [PATCH] c# pow implementation work --- pow-csharp/onionrpow-cli/Program.cs | 16 ++++++++++++++-- pow-csharp/onionrpow/OnionrPow.cs | 8 +++++--- scripts/testblock.py | 12 ++++++++++++ src/onionrproofs/subprocesspow.py | 2 +- static-data/default_config.json | 4 ++-- 5 files changed, 34 insertions(+), 8 deletions(-) create mode 100755 scripts/testblock.py diff --git a/pow-csharp/onionrpow-cli/Program.cs b/pow-csharp/onionrpow-cli/Program.cs index cdf44ecd..770b594a 100644 --- a/pow-csharp/onionrpow-cli/Program.cs +++ b/pow-csharp/onionrpow-cli/Program.cs @@ -1,5 +1,7 @@ using System; using System.Text; +using System.IO; +using System.Collections.Generic; using onionrpow; @@ -9,8 +11,18 @@ namespace onionrpow_cli { static void Main(string[] args) { - Console.WriteLine("Hello World!"); - onionrpow.OnionrPow.compute(Encoding.UTF8.GetBytes("test"), 4); + + using (Stream stdin = Console.OpenStandardInput()) + { + var data = new List(); + byte[] buffer = new byte[60000]; + int bytes; + while ((bytes = stdin.Read(buffer, 0, buffer.Length)) > 0) { + //stdout.Write(buffer, 0, bytes); + data.AddRange(buffer); + } + onionrpow.OnionrPow.compute(data.ToArray(), 3); + } } } } diff --git a/pow-csharp/onionrpow/OnionrPow.cs b/pow-csharp/onionrpow/OnionrPow.cs index bd85b954..44ed14be 100644 --- a/pow-csharp/onionrpow/OnionrPow.cs +++ b/pow-csharp/onionrpow/OnionrPow.cs @@ -11,7 +11,7 @@ namespace onionrpow public static void compute(byte[] data, int difficulty){ using (var shaAlg = SHA3.Net.Sha3.Sha3256()) { - // Replace beginning json with nonce + // Replace beginning json with counter int counter = 0; var copy = new List(); @@ -25,12 +25,12 @@ namespace onionrpow copy.Add(co); } int c = 0; + var copy2 = new List(); while (true){ toploop: c += 1; var num = Encoding.UTF8.GetBytes("{\"pow\": " + c.ToString() + ","); - var copy2 = new List(); - + copy2.Clear(); copy2.AddRange(num); copy2.AddRange(copy); var hash = shaAlg.ComputeHash(copy2.ToArray()); @@ -45,7 +45,9 @@ namespace onionrpow break; } } + Console.WriteLine(Encoding.UTF8.GetString(copy2.ToArray())); Console.WriteLine(BitConverter.ToString(hash)); + Console.WriteLine(c); break; } } diff --git a/scripts/testblock.py b/scripts/testblock.py new file mode 100755 index 00000000..f0085641 --- /dev/null +++ b/scripts/testblock.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python3 + +import sys +import os +if not os.path.exists('onionr.sh'): + os.chdir('../') +sys.path.append("src/") +import onionrblocks + +expire = 600 +print(onionrblocks.insert(data=os.urandom(32), expire=expire)) + diff --git a/src/onionrproofs/subprocesspow.py b/src/onionrproofs/subprocesspow.py index 33571823..901f0ef4 100755 --- a/src/onionrproofs/subprocesspow.py +++ b/src/onionrproofs/subprocesspow.py @@ -113,7 +113,7 @@ class SubprocessPOW: nonce = 0 data = self.data metadata = self.metadata - metadata['nonce'] = secrets.randbits(16) + metadata['n'] = secrets.randbits(16) puzzle = self.puzzle difficulty = self.difficulty diff --git a/static-data/default_config.json b/static-data/default_config.json index b20fe114..c7e3b280 100755 --- a/static-data/default_config.json +++ b/static-data/default_config.json @@ -14,8 +14,8 @@ "hide_created_blocks": true, "insert_deniable_blocks": true, "max_block_age": 2678400, - "minimum_block_pow": 5, - "minimum_send_pow": 5, + "minimum_block_pow": 6, + "minimum_send_pow": 6, "public_key": "", "random_bind_ip": true, "security_level": 0,