Clean {verifier, prover}.py
This commit is contained in:
parent
edfe8d183b
commit
d6b26fa7a0
14
prover.py
Normal file → Executable file
14
prover.py
Normal file → Executable file
@ -1,3 +1,5 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
## Proof of Space-Time prover
|
||||
|
||||
import math, common, ast
|
||||
@ -88,31 +90,19 @@ for indexRequest in indexesRequest:
|
||||
for index in [indexRequest, otherIndex]:
|
||||
verificationMerkleTreeLevels[0][index] = merkleTreeLevels[0][index]
|
||||
|
||||
"""
|
||||
for merkleTreeLevelsIndex, merkleTreeLevel in enumerate(merkleTreeLevels):
|
||||
for i, hash in enumerate(merkleTreeLevel):
|
||||
verificationMerkleTreeLevels[merkleTreeLevelsIndex][i] = hash
|
||||
"""
|
||||
|
||||
entries = []
|
||||
for verificationMerkleTreeLevelsIndex, verificationMerkleTreeLevel in enumerate(verificationMerkleTreeLevels[:-1]):
|
||||
for index in verificationMerkleTreeLevel:
|
||||
otherIndex = common.otherIndex(index)
|
||||
leftIndex, rightIndex = sorted([index, otherIndex])
|
||||
#leftHash, rightHash = [merkleTreeLevels[verificationMerkleTreeLevel][i] for i in [leftIndex, rightIndex]]
|
||||
leftHash, rightHash = [merkleTreeLevels[verificationMerkleTreeLevelsIndex][i] for i in [leftIndex, rightIndex]]
|
||||
otherHash = merkleTreeLevels[verificationMerkleTreeLevelsIndex][otherIndex]
|
||||
verificationMerkleTreeLevels[verificationMerkleTreeLevelsIndex + 1][leftIndex // 2] = common.hash(leftHash + rightHash)
|
||||
if verificationMerkleTreeLevelsIndex > 0 or leftIndex == index:
|
||||
if verificationMerkleTreeLevelsIndex == 0:
|
||||
print(leftIndex, rightIndex)
|
||||
entries += [leftHash, rightHash]
|
||||
# for i, hash in zip([leftIndex, rightIndex], [leftHash, rightHash]):
|
||||
# verificationMerkleTreeLevels[verificationMerkleTreeLevelsIndex][i] = hash
|
||||
else:
|
||||
print(otherIndex)
|
||||
entries += [otherHash]
|
||||
# verificationMerkleTreeLevels[verificationMerkleTreeLevelsIndex][otherIndex] = otherHash
|
||||
|
||||
print(f'{entries=}')
|
||||
|
||||
|
19
verifier.py
Normal file → Executable file
19
verifier.py
Normal file → Executable file
@ -1,3 +1,5 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
## Proof of Space-Time verifier
|
||||
|
||||
import secrets, common, ast
|
||||
@ -58,30 +60,13 @@ for index in indexesRequest:
|
||||
merkleTreeLevels[0][i] = hash
|
||||
|
||||
for merkleTreeLevelsIndex, merkleTreeLevel in enumerate(merkleTreeLevels[:-1]):
|
||||
print(merkleTreeLevelsIndex)
|
||||
print('before', merkleTreeLevels[merkleTreeLevelsIndex])
|
||||
for index in merkleTreeLevel.copy():
|
||||
otherIndex = common.otherIndex(index)
|
||||
leftIndex, rightIndex = sorted([index, otherIndex])
|
||||
if merkleTreeLevelsIndex > 0:
|
||||
print(f'current: {otherIndex}')
|
||||
merkleTreeLevels[merkleTreeLevelsIndex][otherIndex] = entries.pop(0)
|
||||
leftHash, rightHash = [merkleTreeLevels[merkleTreeLevelsIndex][i] for i in [leftIndex, rightIndex]]
|
||||
merkleTreeLevels[merkleTreeLevelsIndex + 1][leftIndex // 2] = common.hash(leftHash + rightHash)
|
||||
"""for i, hash in zip([leftIndex // 2, common.otherIndex(leftIndex)], [common.hash(leftHash + rightHash), '']):
|
||||
print(f'next: {i}')
|
||||
merkleTreeLevels[merkleTreeLevelsIndex + 1][i] = hash"""
|
||||
print('after', merkleTreeLevels[merkleTreeLevelsIndex])
|
||||
|
||||
"""
|
||||
for merkleTreeLevelsIndex, merkleTreeLevel in enumerate(merkleTreeLevels[:-1]):
|
||||
for index in merkleTreeLevel:
|
||||
otherIndex = common.otherIndex(index)
|
||||
leftIndex, rightIndex = sorted([index, otherIndex])
|
||||
leftHash, rightHash = [merkleTreeLevels[merkleTreeLevel][i] for i in [leftIndex, rightIndex]]
|
||||
otherHash = merkleTreeLevels[merkleTreeLevelsIndex][otherIndex]
|
||||
merkleTreeLevels[merkleTreeLevelsIndex + 1][leftIndex // 2] = common.hash(leftHash + rightHash)
|
||||
"""
|
||||
|
||||
# Note that `actualStorage` is the average storage that the prover should have dedicated to be able to solve this execution phase challenge.
|
||||
# If any entry corresponding to requested indexes is incorrect, the Merkle tree won't match or the verification of the claimed difficulty of the provided hash will fail.
|
||||
|
Loading…
Reference in New Issue
Block a user