From f875bc5e71dba2c1dff1d273c75a568df9501c7f Mon Sep 17 00:00:00 2001 From: cairo <101215230+cairoeth@users.noreply.github.com> Date: Thu, 7 Mar 2024 21:19:44 -0800 Subject: [PATCH 01/10] =?UTF-8?q?=E2=9C=A8=20Cairo=20pwn=20launcher?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .python-version | 1 + paradigmctf.py/ctf_launchers/launcher.py | 4 +- paradigmctf.py/ctf_launchers/pwn_launcher.py | 1 + .../ctf_launchers/starknet_pwn_launcher.py | 56 ++++++++++++++++ .../ctf_server/backends/docker_backend.py | 65 +++++++++++++------ paradigmctf.py/ctf_server/types/__init__.py | 1 + 6 files changed, 106 insertions(+), 22 deletions(-) create mode 100644 .python-version create mode 100644 paradigmctf.py/ctf_launchers/starknet_pwn_launcher.py diff --git a/.python-version b/.python-version new file mode 100644 index 0000000..d2c96c0 --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.11.3 diff --git a/paradigmctf.py/ctf_launchers/launcher.py b/paradigmctf.py/ctf_launchers/launcher.py index a72a710..5066929 100644 --- a/paradigmctf.py/ctf_launchers/launcher.py +++ b/paradigmctf.py/ctf_launchers/launcher.py @@ -33,8 +33,9 @@ class Action: class Launcher(abc.ABC): def __init__( - self, project_location: str, provider: TeamProvider, actions: List[Action] = [] + self, type: str, project_location: str, provider: TeamProvider, actions: List[Action] = [] ): + self.type = type self.project_location = project_location self.__team_provider = provider @@ -105,6 +106,7 @@ def launch_instance(self) -> int: body = requests.post( f"{ORCHESTRATOR_HOST}/instances", json=CreateInstanceRequest( + type=self.type, instance_id=self.get_instance_id(), timeout=TIMEOUT, anvil_instances=self.get_anvil_instances(), diff --git a/paradigmctf.py/ctf_launchers/pwn_launcher.py b/paradigmctf.py/ctf_launchers/pwn_launcher.py index 73138e2..dcc9497 100644 --- a/paradigmctf.py/ctf_launchers/pwn_launcher.py +++ b/paradigmctf.py/ctf_launchers/pwn_launcher.py @@ -17,6 +17,7 @@ def __init__( provider: TeamProvider = get_team_provider(), ): super().__init__( + 'ethereum', project_location, provider, [ diff --git a/paradigmctf.py/ctf_launchers/starknet_pwn_launcher.py b/paradigmctf.py/ctf_launchers/starknet_pwn_launcher.py new file mode 100644 index 0000000..26e7e9b --- /dev/null +++ b/paradigmctf.py/ctf_launchers/starknet_pwn_launcher.py @@ -0,0 +1,56 @@ +import os + +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 + +FLAG = os.getenv("FLAG", "PCTF{flag}") + + +class StarknetPwnChallengeLauncher(Launcher): + def __init__( + self, + project_location: str = "challenge/project", + provider: TeamProvider = get_team_provider(), + ): + super().__init__( + 'starknet', + project_location, + provider, + [ + Action(name="get flag", handler=self.get_flag), + ], + ) + + def get_flag(self) -> int: + instance_body = requests.get(f"{ORCHESTRATOR_HOST}/instances/{self.get_instance_id()}").json() + if not instance_body['ok']: + print(instance_body['message']) + return 1 + + user_data = instance_body['data'] + + if not self.is_solved( + user_data, user_data['metadata']["challenge_address"] + ): + print("are you sure you solved it?") + return 1 + + print(FLAG) + 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 diff --git a/paradigmctf.py/ctf_server/backends/docker_backend.py b/paradigmctf.py/ctf_server/backends/docker_backend.py index 9faece8..f4272fb 100644 --- a/paradigmctf.py/ctf_server/backends/docker_backend.py +++ b/paradigmctf.py/ctf_server/backends/docker_backend.py @@ -36,27 +36,50 @@ def _launch_instance_impl(self, request: CreateInstanceRequest) -> UserData: anvil_containers: Dict[str, Container] = {} for anvil_id, anvil_args in request["anvil_instances"].items(): - anvil_containers[anvil_id] = self.__client.containers.run( - name=f"{instance_id}-{anvil_id}", - image=anvil_args.get("image", DEFAULT_IMAGE), - network="paradigmctf", - entrypoint=["sh", "-c"], - command=[ - "while true; do anvil " - + " ".join( - [ - shlex.quote(str(v)) - for v in format_anvil_args(anvil_args, anvil_id) - ] - ) - + "; sleep 1; done;" - ], - restart_policy={"Name": "always"}, - detach=True, - mounts=[ - Mount(target="/data", source=volume.id), - ], - ) + if request["type"] == "starknet": + anvil_containers[anvil_id] = self.__client.containers.run( + name=f"{instance_id}-{anvil_id}", + image=anvil_args.get("image", "shardlabs/starknet-devnet-rs"), + network="paradigmctf", + entrypoint=["sh", "-c"], + # command=[ + # "while true; do anvil " + # + " ".join( + # [ + # shlex.quote(str(v)) + # for v in format_anvil_args(anvil_args, anvil_id) + # ] + # ) + # + "; sleep 1; done;" + # ], + restart_policy={"Name": "always"}, + detach=True, + mounts=[ + Mount(target="/data", source=volume.id), + ], + ) + else: + anvil_containers[anvil_id] = self.__client.containers.run( + name=f"{instance_id}-{anvil_id}", + image=anvil_args.get("image", DEFAULT_IMAGE), + network="paradigmctf", + entrypoint=["sh", "-c"], + command=[ + "while true; do anvil " + + " ".join( + [ + shlex.quote(str(v)) + for v in format_anvil_args(anvil_args, anvil_id) + ] + ) + + "; sleep 1; done;" + ], + restart_policy={"Name": "always"}, + detach=True, + mounts=[ + Mount(target="/data", source=volume.id), + ], + ) daemon_containers: Dict[str, Container] = {} for daemon_id, daemon_args in request.get("daemon_instances", {}).items(): diff --git a/paradigmctf.py/ctf_server/types/__init__.py b/paradigmctf.py/ctf_server/types/__init__.py index 1f514bc..26b56c5 100644 --- a/paradigmctf.py/ctf_server/types/__init__.py +++ b/paradigmctf.py/ctf_server/types/__init__.py @@ -70,6 +70,7 @@ class DaemonInstanceArgs(TypedDict): class CreateInstanceRequest(TypedDict): + type: str instance_id: str timeout: int anvil_instances: NotRequired[Dict[str, LaunchAnvilInstanceArgs]] From 272d198ae56626b11754e36751c20460fae3b682 Mon Sep 17 00:00:00 2001 From: cairo <101215230+cairoeth@users.noreply.github.com> Date: Thu, 7 Mar 2024 22:03:25 -0800 Subject: [PATCH 02/10] =?UTF-8?q?=F0=9F=9A=A7=20starknet=20dev=20node?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + paradigmctf.py/ctf_server/backends/backend.py | 18 ++++++++++++++++++ .../ctf_server/backends/docker_backend.py | 13 ++----------- paradigmctf.py/requirements.txt | 14 ++++++++++++++ paradigmctf.py/setup.py | 2 +- paradigmctf.py/starknet/__init__.py | 0 paradigmctf.py/starknet/anvil.py | 14 ++++++++++++++ 7 files changed, 50 insertions(+), 12 deletions(-) create mode 100644 paradigmctf.py/starknet/__init__.py create mode 100644 paradigmctf.py/starknet/anvil.py diff --git a/.gitignore b/.gitignore index 540c0cb..fb086ad 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ /include **/__pycache__ .DS_Store +dump.rdb diff --git a/paradigmctf.py/ctf_server/backends/backend.py b/paradigmctf.py/ctf_server/backends/backend.py index 03b7541..16540da 100644 --- a/paradigmctf.py/ctf_server/backends/backend.py +++ b/paradigmctf.py/ctf_server/backends/backend.py @@ -18,7 +18,9 @@ from eth_account import Account from eth_account.hdaccount import key_from_seed, seed_from_mnemonic from foundry.anvil import anvil_setBalance +from starknet.anvil import starknet_setBalance from web3 import Web3 +from starknet_py.net.full_node_client import FullNodeClient class InstanceExists(Exception): @@ -97,3 +99,19 @@ def _prepare_node(self, args: LaunchAnvilInstanceArgs, web3: Web3): ).address, hex(int(args.get("balance", DEFAULT_BALANCE) * 10**18)), ) + + def _prepare_node_starknet(self, args: LaunchAnvilInstanceArgs, web3: FullNodeClient): + while type(web3.get_chain_id_sync()) != str: + time.sleep(0.1) + continue + + for i in range(args.get("accounts", DEFAULT_ACCOUNTS)): + starknet_setBalance( + web3, + self.__derive_account( + args.get("derivation_path", DEFAULT_DERIVATION_PATH), + args.get("mnemonic", DEFAULT_MNEMONIC), + i, + ).address, + int(args.get("balance", DEFAULT_BALANCE) * 10**18), + ) diff --git a/paradigmctf.py/ctf_server/backends/docker_backend.py b/paradigmctf.py/ctf_server/backends/docker_backend.py index f4272fb..34dfea8 100644 --- a/paradigmctf.py/ctf_server/backends/docker_backend.py +++ b/paradigmctf.py/ctf_server/backends/docker_backend.py @@ -36,22 +36,13 @@ def _launch_instance_impl(self, request: CreateInstanceRequest) -> UserData: anvil_containers: Dict[str, Container] = {} for anvil_id, anvil_args in request["anvil_instances"].items(): + print(request) if request["type"] == "starknet": anvil_containers[anvil_id] = self.__client.containers.run( name=f"{instance_id}-{anvil_id}", image=anvil_args.get("image", "shardlabs/starknet-devnet-rs"), network="paradigmctf", - entrypoint=["sh", "-c"], - # command=[ - # "while true; do anvil " - # + " ".join( - # [ - # shlex.quote(str(v)) - # for v in format_anvil_args(anvil_args, anvil_id) - # ] - # ) - # + "; sleep 1; done;" - # ], + entrypoint=["tini", "--", "starknet-devnet", "--host", "0.0.0.0", "--port", "8545"], restart_policy={"Name": "always"}, detach=True, mounts=[ diff --git a/paradigmctf.py/requirements.txt b/paradigmctf.py/requirements.txt index 8577cb8..a46bab8 100644 --- a/paradigmctf.py/requirements.txt +++ b/paradigmctf.py/requirements.txt @@ -2,6 +2,7 @@ aiohttp==3.8.6 aiosignal==1.3.1 annotated-types==0.6.0 anyio==3.7.1 +asgiref==3.7.2 async-timeout==4.0.3 asyncio==3.4.3 attrs==23.1.0 @@ -14,9 +15,11 @@ cffi==1.16.0 charset-normalizer==3.3.2 click==8.1.7 colored-traceback==0.3.0 +crypto_cpp_py==1.4.4 cryptography==41.0.5 cytoolz==0.12.2 docker==6.1.3 +ecdsa==0.18.0 eth-abi==4.2.1 eth-account==0.10.0 eth-hash==0.5.2 @@ -35,15 +38,23 @@ intervaltree==3.1.0 jsonschema==4.19.2 jsonschema-specifications==2023.7.1 kubernetes==28.1.0 +lark==1.1.9 lru-dict==1.2.0 Mako==1.3.0 MarkupSafe==2.1.3 +marshmallow==3.21.1 +marshmallow-dataclass==8.6.0 +marshmallow-oneofschema==3.0.1 +mpmath==1.3.0 multidict==6.0.4 +mypy-extensions==1.0.0 oauthlib==3.2.2 packaging==23.2 +paradigmctf.py==1.0.0 paramiko==3.3.1 parsimonious==0.9.0 plumbum==1.8.2 +poseidon_py==0.1.4 protobuf==4.25.0 psutil==5.9.6 pwntools==4.11.0 @@ -74,8 +85,11 @@ rsa==4.9 six==1.16.0 sniffio==1.3.0 sortedcontainers==2.4.0 +starknet-py==0.20.0 starlette==0.27.0 +sympy==1.11.1 toolz==0.12.0 +typing-inspect==0.9.0 typing_extensions==4.8.0 unicorn==2.0.1.post1 urllib3==1.26.18 diff --git a/paradigmctf.py/setup.py b/paradigmctf.py/setup.py index 9a124f9..a8b7115 100644 --- a/paradigmctf.py/setup.py +++ b/paradigmctf.py/setup.py @@ -14,5 +14,5 @@ "docker==6.1.3", "pwntools==4.11.0", ], - py_modules=["foundry", "ctf_server", "ctf_launchers", "ctf_solvers"], + py_modules=["foundry", "starknet", "ctf_server", "ctf_launchers", "ctf_solvers"], ) diff --git a/paradigmctf.py/starknet/__init__.py b/paradigmctf.py/starknet/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/paradigmctf.py/starknet/anvil.py b/paradigmctf.py/starknet/anvil.py new file mode 100644 index 0000000..b022ae9 --- /dev/null +++ b/paradigmctf.py/starknet/anvil.py @@ -0,0 +1,14 @@ +from starknet_py.net.full_node_client import FullNodeClient +import requests + + +def starknet_setBalance( + web3: FullNodeClient, + addr: str, + balance: int, +): + requests.post(web3.url + '/mint', json = { + 'address': addr, + 'amount': balance + }) + From dad203f2ee5f9615aeb72efeb2b37ffdda2a7574 Mon Sep 17 00:00:00 2001 From: cairo <101215230+cairoeth@users.noreply.github.com> Date: Thu, 7 Mar 2024 23:36:04 -0800 Subject: [PATCH 03/10] =?UTF-8?q?=F0=9F=90=9B=20Fix=20starknet=20status=20?= =?UTF-8?q?check?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- paradigmctf.py/ctf_server/backends/backend.py | 17 ++++++---- .../ctf_server/backends/docker_backend.py | 33 +++++++++++++------ paradigmctf.py/ctf_server/types/__init__.py | 8 +++++ paradigmctf.py/requirements.txt | 1 - paradigmctf.py/starknet/anvil.py | 17 +++++++--- 5 files changed, 54 insertions(+), 22 deletions(-) diff --git a/paradigmctf.py/ctf_server/backends/backend.py b/paradigmctf.py/ctf_server/backends/backend.py index 16540da..7c3d14b 100644 --- a/paradigmctf.py/ctf_server/backends/backend.py +++ b/paradigmctf.py/ctf_server/backends/backend.py @@ -18,9 +18,8 @@ from eth_account import Account from eth_account.hdaccount import key_from_seed, seed_from_mnemonic from foundry.anvil import anvil_setBalance -from starknet.anvil import starknet_setBalance +from starknet.anvil import starknet_setBalance, starknet_getVersion from web3 import Web3 -from starknet_py.net.full_node_client import FullNodeClient class InstanceExists(Exception): @@ -100,10 +99,14 @@ def _prepare_node(self, args: LaunchAnvilInstanceArgs, web3: Web3): hex(int(args.get("balance", DEFAULT_BALANCE) * 10**18)), ) - def _prepare_node_starknet(self, args: LaunchAnvilInstanceArgs, web3: FullNodeClient): - while type(web3.get_chain_id_sync()) != str: - time.sleep(0.1) - continue + def _prepare_node_starknet(self, args: LaunchAnvilInstanceArgs, web3: Web3): + while True: + try: + starknet_getVersion(web3) + break + except: + time.sleep(0.1) + continue for i in range(args.get("accounts", DEFAULT_ACCOUNTS)): starknet_setBalance( @@ -114,4 +117,4 @@ def _prepare_node_starknet(self, args: LaunchAnvilInstanceArgs, web3: FullNodeCl i, ).address, int(args.get("balance", DEFAULT_BALANCE) * 10**18), - ) + ) \ No newline at end of file diff --git a/paradigmctf.py/ctf_server/backends/docker_backend.py b/paradigmctf.py/ctf_server/backends/docker_backend.py index 34dfea8..36b819b 100644 --- a/paradigmctf.py/ctf_server/backends/docker_backend.py +++ b/paradigmctf.py/ctf_server/backends/docker_backend.py @@ -12,6 +12,7 @@ InstanceInfo, UserData, format_anvil_args, + format_starknet_args ) from docker.errors import APIError, NotFound from docker.models.containers import Container @@ -36,13 +37,15 @@ def _launch_instance_impl(self, request: CreateInstanceRequest) -> UserData: anvil_containers: Dict[str, Container] = {} for anvil_id, anvil_args in request["anvil_instances"].items(): - print(request) if request["type"] == "starknet": anvil_containers[anvil_id] = self.__client.containers.run( name=f"{instance_id}-{anvil_id}", image=anvil_args.get("image", "shardlabs/starknet-devnet-rs"), network="paradigmctf", - entrypoint=["tini", "--", "starknet-devnet", "--host", "0.0.0.0", "--port", "8545"], + entrypoint=["tini", "--", "starknet-devnet"] + [ + shlex.quote(str(v)) + for v in format_starknet_args(anvil_args, anvil_id) + ], restart_policy={"Name": "always"}, detach=True, mounts=[ @@ -97,14 +100,24 @@ def _launch_instance_impl(self, request: CreateInstanceRequest) -> UserData: "port": 8545, } - self._prepare_node( - request["anvil_instances"][anvil_id], - Web3( - Web3.HTTPProvider( - f"http://{anvil_instances[anvil_id]['ip']}:{anvil_instances[anvil_id]['port']}" - ) - ), - ) + url = f"http://{anvil_instances[anvil_id]['ip']}:{anvil_instances[anvil_id]['port']}" + + logging.info("url %s %s", url, type(url)) + + if request["type"] == "starknet": + self._prepare_node_starknet( + request["anvil_instances"][anvil_id], + Web3( + Web3.HTTPProvider(url) + ), + ) + else: + self._prepare_node( + request["anvil_instances"][anvil_id], + Web3( + Web3.HTTPProvider(url) + ), + ) daemon_instances = {} for daemon_id, daemon_container in daemon_containers.items(): diff --git a/paradigmctf.py/ctf_server/types/__init__.py b/paradigmctf.py/ctf_server/types/__init__.py index 26b56c5..9fdfb17 100644 --- a/paradigmctf.py/ctf_server/types/__init__.py +++ b/paradigmctf.py/ctf_server/types/__init__.py @@ -64,6 +64,14 @@ def format_anvil_args(args: LaunchAnvilInstanceArgs, anvil_id: str, port: int = return cmd_args +def format_starknet_args(args: LaunchAnvilInstanceArgs, anvil_id: str, port: int = 8545) -> List[str]: + cmd_args = [] + cmd_args += ["--host", "0.0.0.0"] + cmd_args += ["--port", str(port)] + cmd_args += ["--accounts", "0"] + + return cmd_args + class DaemonInstanceArgs(TypedDict): image: str diff --git a/paradigmctf.py/requirements.txt b/paradigmctf.py/requirements.txt index a46bab8..bb6f249 100644 --- a/paradigmctf.py/requirements.txt +++ b/paradigmctf.py/requirements.txt @@ -50,7 +50,6 @@ multidict==6.0.4 mypy-extensions==1.0.0 oauthlib==3.2.2 packaging==23.2 -paradigmctf.py==1.0.0 paramiko==3.3.1 parsimonious==0.9.0 plumbum==1.8.2 diff --git a/paradigmctf.py/starknet/anvil.py b/paradigmctf.py/starknet/anvil.py index b022ae9..a5932ea 100644 --- a/paradigmctf.py/starknet/anvil.py +++ b/paradigmctf.py/starknet/anvil.py @@ -1,14 +1,23 @@ -from starknet_py.net.full_node_client import FullNodeClient import requests +from web3 import Web3 +from web3.types import RPCResponse + + +def check_error(resp: RPCResponse): + if "error" in resp: + raise Exception("rpc exception", resp["error"]) + + +def starknet_getVersion(web3: Web3): + check_error(web3.provider.make_request("starknet_specVersion", [])) def starknet_setBalance( - web3: FullNodeClient, + web3: Web3, addr: str, balance: int, ): - requests.post(web3.url + '/mint', json = { + requests.post(web3.provider.endpoint_uri + '/mint', json={ 'address': addr, 'amount': balance }) - From 5f24cb7b6d548fa3fcdeee28210f591351973cff Mon Sep 17 00:00:00 2001 From: cairo <101215230+cairoeth@users.noreply.github.com> Date: Fri, 8 Mar 2024 00:03:37 -0800 Subject: [PATCH 04/10] =?UTF-8?q?=E2=9E=96=20Remove=20not=20needed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- paradigmctf.py/ctf_server/backends/backend.py | 2 +- paradigmctf.py/ctf_server/backends/docker_backend.py | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/paradigmctf.py/ctf_server/backends/backend.py b/paradigmctf.py/ctf_server/backends/backend.py index 7c3d14b..6c81b3e 100644 --- a/paradigmctf.py/ctf_server/backends/backend.py +++ b/paradigmctf.py/ctf_server/backends/backend.py @@ -106,9 +106,9 @@ def _prepare_node_starknet(self, args: LaunchAnvilInstanceArgs, web3: Web3): break except: time.sleep(0.1) - continue for i in range(args.get("accounts", DEFAULT_ACCOUNTS)): + # TODO: use starknet address instaed of normal evm one starknet_setBalance( web3, self.__derive_account( diff --git a/paradigmctf.py/ctf_server/backends/docker_backend.py b/paradigmctf.py/ctf_server/backends/docker_backend.py index 36b819b..9cfea00 100644 --- a/paradigmctf.py/ctf_server/backends/docker_backend.py +++ b/paradigmctf.py/ctf_server/backends/docker_backend.py @@ -102,8 +102,6 @@ def _launch_instance_impl(self, request: CreateInstanceRequest) -> UserData: url = f"http://{anvil_instances[anvil_id]['ip']}:{anvil_instances[anvil_id]['port']}" - logging.info("url %s %s", url, type(url)) - if request["type"] == "starknet": self._prepare_node_starknet( request["anvil_instances"][anvil_id], From a866e654f59e7ab1c7d63badc968319d12ba703b Mon Sep 17 00:00:00 2001 From: cairo <101215230+cairoeth@users.noreply.github.com> Date: Fri, 8 Mar 2024 11:58:27 -0800 Subject: [PATCH 05/10] =?UTF-8?q?=E2=9C=A8=20cairo=20challenge=20deployer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- paradigmctf.py/ctf_launchers/launcher.py | 9 +++-- paradigmctf.py/ctf_launchers/utils.py | 45 ++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/paradigmctf.py/ctf_launchers/launcher.py b/paradigmctf.py/ctf_launchers/launcher.py index 5066929..d1b9359 100644 --- a/paradigmctf.py/ctf_launchers/launcher.py +++ b/paradigmctf.py/ctf_launchers/launcher.py @@ -150,9 +150,12 @@ def kill_instance(self) -> int: def deploy(self, user_data: UserData, mnemonic: str) -> str: web3 = get_privileged_web3(user_data, "main") - return deploy( - web3, self.project_location, mnemonic, env=self.get_deployment_args(user_data) - ) + if self.type == "starknet": + return self.deploy_cairo(web3, self.project_location, mnemonic, env=self.get_deployment_args(user_data)) + else: + return deploy( + web3, self.project_location, mnemonic, env=self.get_deployment_args(user_data) + ) def get_deployment_args(self, user_data: UserData) -> Dict[str, str]: return {} diff --git a/paradigmctf.py/ctf_launchers/utils.py b/paradigmctf.py/ctf_launchers/utils.py index fb9f4b5..37371a1 100644 --- a/paradigmctf.py/ctf_launchers/utils.py +++ b/paradigmctf.py/ctf_launchers/utils.py @@ -69,6 +69,51 @@ def deploy( return result +def deploy_cairo( + web3: Web3, + project_location: str, + mnemonic: str, + deploy_script: str = "scripts/deploy.ts", + env: Dict = {}, +) -> str: + rfd, wfd = os.pipe2(os.O_NONBLOCK) + + proc = subprocess.Popen( + args=[ + "npx", + "hardhat", + "run", + deploy_script, + ], + env={ + "RPC_URL": web3.provider.endpoint_uri, + "PRIVATE_KEY": "0x", + "ACCOUNT_ADDRESS": "0x", + } + | env, + pass_fds=[wfd], + cwd=project_location, + text=True, + encoding="utf8", + stdin=subprocess.DEVNULL, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + ) + stdout, stderr = proc.communicate() + + if proc.returncode != 0: + print(stdout) + print(stderr) + raise Exception("script failed to run") + + result = os.read(rfd, 256).decode("utf8") + + os.close(rfd) + os.close(wfd) + + return result + + def anvil_setCodeFromFile( web3: Web3, addr: str, From 7ba9811b64fcdd44748c5c8849e4268a4e573764 Mon Sep 17 00:00:00 2001 From: cairo <101215230+cairoeth@users.noreply.github.com> Date: Fri, 8 Mar 2024 12:39:48 -0800 Subject: [PATCH 06/10] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20use=20generated=20ac?= =?UTF-8?q?counts=20from=20node?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- paradigmctf.py/ctf_launchers/launcher.py | 62 +++++++++++++++---- paradigmctf.py/ctf_launchers/utils.py | 6 +- .../ctf_server/backends/docker_backend.py | 13 ++-- 3 files changed, 61 insertions(+), 20 deletions(-) diff --git a/paradigmctf.py/ctf_launchers/launcher.py b/paradigmctf.py/ctf_launchers/launcher.py index d1b9359..07faccb 100644 --- a/paradigmctf.py/ctf_launchers/launcher.py +++ b/paradigmctf.py/ctf_launchers/launcher.py @@ -1,8 +1,11 @@ import abc import os import traceback +import random from dataclasses import dataclass from typing import Callable, Dict, List +import requests +import json import requests from ctf_launchers.team_provider import TeamProvider @@ -49,7 +52,14 @@ def run(self): if not self.team: exit(1) - self.mnemonic = generate_mnemonic(12, lang="english") + if self.type == "starknet": + random_generator = random.Random() + + deployer_private_key = random_generator.getrandbits(128) + + self.mnemonic = str(deployer_private_key) + else: + self.mnemonic = generate_mnemonic(12, lang="english") for i, action in enumerate(self._actions): print(f"{i+1} - {action.name}") @@ -119,7 +129,16 @@ def launch_instance(self) -> int: user_data = body["data"] print("deploying challenge...") - challenge_addr = self.deploy(user_data, self.mnemonic) + + if self.type == "starknet": + web3 = get_privileged_web3(user_data, "main") + credentials = self.get_credentials(web3.provider.endpoint_uri) + + challenge_addr = self.deploy_cairo(user_data, credentials) + priv_key = credentials[1][1] + else: + challenge_addr = self.deploy(user_data, self.mnemonic) + priv_key = get_player_account(self.mnemonic).key.hex() self.update_metadata( {"mnemonic": self.mnemonic, "challenge_address": challenge_addr} @@ -134,14 +153,17 @@ def launch_instance(self) -> int: print(f"rpc endpoints:") for id in user_data["anvil_instances"]: print(f" - {PUBLIC_HOST}/{user_data['external_id']}/{id}") - print(f" - {PUBLIC_WEBSOCKET_HOST}/{user_data['external_id']}/{id}/ws") + print( + f" - {PUBLIC_WEBSOCKET_HOST}/{user_data['external_id']}/{id}/ws") - print(f"private key: {get_player_account(self.mnemonic).key.hex()}") + print( + f"private key: {priv_key}") print(f"challenge contract: {challenge_addr}") return 0 def kill_instance(self) -> int: - resp = requests.delete(f"{ORCHESTRATOR_HOST}/instances/${self.get_instance_id()}") + resp = requests.delete( + f"{ORCHESTRATOR_HOST}/instances/${self.get_instance_id()}") body = resp.json() print(body["message"]) @@ -150,12 +172,30 @@ def kill_instance(self) -> int: def deploy(self, user_data: UserData, mnemonic: str) -> str: web3 = get_privileged_web3(user_data, "main") - if self.type == "starknet": - return self.deploy_cairo(web3, self.project_location, mnemonic, env=self.get_deployment_args(user_data)) - else: - return deploy( - web3, self.project_location, mnemonic, env=self.get_deployment_args(user_data) - ) + return deploy( + web3, self.project_location, mnemonic, env=self.get_deployment_args( + user_data) + ) + + def deploy_cairo(self, user_data: UserData, credentials: list) -> str: + web3 = get_privileged_web3(user_data, "main") + + return self.deploy_cairo(web3, self.project_location, credentials, env=self.get_deployment_args(user_data)) + def get_deployment_args(self, user_data: UserData) -> Dict[str, str]: return {} + + def get_credentials(url: str) -> list: + x = json.loads(requests.get(url + '/predeployed_accounts').text) + + system = [] + player = [] + + system.append(x[0]['address']) + system.append(x[0]['private_key']) + + player.append(x[1]['address']) + player.append(x[1]['private_key']) + + return [system, player] diff --git a/paradigmctf.py/ctf_launchers/utils.py b/paradigmctf.py/ctf_launchers/utils.py index 37371a1..ec00c41 100644 --- a/paradigmctf.py/ctf_launchers/utils.py +++ b/paradigmctf.py/ctf_launchers/utils.py @@ -72,7 +72,7 @@ def deploy( def deploy_cairo( web3: Web3, project_location: str, - mnemonic: str, + credentials: list, deploy_script: str = "scripts/deploy.ts", env: Dict = {}, ) -> str: @@ -87,8 +87,8 @@ def deploy_cairo( ], env={ "RPC_URL": web3.provider.endpoint_uri, - "PRIVATE_KEY": "0x", - "ACCOUNT_ADDRESS": "0x", + "PRIVATE_KEY": credentials[0][1], + "ACCOUNT_ADDRESS": credentials[0][0], } | env, pass_fds=[wfd], diff --git a/paradigmctf.py/ctf_server/backends/docker_backend.py b/paradigmctf.py/ctf_server/backends/docker_backend.py index 9cfea00..bbceef4 100644 --- a/paradigmctf.py/ctf_server/backends/docker_backend.py +++ b/paradigmctf.py/ctf_server/backends/docker_backend.py @@ -103,12 +103,13 @@ def _launch_instance_impl(self, request: CreateInstanceRequest) -> UserData: url = f"http://{anvil_instances[anvil_id]['ip']}:{anvil_instances[anvil_id]['port']}" if request["type"] == "starknet": - self._prepare_node_starknet( - request["anvil_instances"][anvil_id], - Web3( - Web3.HTTPProvider(url) - ), - ) + # self._prepare_node_starknet( + # request["anvil_instances"][anvil_id], + # Web3( + # Web3.HTTPProvider(url) + # ), + # ) + pass else: self._prepare_node( request["anvil_instances"][anvil_id], From b3e7de6920c6b009b4a6985bfb3abf93fd1d0b7a Mon Sep 17 00:00:00 2001 From: cairo <101215230+cairoeth@users.noreply.github.com> Date: Fri, 8 Mar 2024 18:15:54 -0800 Subject: [PATCH 07/10] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20use=20starknet=20gen?= =?UTF-8?q?erated=20accounts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- paradigmctf.py/ctf_launchers/launcher.py | 26 ++++++++++------- paradigmctf.py/ctf_launchers/utils.py | 2 +- paradigmctf.py/ctf_server/backends/backend.py | 16 ++--------- .../ctf_server/backends/docker_backend.py | 14 +++++----- paradigmctf.py/ctf_server/types/__init__.py | 28 +------------------ 5 files changed, 28 insertions(+), 58 deletions(-) diff --git a/paradigmctf.py/ctf_launchers/launcher.py b/paradigmctf.py/ctf_launchers/launcher.py index 07faccb..cfd42ce 100644 --- a/paradigmctf.py/ctf_launchers/launcher.py +++ b/paradigmctf.py/ctf_launchers/launcher.py @@ -6,10 +6,11 @@ from typing import Callable, Dict, List import requests import json +import time import requests from ctf_launchers.team_provider import TeamProvider -from ctf_launchers.utils import deploy, http_url_to_ws +from ctf_launchers.utils import deploy, deploy_cairo, http_url_to_ws from ctf_server.types import ( CreateInstanceRequest, DaemonInstanceArgs, @@ -131,9 +132,13 @@ def launch_instance(self) -> int: print("deploying challenge...") if self.type == "starknet": + print('calling predeployed_accounts...') web3 = get_privileged_web3(user_data, "main") + credentials = self.get_credentials(web3.provider.endpoint_uri) + print('calling deploy script...') + challenge_addr = self.deploy_cairo(user_data, credentials) priv_key = credentials[1][1] else: @@ -148,7 +153,7 @@ def launch_instance(self) -> int: print() print(f"your private blockchain has been set up") - print(f"it will automatically terminate in {TIMEOUT} minutes") + print(f"it will automatically terminate in {TIMEOUT/60} minutes") print(f"---") print(f"rpc endpoints:") for id in user_data["anvil_instances"]: @@ -163,7 +168,7 @@ def launch_instance(self) -> int: def kill_instance(self) -> int: resp = requests.delete( - f"{ORCHESTRATOR_HOST}/instances/${self.get_instance_id()}") + f"{ORCHESTRATOR_HOST}/instances/{self.get_instance_id()}") body = resp.json() print(body["message"]) @@ -180,22 +185,23 @@ def deploy(self, user_data: UserData, mnemonic: str) -> str: def deploy_cairo(self, user_data: UserData, credentials: list) -> str: web3 = get_privileged_web3(user_data, "main") - return self.deploy_cairo(web3, self.project_location, credentials, env=self.get_deployment_args(user_data)) + return deploy_cairo(web3, self.project_location, credentials, env=self.get_deployment_args(user_data)) def get_deployment_args(self, user_data: UserData) -> Dict[str, str]: return {} - def get_credentials(url: str) -> list: - x = json.loads(requests.get(url + '/predeployed_accounts').text) + def get_credentials(self, url: str) -> list: + x = requests.get(url + '/predeployed_accounts') + data = json.loads(x.text) system = [] player = [] - system.append(x[0]['address']) - system.append(x[0]['private_key']) + system.append(data[0]['address']) + system.append(data[0]['private_key']) - player.append(x[1]['address']) - player.append(x[1]['private_key']) + player.append(data[1]['address']) + player.append(data[1]['private_key']) return [system, player] diff --git a/paradigmctf.py/ctf_launchers/utils.py b/paradigmctf.py/ctf_launchers/utils.py index ec00c41..16fafd2 100644 --- a/paradigmctf.py/ctf_launchers/utils.py +++ b/paradigmctf.py/ctf_launchers/utils.py @@ -86,7 +86,7 @@ def deploy_cairo( deploy_script, ], env={ - "RPC_URL": web3.provider.endpoint_uri, + "RPC_URL": web3.provider.endpoint_uri + "/rpc", "PRIVATE_KEY": credentials[0][1], "ACCOUNT_ADDRESS": credentials[0][0], } diff --git a/paradigmctf.py/ctf_server/backends/backend.py b/paradigmctf.py/ctf_server/backends/backend.py index 6c81b3e..dafa07f 100644 --- a/paradigmctf.py/ctf_server/backends/backend.py +++ b/paradigmctf.py/ctf_server/backends/backend.py @@ -4,6 +4,8 @@ import string import time from threading import Thread +import requests +import json from ctf_server.databases.database import Database from ctf_server.types import ( @@ -105,16 +107,4 @@ def _prepare_node_starknet(self, args: LaunchAnvilInstanceArgs, web3: Web3): starknet_getVersion(web3) break except: - time.sleep(0.1) - - for i in range(args.get("accounts", DEFAULT_ACCOUNTS)): - # TODO: use starknet address instaed of normal evm one - starknet_setBalance( - web3, - self.__derive_account( - args.get("derivation_path", DEFAULT_DERIVATION_PATH), - args.get("mnemonic", DEFAULT_MNEMONIC), - i, - ).address, - int(args.get("balance", DEFAULT_BALANCE) * 10**18), - ) \ No newline at end of file + time.sleep(0.1) \ No newline at end of file diff --git a/paradigmctf.py/ctf_server/backends/docker_backend.py b/paradigmctf.py/ctf_server/backends/docker_backend.py index bbceef4..b9e82e1 100644 --- a/paradigmctf.py/ctf_server/backends/docker_backend.py +++ b/paradigmctf.py/ctf_server/backends/docker_backend.py @@ -3,6 +3,7 @@ import shlex import time from typing import Dict, List +import requests import docker from ctf_server.databases.database import Database @@ -103,13 +104,12 @@ def _launch_instance_impl(self, request: CreateInstanceRequest) -> UserData: url = f"http://{anvil_instances[anvil_id]['ip']}:{anvil_instances[anvil_id]['port']}" if request["type"] == "starknet": - # self._prepare_node_starknet( - # request["anvil_instances"][anvil_id], - # Web3( - # Web3.HTTPProvider(url) - # ), - # ) - pass + self._prepare_node_starknet( + request["anvil_instances"][anvil_id], + Web3( + Web3.HTTPProvider(url) + ), + ) else: self._prepare_node( request["anvil_instances"][anvil_id], diff --git a/paradigmctf.py/ctf_server/types/__init__.py b/paradigmctf.py/ctf_server/types/__init__.py index 9fdfb17..afe50bb 100644 --- a/paradigmctf.py/ctf_server/types/__init__.py +++ b/paradigmctf.py/ctf_server/types/__init__.py @@ -68,7 +68,7 @@ def format_starknet_args(args: LaunchAnvilInstanceArgs, anvil_id: str, port: int cmd_args = [] cmd_args += ["--host", "0.0.0.0"] cmd_args += ["--port", str(port)] - cmd_args += ["--accounts", "0"] + cmd_args += ["--accounts", "2"] return cmd_args @@ -110,32 +110,6 @@ class UserData(TypedDict): daemon_instances: Dict[str, InstanceInfo] metadata: Dict - # def get_privileged_account(self, offset: int) -> LocalAccount: - # seed = seed_from_mnemonic(self.mnemonic, "") - # private_key = key_from_seed(seed, f"m/44'/60'/0'/0/{offset}") - - # return Account.from_key(private_key) - - # def get_player_account(self) -> LocalAccount: - # return self.get_privileged_account(0) - - # def get_system_account(self) -> LocalAccount: - # return self.get_privileged_account(1) - - # def get_additional_account(self, offset: int) -> LocalAccount: - # return self.get_privileged_account(offset + 2) - - # def get_privileged_web3(self, id: str) -> Web3: - # return Web3(Web3.HTTPProvider(f"http://127.0.0.1:{self.instances[id].port}")) - - # def get_unprivileged_web3(self, id: str) -> Web3: - # return Web3( - # Web3.HTTPProvider( - # f"http://127.0.0.1:8545/{self.internal_id}/{id}", - # request_kwargs={"timeout": 60}, - # ) - # ) - def get_account(mnemonic: str, offset: int) -> LocalAccount: seed = seed_from_mnemonic(mnemonic, "") From 5a7227fc3d8ba31984c1fe47bc9a78f30e333dfd Mon Sep 17 00:00:00 2001 From: cairo <101215230+cairoeth@users.noreply.github.com> Date: Fri, 8 Mar 2024 23:21:37 -0800 Subject: [PATCH 08/10] =?UTF-8?q?=E2=9C=A8=20cairo=20challenge=20deploymen?= =?UTF-8?q?t?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- paradigmctf.py/ctf_launchers/launcher.py | 18 ++++-------------- paradigmctf.py/ctf_launchers/utils.py | 13 ++++--------- paradigmctf.py/requirements.txt | 4 ++-- 3 files changed, 10 insertions(+), 25 deletions(-) diff --git a/paradigmctf.py/ctf_launchers/launcher.py b/paradigmctf.py/ctf_launchers/launcher.py index cfd42ce..2684ead 100644 --- a/paradigmctf.py/ctf_launchers/launcher.py +++ b/paradigmctf.py/ctf_launchers/launcher.py @@ -1,12 +1,10 @@ import abc import os import traceback -import random from dataclasses import dataclass from typing import Callable, Dict, List import requests import json -import time import requests from ctf_launchers.team_provider import TeamProvider @@ -53,14 +51,7 @@ def run(self): if not self.team: exit(1) - if self.type == "starknet": - random_generator = random.Random() - - deployer_private_key = random_generator.getrandbits(128) - - self.mnemonic = str(deployer_private_key) - else: - self.mnemonic = generate_mnemonic(12, lang="english") + self.mnemonic = generate_mnemonic(12, lang="english") for i, action in enumerate(self._actions): print(f"{i+1} - {action.name}") @@ -132,13 +123,10 @@ def launch_instance(self) -> int: print("deploying challenge...") if self.type == "starknet": - print('calling predeployed_accounts...') web3 = get_privileged_web3(user_data, "main") credentials = self.get_credentials(web3.provider.endpoint_uri) - print('calling deploy script...') - challenge_addr = self.deploy_cairo(user_data, credentials) priv_key = credentials[1][1] else: @@ -153,7 +141,7 @@ def launch_instance(self) -> int: print() print(f"your private blockchain has been set up") - print(f"it will automatically terminate in {TIMEOUT/60} minutes") + print(f"it will automatically terminate in {round(TIMEOUT/60)} minutes") print(f"---") print(f"rpc endpoints:") for id in user_data["anvil_instances"]: @@ -161,6 +149,8 @@ def launch_instance(self) -> int: print( f" - {PUBLIC_WEBSOCKET_HOST}/{user_data['external_id']}/{id}/ws") + if self.type == "starknet": + print(f"player address: {credentials[1][0]}") print( f"private key: {priv_key}") print(f"challenge contract: {challenge_addr}") diff --git a/paradigmctf.py/ctf_launchers/utils.py b/paradigmctf.py/ctf_launchers/utils.py index 16fafd2..bf30e41 100644 --- a/paradigmctf.py/ctf_launchers/utils.py +++ b/paradigmctf.py/ctf_launchers/utils.py @@ -73,16 +73,14 @@ def deploy_cairo( web3: Web3, project_location: str, credentials: list, - deploy_script: str = "scripts/deploy.ts", + deploy_script: str = "deploy.py", env: Dict = {}, ) -> str: rfd, wfd = os.pipe2(os.O_NONBLOCK) proc = subprocess.Popen( args=[ - "npx", - "hardhat", - "run", + "/usr/local/bin/python3", deploy_script, ], env={ @@ -106,12 +104,9 @@ def deploy_cairo( print(stderr) raise Exception("script failed to run") - result = os.read(rfd, 256).decode("utf8") + output = stdout.split('address: ') - os.close(rfd) - os.close(wfd) - - return result + return output[1] def anvil_setCodeFromFile( diff --git a/paradigmctf.py/requirements.txt b/paradigmctf.py/requirements.txt index bb6f249..877dbac 100644 --- a/paradigmctf.py/requirements.txt +++ b/paradigmctf.py/requirements.txt @@ -43,7 +43,7 @@ lru-dict==1.2.0 Mako==1.3.0 MarkupSafe==2.1.3 marshmallow==3.21.1 -marshmallow-dataclass==8.6.0 +marshmallow-dataclass==8.4.2 marshmallow-oneofschema==3.0.1 mpmath==1.3.0 multidict==6.0.4 @@ -84,7 +84,7 @@ rsa==4.9 six==1.16.0 sniffio==1.3.0 sortedcontainers==2.4.0 -starknet-py==0.20.0 +starknet-py==0.18.2 starlette==0.27.0 sympy==1.11.1 toolz==0.12.0 From 0ba92074ec33c008a1eb84adc71559fcb1cf820d Mon Sep 17 00:00:00 2001 From: cairo <101215230+cairoeth@users.noreply.github.com> Date: Sat, 9 Mar 2024 00:16:02 -0800 Subject: [PATCH 09/10] =?UTF-8?q?=F0=9F=92=A1=20solved=20check=20for=20cai?= =?UTF-8?q?ro=20challenge?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ctf_launchers/starknet_pwn_launcher.py | 39 +++++++++++-------- paradigmctf.py/ctf_launchers/utils.py | 4 +- paradigmctf.py/ctf_server/anvil_proxy.py | 2 +- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/paradigmctf.py/ctf_launchers/starknet_pwn_launcher.py b/paradigmctf.py/ctf_launchers/starknet_pwn_launcher.py index 26e7e9b..2da4957 100644 --- a/paradigmctf.py/ctf_launchers/starknet_pwn_launcher.py +++ b/paradigmctf.py/ctf_launchers/starknet_pwn_launcher.py @@ -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}") @@ -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 @@ -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 diff --git a/paradigmctf.py/ctf_launchers/utils.py b/paradigmctf.py/ctf_launchers/utils.py index bf30e41..c01d7c8 100644 --- a/paradigmctf.py/ctf_launchers/utils.py +++ b/paradigmctf.py/ctf_launchers/utils.py @@ -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( diff --git a/paradigmctf.py/ctf_server/anvil_proxy.py b/paradigmctf.py/ctf_server/anvil_proxy.py index b33a2b2..9773e4c 100644 --- a/paradigmctf.py/ctf_server/anvil_proxy.py +++ b/paradigmctf.py/ctf_server/anvil_proxy.py @@ -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", From 0c5ddd2a83f53b5ca53d49894613b2ea14e935d7 Mon Sep 17 00:00:00 2001 From: cairo <101215230+cairoeth@users.noreply.github.com> Date: Sat, 9 Mar 2024 00:25:12 -0800 Subject: [PATCH 10/10] =?UTF-8?q?=E2=9A=B0=EF=B8=8F=20Remove=20Starknet=20?= =?UTF-8?q?helper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- paradigmctf.py/ctf_server/backends/backend.py | 2 +- paradigmctf.py/starknet/anvil.py | 12 ------------ 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/paradigmctf.py/ctf_server/backends/backend.py b/paradigmctf.py/ctf_server/backends/backend.py index dafa07f..f5a0de8 100644 --- a/paradigmctf.py/ctf_server/backends/backend.py +++ b/paradigmctf.py/ctf_server/backends/backend.py @@ -20,7 +20,7 @@ from eth_account import Account from eth_account.hdaccount import key_from_seed, seed_from_mnemonic from foundry.anvil import anvil_setBalance -from starknet.anvil import starknet_setBalance, starknet_getVersion +from starknet.anvil import starknet_getVersion from web3 import Web3 diff --git a/paradigmctf.py/starknet/anvil.py b/paradigmctf.py/starknet/anvil.py index a5932ea..df1daf9 100644 --- a/paradigmctf.py/starknet/anvil.py +++ b/paradigmctf.py/starknet/anvil.py @@ -1,4 +1,3 @@ -import requests from web3 import Web3 from web3.types import RPCResponse @@ -10,14 +9,3 @@ def check_error(resp: RPCResponse): def starknet_getVersion(web3: Web3): check_error(web3.provider.make_request("starknet_specVersion", [])) - - -def starknet_setBalance( - web3: Web3, - addr: str, - balance: int, -): - requests.post(web3.provider.endpoint_uri + '/mint', json={ - 'address': addr, - 'amount': balance - })