Skip to content

Commit

Permalink
💡 solved check for cairo challenge
Browse files Browse the repository at this point in the history
  • Loading branch information
cairoeth committed Mar 9, 2024
1 parent 5a7227f commit 0ba9207
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
39 changes: 23 additions & 16 deletions paradigmctf.py/ctf_launchers/starknet_pwn_launcher.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import os

import json
import requests
from ctf_launchers.launcher import Action, Launcher, ORCHESTRATOR_HOST, CHALLENGE
from ctf_launchers.team_provider import TeamProvider, get_team_provider
from ctf_server.types import UserData
from ctf_server.types import UserData, get_privileged_web3

FLAG = os.getenv("FLAG", "PCTF{flag}")

Expand All @@ -24,7 +24,8 @@ def __init__(
)

def get_flag(self) -> int:
instance_body = requests.get(f"{ORCHESTRATOR_HOST}/instances/{self.get_instance_id()}").json()
instance_body = requests.get(
f"{ORCHESTRATOR_HOST}/instances/{self.get_instance_id()}").json()
if not instance_body['ok']:
print(instance_body['message'])
return 1
Expand All @@ -41,16 +42,22 @@ def get_flag(self) -> int:
return 0

def is_solved(self, user_data: UserData, addr: str) -> bool:
# web3 = get_privileged_web3(user_data, "main")

# (result,) = abi.decode(
# ["bool"],
# web3.eth.call(
# {
# "to": addr,
# "data": web3.keccak(text="isSolved()")[:4],
# }
# ),
# )
# return result
return False
web3 = get_privileged_web3(user_data, "main")

x = requests.post(web3.provider.endpoint_uri + "/rpc", json={
"id": 1,
"jsonrpc": "2.0",
"method": "starknet_call",
"params": [
{
"contract_address": addr,
"calldata": [],
"entry_point_selector": "0x1f8ddd388f265b0bcab25a3e457e789fe182bdf8ede59d9ef42b3158a533c8"
},
"latest"
]
})

solved = True if json.loads(x.text)['result'][0] == "0x0" else False

return solved
4 changes: 2 additions & 2 deletions paradigmctf.py/ctf_launchers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ def deploy_cairo(
print(stderr)
raise Exception("script failed to run")

output = stdout.split('address: ')
output = stdout.split('address: ')[1].replace("\\n", "")

return output[1]
return output[:65]


def anvil_setCodeFromFile(
Expand Down
2 changes: 1 addition & 1 deletion paradigmctf.py/ctf_server/anvil_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from .utils import load_database


ALLOWED_NAMESPACES = ["web3", "eth", "net"]
ALLOWED_NAMESPACES = ["web3", "eth", "net", "starknet"]
DISALLOWED_METHODS = [
"eth_sign",
"eth_signTransaction",
Expand Down

0 comments on commit 0ba9207

Please sign in to comment.