Compare commits

...

2 Commits

Author SHA1 Message Date
a5b18ef24b #8: Debugging 2023-06-03 16:32:19 +02:00
9fd6d63734 Add reproducibility to solve #8 2023-06-03 15:40:22 +02:00
4 changed files with 30 additions and 10 deletions

View File

@@ -45,4 +45,4 @@ def otherIndex(n):
def doesHashMatchDifficulty(hashed):
hashedInteger = int(hashed, 16)
hashedDifficulty = hashedInteger / LEAST_DIFFICULT_HASH
return hashedDifficulty <= MAXIMUM_HASH_DIFFICULTY
return hashedDifficulty <= MAXIMUM_HASH_DIFFICULTY

View File

@@ -34,6 +34,9 @@ while True:
write(prover, 'indexesRequest.txt')
getProgramLine(prover)
with open('indexesRequest.txt') as f:
print(f.read())
write(verifier, 'entries.txt')
result = ' '.join(getProgramLine(verifier).split()[1:])
print(result)

View File

@@ -2,7 +2,7 @@
## Proof of Space-Time prover
import math, common, ast
import math, common, ast, sys
# For the ratio between storing and power:
# Note that for a production ready system hashing speedup (as designed for Bitcoin in [AsicBoost - A Speedup for Bitcoin Mining, Dr. Timo Hanke, March 31, 2016 (rev. 5)](https://arxiv.org/pdf/1604.00575.pdf)) should be considered.
@@ -26,7 +26,7 @@ while len(STORED_NONCES) < common.ENTRIES_NUMBER:
deltaCounter = counter - lastCounter
STORED_NONCES += [deltaCounter]
lastCounter = counter
print(len(STORED_NONCES), common.ENTRIES_NUMBER)
print(len(STORED_NONCES), common.ENTRIES_NUMBER, file=sys.stderr)
counter += 1
## Execution phase: 1. Receive a random bitstring from the verifier.
@@ -82,14 +82,19 @@ with open(input('indexesRequest: ')) as f:
verificationMerkleTreeLevels = [{} for _ in range(common.LEVELS)]
print(len(indexesRequest))
for indexRequest in indexesRequest:
otherIndex = common.otherIndex(indexRequest)
print(indexRequest, otherIndex)
for index in [indexRequest, otherIndex]:
verificationMerkleTreeLevels[0][index] = merkleTreeLevels[0][index]
print(len(verificationMerkleTreeLevels[0]), verificationMerkleTreeLevels[0])
# Should rename `entries`, as they aren't *entries* for higher levels.
entries = []
for verificationMerkleTreeLevelsIndex, verificationMerkleTreeLevel in enumerate(verificationMerkleTreeLevels[:-1]):
#print('len', len(verificationMerkleTreeLevel))
for index in verificationMerkleTreeLevel:
otherIndex = common.otherIndex(index)
leftIndex, rightIndex = sorted([index, otherIndex])
@@ -100,9 +105,16 @@ for verificationMerkleTreeLevelsIndex, verificationMerkleTreeLevel in enumerate(
if verificationMerkleTreeLevelsIndex == 0:
leftNonce = sum(STORED_NONCES[:leftIndex + 1])
rightNonce = leftNonce + STORED_NONCES[rightIndex]
print(leftNonce, rightNonce)
entries += [leftNonce, rightNonce]
else:
print('once', otherHash)
entries += [otherHash]
elif verificationMerkleTreeLevelsIndex == 0:
leftNonce = sum(STORED_NONCES[:leftIndex + 1])
rightNonce = leftNonce + STORED_NONCES[rightIndex]
print('nope', leftNonce, rightNonce)
entriesFilePath = 'entries.txt'

View File

@@ -2,19 +2,19 @@
## Proof of Space-Time verifier
import secrets, common, ast
import secrets, common, ast, sys
## Initialization phase: Generate a random bitstring to send to the prover.
# To make sure that the following protocol execution can't be used partially or totally by the prover to reduce the cost of another protocol execution.
protocolInitializationPhaseId = secrets.token_hex(common.SECURITY_PARAMETER // 8)
protocolInitializationPhaseId = secrets.token_hex(common.SECURITY_PARAMETER // 8) if len(sys.argv) == 1 else sys.argv[1]
print(f'{protocolInitializationPhaseId=}')
## Execution phase: 1. Generate a random bitstring to send to the prover.
# TODO: improve step numbering, as it's a bit unclear what step of each to run after which one
# Wait the initialization phase termination from the prover side before starting the execution phase.
protocolExecutionPhaseId = secrets.token_hex(common.SECURITY_PARAMETER // 8)
protocolExecutionPhaseId = secrets.token_hex(common.SECURITY_PARAMETER // 8) if len(sys.argv) <= 2 else sys.argv[2]
print(f'{protocolExecutionPhaseId=}')
## Execution phase: 2. Receive the prover commitment to the table contents given this random challenge.
@@ -28,11 +28,12 @@ merkleTreeRoot = input('merkleTreeRoot: ')
# Note that there's no advantage to request the last table entry by hoping that the prover is storing the nonces with delta in such order, for instance he can have stored the delta the other way around which screw up this additional request aim.
indexesRequest = set()
indexesRequest = set() if len(sys.argv) <= 3 else ast.literal_eval(sys.argv[3])
while len(indexesRequest) < common.NUMBER_OF_ENTRIES_TO_VERIFY:
index = secrets.randbelow(common.ENTRIES_NUMBER)
indexesRequest.add(index)
if indexesRequest == set():
while len(indexesRequest) < common.NUMBER_OF_ENTRIES_TO_VERIFY:
index = secrets.randbelow(common.ENTRIES_NUMBER)
indexesRequest.add(index)
indexesRequestFilePath = 'indexesRequest.txt'
@@ -53,12 +54,16 @@ with open(input('entries: ')) as f:
merkleTreeLevels = [{} for _ in range(common.LEVELS)]
print(entries[:len(indexesRequest) * 2])
print(len(indexesRequest)) # 18
for index in indexesRequest:
otherIndex = common.otherIndex(index)
leftIndex, rightIndex = sorted([index, otherIndex])
for i, nonce in zip([leftIndex, rightIndex], [entries.pop(0) for _ in range(2)]):
print(protocolInitializationPhaseId, str(nonce))
hashed = common.hash(protocolInitializationPhaseId + str(nonce))
if not common.doesHashMatchDifficulty(hashed):
print(hashed)
print("The received difficulty doesn't match the claimed one!")
exit(1)
merkleTreeLevels[0][i] = common.hash(protocolInitializationPhaseId + protocolExecutionPhaseId + str(nonce))