Skip to content

Commit

Permalink
Raise if argent status is not TX_ACCEPTED_L2 (#1501)
Browse files Browse the repository at this point in the history
<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg"
height="34" align="absmiddle"
alt="Reviewable"/>](https://reviewable.io/reviews/kkrt-labs/kakarot/1501)
<!-- Reviewable:end -->
  • Loading branch information
ClementWalter authored Oct 14, 2024
1 parent bee7372 commit 31d14bf
Show file tree
Hide file tree
Showing 13 changed files with 148 additions and 72 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/cairo-zero-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ jobs:
- uses: asdf-vm/actions/install@v3
- run: asdf install
- name: Compile all the cairo files
run: make build
run: |
cp .env.example .env
make build
- name: Uploads Kakarot build artifacts
uses: actions/upload-artifact@v3
Expand Down Expand Up @@ -97,7 +99,9 @@ jobs:
- name: Run tests
env:
HYPOTHESIS_PROFILE: ci
run: make test-unit-cairo-zero
run: |
cp .env.example .env
make test-unit-cairo-zero
- name: Upload coverage report to codecov
uses: codecov/codecov-action@v3
with:
Expand Down
6 changes: 1 addition & 5 deletions deployments/starknet-mainnet/deployments.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
{
"kakarot": {
"address": "0x6ec07c9b2724d42faa654878fafe406b860d77547e65f81d83214efc0dc4ca7",
"tx": "0xb5df9733082e46f926e02d886dceabd951f80f259ec2566f3014977b19e909",
"artifact": "None"
}
"kakarot": "0x15626fc5070f7675966aac4f3a4dc5a9c721cd8df311c6d05611912e3c51c91"
}
34 changes: 34 additions & 0 deletions deployments/starknet-mainnet/kakarot_deployments.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"WETH9": {
"address": "0x7a2dee402f31632592e3c9270d4f12e450877f86",
"starknet_address": "0x560ee2d03b8d5324ab2b2633f1cc7e622670f0dd5f4339cd805f7a8c7c2954c"
},
"KakarotETH": {
"address": "0xc9c677a629aae7a149f5f0e7546394f2630e8e9e",
"starknet_address": "0x148fb0906ddab285adfca8d6cb263f2d1d80f4a5de73097fb4d6f915de37ddb"
},
"KakarotSTRK": {
"address": "0x506de97018260b95ddf3d1b4c3d795a639b04d3f",
"starknet_address": "0x5d2c7e0607e567b216d6797340a6d2abc0d2e2ed10c6e02ed59eaf938efd8ee"
},
"Coinbase": {
"address": "0x20a6338ae7c41a5f70fb8c660c8cc5b3f5f631f7",
"starknet_address": "0x61410328063dd18e8ba0dc4036b19f542898111e94f3592d5dc7a99226a0f59"
},
"Multicall3": {
"address": "0xca11bde05977b3631167028862be2a173976ca11",
"starknet_address": "0x6651e54eeedb45bc4c35afdb347087a9bf4d605c2c32059d40a53c11c58ad54"
},
"ArachnidProxy": {
"address": "0x4e59b44847b379578588920ca78fbf26c0b4956c",
"starknet_address": "0x1951616e873145d51a0e77cc6c9c3ea2d1d3cc40ec9fa226b217a06f415dd61"
},
"CreateX": {
"address": "0xba5ed099633d3b313e4d5f7bdc1305d3c28ba5ed",
"starknet_address": "0x374b73d5437a4e0f6f5350da52d937b4241d010ae419dc7093bb36294d56ddf"
},
"L2KakarotMessaging": {
"address": "0xd88b092890db8c02e0c7a838841d88f3cf4d8286",
"starknet_address": "0x1c172576798412602954fdc8024276c3e801be5352c0d3166b23765552aa879"
}
}
5 changes: 3 additions & 2 deletions deployments/starknet-mainnet/l1_addresses.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"StarknetCore": "0xc662c410C0ECf747543f5bA90660f6ABeBD9C8c4",
"StarknetVerifier": "0x47312450B3Ac8b5b8e247a6bB6d523e7605bDb60"
}
"StarknetVerifier": "0x47312450B3Ac8b5b8e247a6bB6d523e7605bDb60",
"L1KakarotMessaging": "0xd52042e28e6f726738A48497A0728Fc5977AF3F8"
}
11 changes: 5 additions & 6 deletions kakarot_scripts/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,11 @@ class ChainId(IntEnum):
f"⚠️ {prefix}_EVM_PRIVATE_KEY not set, defaulting to EVM_PRIVATE_KEY"
)
EVM_PRIVATE_KEY = os.getenv("EVM_PRIVATE_KEY")
EVM_ADDRESS = (
EVM_PRIVATE_KEY
and keys.PrivateKey(
bytes.fromhex(EVM_PRIVATE_KEY[2:])
).public_key.to_checksum_address()
)
if EVM_PRIVATE_KEY is None:
raise ValueError("EVM_PRIVATE_KEY not set")
EVM_ADDRESS = keys.PrivateKey(
bytes.fromhex(EVM_PRIVATE_KEY[2:])
).public_key.to_checksum_address()

NETWORK["account_address"] = os.environ.get(f"{prefix}_ACCOUNT_ADDRESS")
if NETWORK["account_address"] is None:
Expand Down
5 changes: 1 addition & 4 deletions kakarot_scripts/deployment/evm_deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from kakarot_scripts.utils.starknet import invoke

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)


# %%
Expand Down Expand Up @@ -109,10 +110,6 @@ async def main():
logger.error("❌ Kakarot is not deployed, exiting...")
return

if not EVM_ADDRESS:
logger.warn("⚠️ No EVM address provided, skipping EVM deployments")
return

await deploy_evm_contracts()
await execute_calls()

Expand Down
12 changes: 12 additions & 0 deletions kakarot_scripts/deployment/kakarot_deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
BLOCK_GAS_LIMIT,
DEFAULT_GAS_PRICE,
ETH_TOKEN_ADDRESS,
EVM_ADDRESS,
NETWORK,
RPC_CLIENT,
NetworkType,
Expand All @@ -24,6 +25,7 @@
)

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)


# %%
Expand Down Expand Up @@ -68,6 +70,15 @@ async def deploy_or_upgrade_kakarot(owner):
DEFAULT_GAS_PRICE,
address=starknet_deployments["kakarot"],
)
# Temporarily set the coinbase to the default EVM deployer so that
# fees are not sent to 0x0 but rather sent back to the deployer itself,
# until the coinbase is set to the deployed contract later on.
await invoke(
"kakarot",
"set_coinbase",
int(EVM_ADDRESS, 16),
address=starknet_deployments["kakarot"],
)

dump_deployments(starknet_deployments)

Expand All @@ -79,6 +90,7 @@ async def main():
except Exception:
logger.error("❌ Kakarot is not declared, exiting...")
return

account = await get_starknet_account()
register_lazy_account(account.address)
await deploy_or_upgrade_kakarot(account)
Expand Down
42 changes: 34 additions & 8 deletions kakarot_scripts/deployment/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from uvloop import run

from kakarot_scripts.constants import EVM_ADDRESS, L1_RPC_PROVIDER, NETWORK
from kakarot_scripts.deployment.declarations import declare_contracts
from kakarot_scripts.deployment.evm_deployments import deploy_evm_contracts
from kakarot_scripts.deployment.kakarot_deployment import deploy_or_upgrade_kakarot
Expand All @@ -16,6 +17,7 @@
whitelist_pre_eip155_txs,
)
from kakarot_scripts.deployment.starknet_deployments import deploy_starknet_contracts
from kakarot_scripts.utils.kakarot import eth_balance_of, get_contract
from kakarot_scripts.utils.starknet import (
call,
execute_calls,
Expand All @@ -28,9 +30,9 @@
logging.basicConfig()
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
# %%


# %%
async def main():

# %% Account initialization
Expand Down Expand Up @@ -65,16 +67,40 @@ async def main():
await deploy_l2_messaging_contracts()

# %% Tear down
coinbase_address = (await call("kakarot", "get_coinbase")).coinbase
if coinbase_address == 0:
logger.error("❌ Coinbase is set to 0, all transaction fees will be lost")
else:
logger.info(f"✅ Coinbase set to: 0x{coinbase_address:040x}")
coinbase = await get_contract("Kakarot", "Coinbase", address=coinbase_address)
coinbase_balance = await eth_balance_of(coinbase_address)
if coinbase_balance / 1e18 > 0.001:
logger.info(
f"ℹ️ Withdrawing {coinbase_balance / 1e18} ETH from Coinbase to Starknet deployer"
)
await coinbase.withdraw(account.address)

balance_after = await get_balance(account.address)
logger.info(
f"ℹ️ Deployer balance changed from {balance_before / 1e18} to {balance_after / 1e18} ETH"
f"💰 Deployer balance changed from {balance_before / 1e18} to {balance_after / 1e18} ETH"
)
logger.info(
f"💰 Coinbase balance: {await eth_balance_of(coinbase_address) / 1e18} ETH"
)
logger.info(
"💰 Relayers balance:\n"
+ "\n".join(
[
f" {hex(account.address)}: {await get_balance(account.address) / 1e18} ETH"
for account in NETWORK["relayers"].relayer_accounts
]
)
)
l2_balance = await eth_balance_of(EVM_ADDRESS) / 1e18
l1_balance = L1_RPC_PROVIDER.eth.get_balance(EVM_ADDRESS) / 1e18
logger.info(
f"💰 EVM deployer balance:\n L2: {l2_balance} ETH\n L1: {l1_balance} ETH"
)

coinbase = (await call("kakarot", "get_coinbase")).coinbase
if coinbase == 0:
logger.error("❌ Coinbase is set to 0, all transaction fees will be lost")
else:
logger.info(f"✅ Coinbase set to: 0x{coinbase:040x}")


# %%
Expand Down
19 changes: 10 additions & 9 deletions kakarot_scripts/deployment/messaging_deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,17 @@ async def deploy_l1_messaging_contracts():
starknet_deployments = get_starknet_deployments()
l1_addresses = get_l1_addresses()

l1_kakarot_messaging = get_l1_contract(
"L1L2Messaging",
"L1KakarotMessaging",
address=l1_addresses.get("L1KakarotMessaging"),
)
l1_kakarot_messaging_registered_address = None
try:
l1_kakarot_messaging_registered_address = l1_kakarot_messaging.kakarotAddress()
except (ContractLogicError, InsufficientDataBytes):
pass
if address := l1_addresses.get("L1KakarotMessaging"):
l1_kakarot_messaging = get_l1_contract(
"L1L2Messaging", "L1KakarotMessaging", address=address
)
try:
l1_kakarot_messaging_registered_address = (
l1_kakarot_messaging.kakarotAddress()
)
except (ContractLogicError, InsufficientDataBytes):
pass

if l1_kakarot_messaging_registered_address != starknet_deployments["kakarot"]:
if NETWORK["type"] == NetworkType.DEV:
Expand Down
3 changes: 1 addition & 2 deletions kakarot_scripts/deployment/pre_eip155_deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@
remove_lazy_account,
)

# %%


# %%
async def deploy_pre_eip155_senders():
# %% Deployers
for contract_name in PRE_EIP155_TX.keys():
Expand Down
55 changes: 28 additions & 27 deletions kakarot_scripts/deployment/starknet_deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
)

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)


# %%
Expand All @@ -33,36 +34,36 @@ async def deploy_starknet_contracts(account):
class_hash = get_declarations()
starknet_deployments = get_deployments()

if NETWORK["type"] is not NetworkType.PROD:
starknet_deployments["EVM"] = await deploy_starknet(
"EVM",
account.address,
ETH_TOKEN_ADDRESS,
class_hash["account_contract"],
class_hash["uninitialized_account"],
class_hash["Cairo1Helpers"],
BLOCK_GAS_LIMIT,
)
await invoke(
"EVM",
"set_coinbase",
COINBASE,
address=starknet_deployments["EVM"],
)
starknet_deployments["Counter"] = await deploy_starknet("Counter")
starknet_deployments["MockPragmaOracle"] = await deploy_starknet(
"MockPragmaOracle"
)
starknet_deployments["UniversalLibraryCaller"] = await deploy_starknet(
"UniversalLibraryCaller"
)
starknet_deployments["BenchmarkCairoCalls"] = await deploy_starknet(
"BenchmarkCairoCalls"
)
if NETWORK["type"] is NetworkType.PROD:
return

starknet_deployments["EVM"] = await deploy_starknet(
"EVM",
account.address,
ETH_TOKEN_ADDRESS,
class_hash["account_contract"],
class_hash["uninitialized_account"],
class_hash["Cairo1Helpers"],
BLOCK_GAS_LIMIT,
)
await invoke(
"EVM",
"set_coinbase",
COINBASE,
address=starknet_deployments["EVM"],
)
starknet_deployments["Counter"] = await deploy_starknet("Counter")
starknet_deployments["MockPragmaOracle"] = await deploy_starknet("MockPragmaOracle")
starknet_deployments["UniversalLibraryCaller"] = await deploy_starknet(
"UniversalLibraryCaller"
)
starknet_deployments["BenchmarkCairoCalls"] = await deploy_starknet(
"BenchmarkCairoCalls"
)

dump_deployments(starknet_deployments)
# %%
return starknet_deployments
return


# %% Run
Expand Down
7 changes: 4 additions & 3 deletions kakarot_scripts/utils/kakarot.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,9 @@ async def send_pre_eip155_transaction(name: str, max_fee: Optional[int] = None):
signed_tx = PRE_EIP155_TX[name]["signed_tx"]
deployer_evm_address = PRE_EIP155_TX[name]["deployer"]
deployer_starknet_address = await get_starknet_address(deployer_evm_address)
should_deploy = PRE_EIP155_TX[name].get("deployer", False)
should_deploy = PRE_EIP155_TX[name].get("should_deploy", False)
if not should_deploy:
logger.info(f"ℹ️ {name} is already deployed, skipping")
logger.info(f"ℹ️ {name} is already deployed, skipping")
return

if WEB3.is_connected():
Expand Down Expand Up @@ -785,7 +785,7 @@ async def store_bytecode(bytecode: Union[str, bytes], **kwargs):
return evm_address


async def deploy_pre_eip155_sender(name: str) -> bool:
async def deploy_pre_eip155_sender(name: str):
tx_instance = PRE_EIP155_TX[name]
deployer_evm_address = tx_instance["deployer"]
amount = tx_instance["required_eth"]
Expand All @@ -801,6 +801,7 @@ async def deploy_pre_eip155_sender(name: str) -> bool:
logger.info(
f"ℹ️ Nonce for {deployer_evm_address} is not 0 ({nonce}), skipping transaction"
)
tx_instance["should_deploy"] = False
return

# Deploy and fund deployer to enable the authorization callback when calling set_authorized_pre_eip155_tx
Expand Down
Loading

0 comments on commit 31d14bf

Please sign in to comment.