Skip to content

Instantly share code, notes, and snippets.

@Shungy
Last active July 10, 2023 10:52
Show Gist options
  • Save Shungy/1c3a0512306763a847d853e8f06d4254 to your computer and use it in GitHub Desktop.
Save Shungy/1c3a0512306763a847d853e8f06d4254 to your computer and use it in GitHub Desktop.
Curta Puzzle 13 Solution
import sys
import re
from starknet_py.hash.utils import pedersen_hash
from eth_utils import keccak, big_endian_to_int, to_checksum_address
# Change to at least ~10 hours after the current block due to L2->L1 Starknet transaction delay.
TARGET_BLOCK = 17666132
# Change to your Ethereum adress in decimal format.
MY_ADDRESS = 544888184176857984448844311794968001596801059536
# PingPong contract address in decimal format. Do not change.
TARGET = 721328058414722799301191226073744132574071370988
def mine_bobstuart(kevin):
bobstuart = 1
while True:
solution = pedersen_hash(bobstuart, bobstuart)
solution = pedersen_hash(kevin[0], solution)
solution = pedersen_hash(kevin[1], solution)
if re.match(r'^0xac[a-f0-9]{60}$', hex(solution)):
return (bobstuart, solution)
bobstuart += 1
start = big_endian_to_int(keccak(hexstr=f'0x{MY_ADDRESS:040x}{TARGET_BLOCK:064x}'))
kevin = [start >> 128, ((start << 128) % (2**256)) >> 128]
(bobstuart, solution) = mine_bobstuart(kevin)
print("L2 Message")
print("==========")
print(f'target : {TARGET}')
print(f'kev : {kevin[0]}')
print(f'in : {kevin[1]}')
print(f'bob : {bobstuart}')
print(f'stuart : {bobstuart}')
print()
print("L1 Submission")
print("=============")
print(f'block : {TARGET_BLOCK}')
print(f'from : {to_checksum_address(MY_ADDRESS)}')
print(f'solution : {solution}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment