Scoreboard by Robin Jadoul and address fix

main
six 2022-08-25 18:13:05 +02:00
parent 52a5721572
commit a09dc4b008
4 changed files with 78 additions and 5 deletions

View File

@ -19,7 +19,7 @@ The story of CCTF: From crypto hackers' vision to the biggest web3 hacking compe
**Finish date**: 2022 August 26., 16:00, Singapore Time - UTC/GMT +8
**Global location link**: Flags are to be submitted to the CCTF smart contract!
**Global location link**: TBA (flags are to be submitted to the CCTF smart contract)
**Physical location**: HiTB Conference, InterContinental Singapore, 80 Middle Rd, Singapore 188966

View File

@ -1,7 +1,7 @@
## CCTF vol9 Info
Max points = 4096
Registration => https://polygonscan.com/address/0x5c9d7d00880a6dda6fc0a27ea682f513eab8045a#writeContract
Registration => https://polygonscan.com/address/0x36a1424da63a50627863d8f65c0669da7347814a
How to and rules => https://cryptoctf.org/2022/08/22/decentralized-ctf/
@ -9,8 +9,6 @@ If you have not found a private key, but a standard string, use one of this API:
http://209.250.246.26:6789/get?flag=CCTF{test}
fyord7wc4lzrgp4g4v2z7nhftoymolmmhmuixgkmnvo6f2bvlqdtjjid.onion
Start date, Day 0: 2022 August 25, 10:00, Singapore Time - UTC/GMT +8
Release of Day 1 challenges: Start date: 2022 August 26, 10:00, Singapore Time - UTC/GMT +8

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,74 @@
#!/usr/bin/env python3
# This scoreboard is a community contribution by Robin Jadoul. Thank you!
import collections, pickle
import rich.console, rich.table
from pwn import *
from web3 import Web3, HTTPProvider
from web3.middleware import geth_poa_middleware
import eth_account, eth_abi
import pprint, time, json, shutil, os
import requests
web3 = Web3(HTTPProvider("https://polygon-rpc.com/"))
web3.middleware_onion.inject(geth_poa_middleware, layer=0)
GAME_CONTRACT = "0x36A1424DA63a50627863d8f65C0669da7347814A"
GAME = web3.eth.contract(GAME_CONTRACT, abi=json.load(open("game_abi.json")))
known_addresses = {
#"address": "username", # Fill it if you want to see the names
}
#############################################################
BLOCK_START = 32265959
BLOCK_END = web3.eth.block_number
BLOCK_RANGE = 10000
if os.path.exists("scoreboard.pkl"):
with open("scoreboard.pkl", "rb") as f:
seenEvents = pickle.load(f)
else:
seenEvents = {}
def iterEvents(ev):
name = ev.event_name
known, start = seenEvents.get(name, ([], BLOCK_START))
yield from known
for i in range(start, BLOCK_END + 1, BLOCK_RANGE):
res = ev.getLogs(fromBlock=hex(i), toBlock=hex(i + BLOCK_RANGE))
known += list(res)
yield from res
seenEvents[name] = (known, BLOCK_END)
with open("scoreboard.pkl", "wb") as f:
pickle.dump(seenEvents, f)
def main():
con = rich.console.Console()
allchals = []
solves = collections.defaultdict(lambda: collections.defaultdict(lambda: False))
for chal in iterEvents(GAME.events.FlagAdded):
chal = (chal["args"]["flagId"], GAME.caller.flags(chal["args"]["flagId"])[3])
allchals.append(chal)
for solve in iterEvents(GAME.events.FlagSolved):
solver, chal = solve["args"]["solver"], solve["args"]["flagId"]
solves[solver][chal] = True
board = [(solver if solver not in known_addresses else f"[bold cyan]{known_addresses[solver]}", str(GAME.caller.getPlayerPoints(solver))) + tuple(["[bold red]:x:", "[bold green]:heavy_check_mark:"][solved[c[0]]] for c in allchals) for solver, solved in solves.items()]
allchals.sort()
board.sort(key = lambda e: (int(e[1]), e[0]), reverse=True)
tab = rich.table.Table("Rank", "User", "Score", *[c[1] for c in allchals], title="Scoreboard")
for i, b in enumerate(board, 1):
tab.add_row(str(i), *b)
con.print(tab)
if __name__ == "__main__":
main()