Skip to content

Instantly share code, notes, and snippets.

@drewstaylor
Last active April 11, 2021 00:26
Show Gist options
  • Save drewstaylor/1df33cb3fc3888070b898b7cfe8b6bbf to your computer and use it in GitHub Desktop.
Save drewstaylor/1df33cb3fc3888070b898b7cfe8b6bbf to your computer and use it in GitHub Desktop.
Project Uanon - Generating proofs in Python
'''
Example 2 looks at ascensions, which are special end of season puzzles. They require you submit all previous proofs of the season, in consecutive order, as well as the passwords of the current puzzle. Hashing rounds are increased for all puzzles with rewards. If a puzzle has rewards but isn't the final puzzle of that season, you won't need to submit all of the sub proofs in addition to the current passwords, but you will need to increase the rounds of hashing. You can access this ascension example at https://uanon.observer/learn, but only if you're holding the correct sub-proofs.
Title: Through darkness and the ages, softly
Description: We ascend
Public Key: afbda72bc5ca82bc61d800fcc8fdfa4f059d95e58879795863b34525ded88fce
Operation: oorfEK3FTyx3ha5FPY8vmpEQ86z1xQemVMXGd5BkNbqRPJTXHpq
Format: Separate the sentences and add spaces between words. Cipher provides the case. No punctuation.
Hint: Solution 4 is a single character, if you're confused get your faqs straight
'''
import hashlib
import json
# Configuration
asc_public_key = 'afbda72bc5ca82bc61d800fcc8fdfa4f059d95e58879795863b34525ded88fce'
pad_size = 4
is_tezos_transaction = True
debug = True
debug_verbose = False
if is_tezos_transaction is True:
hashing_rounds = 1001
else:
hashing_rounds = 2
'''
Replace these with your own proofs derived from the output of the `log` command from console mode after solving Tutorials 1 to 5.
'''
# Sub-proofs
subproof_tutorial_1 = ''
subproof_tutorial_2 = ''
subproof_tutorial_3 = ''
subproof_tutorial_4 = ''
subproof_tutorial_5 = ''
# Manage array of passwords
fields = [
# Previous proofs of season
subproof_tutorial_1,
subproof_tutorial_2,
subproof_tutorial_3,
subproof_tutorial_4,
subproof_tutorial_5,
# Current puzzle solutions
'Well done player',
'We wait for light but behold darkness',
'I wish you a world free of demons and full of light',
'U'
]
fields = json.dumps(fields, separators=(',',':'))
len_bytes = (len(fields)).to_bytes(pad_size, byteorder='big')
fields = fields.encode()
# Data prefix
prefix = b'\x05\x01'
raw_secret = prefix + len_bytes + fields
# Rounds settings init
iterations = list(range(hashing_rounds))
last_hash = False
last_hash_b = None
attempts = []
# Hashing rounds
for i in iterations:
if last_hash is False:
attempts.append(raw_secret)
hash_i = hashlib.blake2b(raw_secret, digest_size=32).digest()
if debug is True:
print('Raw Secret:', raw_secret)
else:
hash_i = hashlib.blake2b(last_hash_b, digest_size=32).digest()
last_hash = hash_i.hex()
last_hash_b = hash_i
attempts.append(last_hash)
if debug is True:
print('Iteration ' + str(i+1) + ':', last_hash)
if debug_verbose is True:
print('\nSolution chain:\n')
print(attempts)
# What is True?
assert last_hash == asc_public_key, 'Final hash does not match public key'
# The opposite of False
print('\nFinal hash (' + last_hash + ') and Public Key (' + asc_public_key + ') are equivalent\n')
'''
Example 1 uses the first Tutorial. This puzzle does not include a Tezos and transaction and is not an ascension. You can access the puzzle at https://uanon.observer/tutorial/1.
Title: Hello World
Description: The site says: {payload}
Public Key: df69b9d584c7594c819796d31b8c9b174a3c2f45f3a1e9f3443ce4831584c074
Operation: opYLmo1SAtwSWzQEMfmAmFRBucqAFZu42591XwcmgyVJrEQsUKN
Payload: Hello
Format: 1 word, uppercase first letter
'''
import hashlib
import json
# Configuration
t1_public_key = 'df69b9d584c7594c819796d31b8c9b174a3c2f45f3a1e9f3443ce4831584c074'
pad_size = 4
is_tezos_transaction = False
debug = True
debug_verbose = False
if is_tezos_transaction is True:
hashing_rounds = 1001
else:
hashing_rounds = 2
# Manage array of passwords
fields = ["World"]
fields = json.dumps(fields, separators=(',',':'))
len_bytes = (len(fields)).to_bytes(pad_size, byteorder='big')
fields = fields.encode()
# Data prefix
prefix = b'\x05\x01'
raw_secret = prefix + len_bytes + fields
# Rounds settings init
iterations = list(range(hashing_rounds))
last_hash = False
last_hash_b = None
attempts = []
# Hashing rounds
for i in iterations:
if last_hash is False:
attempts.append(raw_secret)
hash_i = hashlib.blake2b(raw_secret, digest_size=32)
if debug is True:
print('Raw Secret:', raw_secret)
else:
hash_i = hashlib.blake2b(last_hash_b, digest_size=32)
last_hash = hash_i.hexdigest()
last_hash_b = hash_i.digest()
attempts.append(last_hash)
if debug is True:
print('Iteration ' + str(i) + ':', last_hash)
# What is True?
assert last_hash == t1_public_key, 'Final hash does not match public key'
# The opposite of False
print('\nFinal hash (' + last_hash + ') and Public Key (' + t1_public_key + ') are equivalent\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment