diff --git a/ghost.py b/ghost.py index 9300fed..a415c7f 100644 --- a/ghost.py +++ b/ghost.py @@ -1,15 +1,15 @@ # Time between successful PoW solutions -POW_SOLUTION_TIME = 60 +POW_SOLUTION_TIME = 6 # Time for a block to traverse the network TRANSIT_TIME = 12 # Max uncle depth -UNCLE_DEPTH = 1 +UNCLE_DEPTH = 4 # Uncle block reward (normal block reward = 1) -UNCLE_REWARD_COEFF = 7/8. +UNCLE_REWARD_COEFF = 15/16. # Reward for including uncles -NEPHEW_REWARD_COEFF = 1/16. +NEPHEW_REWARD_COEFF = 1/32. # Rounds to test -ROUNDS = 1000000 +ROUNDS = 500000 import random diff --git a/mining.py b/mining.py new file mode 100644 index 0000000..ff7a474 --- /dev/null +++ b/mining.py @@ -0,0 +1,59 @@ +import pyethereum +u = pyethereum.utils +import time + +ops = [ + lambda x, y: x+y % 2**256, + lambda x, y: x*y % 2**256, + lambda x, y: x % y if y > 0 else x+y, + lambda x, y: x & y, + lambda x, y: x | y, + lambda x, y: x ^ y +] + + +def gen(seed, w, d): + tape = [] + h = 0 + for i in range(d): + if h < 2**32: + h = u.big_endian_to_int(u.sha3(seed+str(i))) + v1 = h % w + h /= w + v2 = h % w + h /= w + op = ops[h % len(ops)] + h /= len(ops) + tape.append([v1, v2, op]) + return tape + + +def lshift(n): + return 2**255 * (n % 2) + (n / 2) + + +def run(seed, w, tape): + v = [] + h = 0 + for i in range(w): + if i % 1 == 0: + h = u.big_endian_to_int(u.sha3(seed+str(i))) + else: + h = lshift(h) + v.append(h) + for t in tape: + v[t[0]] = t[2](v[t[0]], v[t[1]]) + return u.sha3(str(v)) + + +def test(): + t1 = time.time() + for i in range(10): + tape = gen(str(i), 1000, 1000) + print time.time() - t1 + + t2 = time.time() + for i in range(10): + p = run(str(i), 1000, tape) + print time.time() - t2 + p = p