Skip to content

Commit 1c7de29

Browse files
authored
feat: Adding 4788 deployment (#275)
1 parent df27a8e commit 1c7de29

File tree

6 files changed

+182
-13
lines changed

6 files changed

+182
-13
lines changed

README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -507,15 +507,17 @@ This package comes with [seven prefunded keys for testing](https://github.com/ku
507507

508508
Here's a table of where the keys are used
509509

510-
| Account Index| Component Used In | Private Key Used | Public Key Used | Comment |
511-
|----------------|---------------------|------------------|-----------------|----------------------------|
512-
| 3 | transaction_spammer || | To spam transactions with |
513-
| 0 | mev_flood || | As the admin_key |
514-
| 2 | mev_flood || | As the user_key |
515-
| 0 | mev_custom_flood | || As the receiver of balance |
516-
| 6 | mev_custom_flood || | As the sender of balance |
517-
| 1 | blob_spammer || | As the sender of blobs |
510+
| Account Index | Component Used In | Private Key Used | Public Key Used | Comment |
511+
|---------------|---------------------|------------------|-----------------|----------------------------|
512+
| 0 | mev_flood || | As the admin_key |
513+
| 0 | mev_custom_flood | || As the receiver of balance |
514+
| 1 | blob_spammer || | As the sender of blobs |
515+
| 2 | mev_flood || | As the user_key |
516+
| 3 | transaction_spammer || | To spam transactions with |
518517
| 4 | goomy_blob || | As the sender of blobs |
518+
| 5 | eip4788_deployment || | As contract deployer |
519+
| 6 | mev_custom_flood || | As the sender of balance |
520+
519521

520522
## Developing On This Package
521523

main.star

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ mev_flood_module = import_module("./src/mev_flood/mev_flood_launcher.star")
2929
mev_custom_flood_module = import_module(
3030
"./src/mev_custom_flood/mev_custom_flood_launcher.star"
3131
)
32-
32+
eip4788_deployment_module = import_module(
33+
"./src/eip4788_deployment/eip4788_deployment_launcher.star"
34+
)
3335
GRAFANA_USER = "admin"
3436
GRAFANA_PASSWORD = "admin"
3537
GRAFANA_DASHBOARD_PATH_URL = "/d/QdTOwy-nz/eth2-merge-kurtosis-module-dashboard?orgId=1"
@@ -94,6 +96,17 @@ def run(plan, args={}):
9496
all_el_client_contexts.append(participant.el_client_context)
9597
all_cl_client_contexts.append(participant.cl_client_context)
9698

99+
if network_params.deneb_fork_epoch != 0:
100+
plan.print("Launching 4788 contract deployer")
101+
el_uri = "http://{0}:{1}".format(
102+
all_el_client_contexts[0].ip_addr, all_el_client_contexts[0].rpc_port_num
103+
)
104+
eip4788_deployment_module.deploy_eip4788_contract_in_background(
105+
plan,
106+
genesis_constants.PRE_FUNDED_ACCOUNTS[5].private_key,
107+
el_uri,
108+
)
109+
97110
mev_endpoints = []
98111
# passed external relays get priority
99112
# perhaps add mev_type External or remove this
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
PYTHON_IMAGE = "python:3.11-alpine"
2+
EIP4788_DEPLOYMENT_SERVICE_NAME = "eip4788-contract-deployment"
3+
4+
5+
def deploy_eip4788_contract_in_background(plan, sender_key, el_uri):
6+
sender_script = plan.upload_files("./sender.py")
7+
8+
plan.add_service(
9+
name=EIP4788_DEPLOYMENT_SERVICE_NAME,
10+
config=ServiceConfig(
11+
image=PYTHON_IMAGE,
12+
files={"/tmp": sender_script},
13+
cmd=["/bin/sh", "-c", "touch /tmp/sender.log && tail -f /tmp/sender.log"],
14+
env_vars={
15+
"SENDER_PRIVATE_KEY": sender_key,
16+
"EL_RPC_URI": el_uri,
17+
},
18+
),
19+
)
20+
21+
plan.exec(
22+
service_name=EIP4788_DEPLOYMENT_SERVICE_NAME,
23+
recipe=ExecRecipe(["pip", "install", "web3"]),
24+
)
25+
26+
plan.exec(
27+
service_name=EIP4788_DEPLOYMENT_SERVICE_NAME,
28+
recipe=ExecRecipe(
29+
["/bin/sh", "-c", "nohup python /tmp/sender.py > /dev/null 2>&1 &"]
30+
),
31+
)

src/eip4788_deployment/sender.py

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
"""
2+
this script deploys the contract used by eip4788. It has been presigned and the contract uses a deterministic deployment.
3+
4+
"""
5+
6+
from web3 import Web3
7+
from web3.middleware import construct_sign_and_send_raw_middleware
8+
import os
9+
import time
10+
import logging
11+
from decimal import Decimal
12+
13+
VALUE_TO_SEND = 0x9184
14+
15+
logging.basicConfig(filename="/tmp/sender.log",
16+
filemode='a',
17+
format='%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s',
18+
datefmt='%H:%M:%S',
19+
level=logging.INFO)
20+
21+
22+
def eip4788_deployment():
23+
# this is the 5th prefunded address
24+
sender = os.getenv("SENDER_PRIVATE_KEY", "7da08f856b5956d40a72968f93396f6acff17193f013e8053f6fbb6c08c194d6")
25+
# this is the 4788 presigned contract deployer
26+
receiver = "0x0B799C86a49DEeb90402691F1041aa3AF2d3C875"
27+
signed_4788_deployment_tx = os.getenv("SIGNED_4788_DEPLOYMENT_TX", "f8838085e8d4a510008303d0908080b86a60618060095f395ff33373fffffffffffffffffffffffffffffffffffffffe14604d57602036146024575f5ffd5b5f35801560495762001fff810690815414603c575f5ffd5b62001fff01545f5260205ff35b5f5ffd5b62001fff42064281555f359062001fff0155001b820539851b9b6eb1f0")
28+
el_uri = os.getenv("EL_RPC_URI", 'http://0.0.0.0:53913')
29+
logging.info(f"Using sender {sender} receiver {receiver} and el_uri {el_uri}")
30+
31+
w3 = Web3(Web3.HTTPProvider(el_uri))
32+
# sleep for 10s before checking again
33+
time.sleep(10)
34+
35+
# Check if the chain has started before submitting transactions
36+
block = w3.eth.get_block('latest')
37+
38+
logging.info(f"Latest block number: {block.number}")
39+
if block.number >1:
40+
logging.info("Chain has started, proceeding with Funding")
41+
# Import sender account
42+
sender_account = w3.eth.account.from_key(sender)
43+
# Prepare to Construct and sign transaction
44+
w3.middleware_onion.add(construct_sign_and_send_raw_middleware(sender_account))
45+
46+
# Prepare funding transaction
47+
logging.info("Preparing funding tx")
48+
transaction = {
49+
"from": sender_account.address,
50+
"to": receiver,
51+
"value": w3.to_wei(Decimal('1000.0'), 'ether'), # Sending 1000 Ether
52+
"gasPrice": w3.eth.gas_price,
53+
'nonce': w3.eth.get_transaction_count(sender_account.address)
54+
}
55+
56+
# Estimate gas
57+
logging.info("Estimating gas")
58+
estimated_gas = w3.eth.estimate_gas(transaction)
59+
60+
# Set gas value
61+
transaction["gas"] = estimated_gas
62+
63+
# Send transaction
64+
logging.debug(f"Sending deployment tx: {transaction}")
65+
tx_hash = w3.eth.send_transaction(transaction)
66+
67+
time.sleep(10)
68+
# Wait for the transaction to be mined
69+
funding_tx = w3.eth.get_transaction(tx_hash)
70+
logging.debug(f"Funding Txhash: {tx_hash.hex()}")
71+
logging.info(f"Genesis funder Balance: {w3.eth.get_balance(sender_account.address)}")
72+
logging.info(f"4788 deployer Balance: {w3.eth.get_balance(receiver)}")
73+
74+
if funding_tx["from"] == sender_account.address:
75+
logging.info("Funding tx mined successfully")
76+
logging.info("Deploying signed tx")
77+
# Prepare deployment transaction
78+
deployment_tx_hash = w3.eth.send_raw_transaction(signed_4788_deployment_tx)
79+
80+
# Sleep before checking
81+
time.sleep(10)
82+
deployment_tx = w3.eth.get_transaction(deployment_tx_hash)
83+
logging.debug(f"Deployment Txhash: {deployment_tx.hash.hex()}")
84+
85+
# Sleep before checking
86+
time.sleep(10)
87+
88+
logging.info(f"4788 deployer Balance: {w3.eth.get_balance(receiver)}")
89+
assert deployment_tx["from"] == receiver
90+
91+
# Check if contract has been deployed
92+
eip4788_code = w3.eth.get_code('0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02')
93+
if eip4788_code != "":
94+
logging.info(f"Contract deployed: {eip4788_code.hex()}")
95+
logging.info("Deployment tx mined successfully")
96+
97+
# Exit script
98+
return True
99+
else:
100+
logging.info("Deployment failed, restarting script")
101+
return False
102+
else:
103+
logging.info("Funding failed, restarting script")
104+
return False
105+
else:
106+
logging.info("Chain has not started, restarting script")
107+
return False
108+
109+
def run_till_deployed():
110+
deployment_status = False
111+
while deployment_status is False:
112+
try:
113+
deployment_status = eip4788_deployment()
114+
except Exception as e:
115+
logging.error(e)
116+
logging.error("restarting deployment as previous one failed")
117+
118+
119+
120+
if __name__ == "__main__":
121+
run_till_deployed()
122+
logging.info("Deployment complete, exiting script")

src/mev_custom_flood/mev_custom_flood_launcher.star

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
PYTHON_IMAGE = "python:3.11-alpine"
2-
CUSTOM_FLOOD_SREVICE_NAME = "mev-custom-flood"
2+
CUSTOM_FLOOD_SERVICE_NAME = "mev-custom-flood"
33

44

55
def spam_in_background(plan, sender_key, receiver_key, el_uri):
66
sender_script = plan.upload_files("./sender.py")
77

88
plan.add_service(
9-
name=CUSTOM_FLOOD_SREVICE_NAME,
9+
name=CUSTOM_FLOOD_SERVICE_NAME,
1010
config=ServiceConfig(
1111
image=PYTHON_IMAGE,
1212
files={"/tmp": sender_script},
@@ -20,12 +20,12 @@ def spam_in_background(plan, sender_key, receiver_key, el_uri):
2020
)
2121

2222
plan.exec(
23-
service_name=CUSTOM_FLOOD_SREVICE_NAME,
23+
service_name=CUSTOM_FLOOD_SERVICE_NAME,
2424
recipe=ExecRecipe(["pip", "install", "web3"]),
2525
)
2626

2727
plan.exec(
28-
service_name=CUSTOM_FLOOD_SREVICE_NAME,
28+
service_name=CUSTOM_FLOOD_SERVICE_NAME,
2929
recipe=ExecRecipe(
3030
["/bin/sh", "-c", "nohup python /tmp/sender.py > /dev/null 2>&1 &"]
3131
),

src/mev_custom_flood/sender.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def flood():
4242
"to": receiver,
4343
"data": "0xabcd",
4444
"gasPrice": w3.eth.gas_price,
45+
"nonce": w3.eth.get_transaction_count(sender_account.address)
4546
}
4647

4748
estimated_gas = w3.eth.estimate_gas(transaction)

0 commit comments

Comments
 (0)