Skip to content

Commit

Permalink
✨ nitro initialize contract with cast
Browse files Browse the repository at this point in the history
  • Loading branch information
cairoeth committed Mar 11, 2024
1 parent 1d2b254 commit 480b8b6
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 3 deletions.
14 changes: 12 additions & 2 deletions paradigmctf.py/ctf_launchers/nitro_pwn_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,15 @@ def get_flag(self) -> int:
return 0

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

(result,) = abi.decode(
["bool"],
web3.eth.call(
{
"to": addr,
"data": web3.keccak(text="isSolved()")[:4],
}
),
)
return result
52 changes: 51 additions & 1 deletion paradigmctf.py/ctf_launchers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@ def deploy_no_impersonate(
web3: Web3,
project_location: str,
mnemonic: str,
token: str,
deploy_script: str = "script/Deploy.s.sol:Deploy",
env: Dict = {},
env: Dict = {}
) -> str:
rfd, wfd = os.pipe2(os.O_NONBLOCK)

Expand Down Expand Up @@ -158,9 +159,57 @@ def deploy_no_impersonate(
os.close(rfd)
os.close(wfd)

# cast_initialize(web3, project_location, token, result)

return result


def cast_initialize(
web3: Web3,
project_location: str,
token: str,
entrypoint: str
) -> str:
rfd, wfd = os.pipe2(os.O_NONBLOCK)

proc = subprocess.Popen(
args=[
"/opt/foundry/bin/cast",
"send",
token,
'"initialize(address)"',
entrypoint,
"--rpc-url",
web3.provider.endpoint_uri,
"--private-key",
"0xb6b15c8cb491557369f3c7d2c287b053eb229daa9c22138887752191c9520659"
],
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("cast failed to run")

result = os.read(rfd, 256).decode("utf8")

os.close(rfd)
os.close(wfd)

return result





def deploy_nitro(
web3: Web3,
project_location: str,
Expand Down Expand Up @@ -212,6 +261,7 @@ def deploy_nitro(
web3,
project_location,
"",
token,
env=env,
)

Expand Down

0 comments on commit 480b8b6

Please sign in to comment.