Skip to content

Commit b85c53e

Browse files
authored
Add Comments to Help Understanding
1 parent 3d5ec14 commit b85c53e

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

ethereum/pow/ethash.py

+6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def _get_cache(seed, n):
2828
for i in range(1, n):
2929
o.append(sha3_512(o[-1]))
3030

31+
# Use a low-round version of randmemohash
3132
for _ in range(CACHE_ROUNDS):
3233
for i in range(n):
3334
v = o[i][0] % n
@@ -39,9 +40,11 @@ def _get_cache(seed, n):
3940
def calc_dataset_item(cache, i):
4041
n = len(cache)
4142
r = HASH_BYTES // WORD_BYTES
43+
# initialize the mix
4244
mix = copy.copy(cache[i % n])
4345
mix[0] ^= i
4446
mix = sha3_512(mix)
47+
# fnv it with a lot of random cache nodes based on i
4548
for j in range(DATASET_PARENTS):
4649
cache_index = fnv(i ^ j, mix[j % r])
4750
mix = list(map(fnv, mix, cache[cache_index % n]))
@@ -64,16 +67,19 @@ def hashimoto(header, nonce, full_size, dataset_lookup):
6467
n = full_size // HASH_BYTES
6568
w = MIX_BYTES // WORD_BYTES
6669
mixhashes = MIX_BYTES // HASH_BYTES
70+
# combine header+nonce into a 64 byte seed
6771
s = sha3_512(header + nonce[::-1])
6872
mix = []
6973
for _ in range(MIX_BYTES // HASH_BYTES):
7074
mix.extend(s)
75+
# mix in random dataset nodes
7176
for i in range(ACCESSES):
7277
p = fnv(i ^ s[0], mix[i % w]) % (n // mixhashes) * mixhashes
7378
newdata = []
7479
for j in range(mixhashes):
7580
newdata.extend(dataset_lookup(p + j))
7681
mix = list(map(fnv, mix, newdata))
82+
# compress mix
7783
cmix = []
7884
for i in range(0, len(mix), 4):
7985
cmix.append(fnv(fnv(fnv(mix[i], mix[i + 1]), mix[i + 2]), mix[i + 3]))

0 commit comments

Comments
 (0)