From c2c24f77388967a3df6415d83b7018b6f36855e0 Mon Sep 17 00:00:00 2001 From: enitrat Date: Tue, 24 Sep 2024 10:14:03 +0200 Subject: [PATCH 1/8] remove coinbase constructor arg --- kakarot_scripts/constants.py | 2 +- kakarot_scripts/deploy_kakarot.py | 3 --- src/kakarot/kakarot.cairo | 2 -- src/kakarot/library.cairo | 3 --- tests/utils/constants.py | 5 ----- 5 files changed, 1 insertion(+), 14 deletions(-) diff --git a/kakarot_scripts/constants.py b/kakarot_scripts/constants.py index c2a65152e..79195b300 100644 --- a/kakarot_scripts/constants.py +++ b/kakarot_scripts/constants.py @@ -223,7 +223,7 @@ class ChainId(IntEnum): ETH_TOKEN_ADDRESS = 0x49D36570D4E46F48E99674BD3FCC84644DDD6B96F7C741B1562B82F9E004DC7 COINBASE = int( os.getenv("KAKAROT_COINBASE_RECIPIENT") - or "0x20eB005C0b9c906691F885eca5895338E15c36De", + or "0x20eB005C0b9c906691F885eca5895338E15c36De", # Defaults to faucet on appchain sepolia 16, ) CAIRO_ZERO_DIR = Path("src") diff --git a/kakarot_scripts/deploy_kakarot.py b/kakarot_scripts/deploy_kakarot.py index 3ebffeb45..cd1d604e5 100644 --- a/kakarot_scripts/deploy_kakarot.py +++ b/kakarot_scripts/deploy_kakarot.py @@ -6,7 +6,6 @@ ARACHNID_PROXY_DEPLOYER, ARACHNID_PROXY_SIGNED_TX, BLOCK_GAS_LIMIT, - COINBASE, CREATEX_DEPLOYER, CREATEX_SIGNED_TX, DECLARED_CONTRACTS, @@ -63,7 +62,6 @@ async def main(): class_hash["account_contract"], # account_contract_class_hash_ class_hash["uninitialized_account"], # uninitialized_account_class_hash_ class_hash["Cairo1Helpers"], - COINBASE, BLOCK_GAS_LIMIT, ) starknet_deployments["Counter"] = await deploy_starknet("Counter") @@ -105,7 +103,6 @@ async def main(): class_hash["account_contract"], # account_contract_class_hash_ class_hash["uninitialized_account"], # uninitialized_account_class_hash_ class_hash["Cairo1Helpers"], - COINBASE, BLOCK_GAS_LIMIT, ) await invoke( diff --git a/src/kakarot/kakarot.cairo b/src/kakarot/kakarot.cairo index ddcc71c1b..07a8558a5 100644 --- a/src/kakarot/kakarot.cairo +++ b/src/kakarot/kakarot.cairo @@ -78,7 +78,6 @@ func constructor{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr account_contract_class_hash: felt, uninitialized_account_class_hash: felt, cairo1_helpers_class_hash: felt, - coinbase: felt, block_gas_limit: felt, ) { return Kakarot.constructor( @@ -87,7 +86,6 @@ func constructor{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr account_contract_class_hash, uninitialized_account_class_hash, cairo1_helpers_class_hash, - coinbase, block_gas_limit, ); } diff --git a/src/kakarot/library.cairo b/src/kakarot/library.cairo index 5a4af623d..4b48922eb 100644 --- a/src/kakarot/library.cairo +++ b/src/kakarot/library.cairo @@ -43,14 +43,12 @@ namespace Kakarot { // @param account_contract_class_hash The clash hash of the contract account. // @param uninitialized_account_class_hash The class hash of the uninitialized account used for deterministic address calculation. // @param cairo1_helpers_class_hash The precompiles class hash for precompiles not implemented in Kakarot. - // @param coinbase The EOA whose key is owned by the deployer (or known to be owned by Coinbase) func constructor{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( owner: felt, native_token_address, account_contract_class_hash, uninitialized_account_class_hash, cairo1_helpers_class_hash, - coinbase, block_gas_limit, ) { Ownable.initializer(owner); @@ -58,7 +56,6 @@ namespace Kakarot { Kakarot_account_contract_class_hash.write(account_contract_class_hash); Kakarot_uninitialized_account_class_hash.write(uninitialized_account_class_hash); Kakarot_cairo1_helpers_class_hash.write(cairo1_helpers_class_hash); - Kakarot_coinbase.write(coinbase); Kakarot_block_gas_limit.write(block_gas_limit); return (); } diff --git a/tests/utils/constants.py b/tests/utils/constants.py index 55a0ab7b3..fcf8c4bf5 100644 --- a/tests/utils/constants.py +++ b/tests/utils/constants.py @@ -19,11 +19,6 @@ # Account balance is the amount of funds that the account has after being deployed ACCOUNT_BALANCE = PRE_FUND_AMOUNT -# Coinbase address is the address of the sequencer -MOCK_COINBASE_ADDRESS = ( - 0x388CA486B82E20CC81965D056B4CDCAACDFFE0CF08E20ED8BA10EA97A487004 -) - # STACK STACK_MAX_DEPTH = 1024 From dd2bc10a2346356861aedfba7c7cb6afdf0e0409 Mon Sep 17 00:00:00 2001 From: enitrat Date: Tue, 24 Sep 2024 10:37:14 +0200 Subject: [PATCH 2/8] add logger on coibase --- kakarot_scripts/deploy_kakarot.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/kakarot_scripts/deploy_kakarot.py b/kakarot_scripts/deploy_kakarot.py index cd1d604e5..4540fa347 100644 --- a/kakarot_scripts/deploy_kakarot.py +++ b/kakarot_scripts/deploy_kakarot.py @@ -146,6 +146,15 @@ async def main(): ) await invoke("kakarot", "set_coinbase", int(bridge.address, 16)) + coinbase = await RPC_CLIENT.call_contract( + starknet_deployments["kakarot"]["address"], "get_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}") + weth = await deploy_evm("WETH", "WETH9") evm_deployments["WETH"] = { "address": int(weth.address, 16), From 891772441860fa106072fcedd6e668c5af477dfd Mon Sep 17 00:00:00 2001 From: enitrat Date: Tue, 24 Sep 2024 11:42:00 +0200 Subject: [PATCH 3/8] fix coinbase call in deploy script --- kakarot_scripts/deploy_kakarot.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/kakarot_scripts/deploy_kakarot.py b/kakarot_scripts/deploy_kakarot.py index 4540fa347..e7f7f6708 100644 --- a/kakarot_scripts/deploy_kakarot.py +++ b/kakarot_scripts/deploy_kakarot.py @@ -25,7 +25,7 @@ ) from kakarot_scripts.utils.kakarot import dump_deployments as dump_evm_deployments from kakarot_scripts.utils.kakarot import get_deployments as get_evm_deployments -from kakarot_scripts.utils.starknet import declare +from kakarot_scripts.utils.starknet import call, declare from kakarot_scripts.utils.starknet import deploy as deploy_starknet from kakarot_scripts.utils.starknet import ( dump_declarations, @@ -146,9 +146,7 @@ async def main(): ) await invoke("kakarot", "set_coinbase", int(bridge.address, 16)) - coinbase = await RPC_CLIENT.call_contract( - starknet_deployments["kakarot"]["address"], "get_coinbase" - ) + coinbase = (await call("kakarot", "get_coinbase")).coinbase if coinbase == 0: logger.error("❌ Coinbase is set to 0, all transaction fees will be lost") From 7cd417ab50c3913641b62611aca7738ab9fa0e73 Mon Sep 17 00:00:00 2001 From: enitrat Date: Tue, 24 Sep 2024 14:59:40 +0200 Subject: [PATCH 4/8] fix test --- kakarot_scripts/deploy_kakarot.py | 1 - tests/end_to_end/test_kakarot.py | 18 +++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/kakarot_scripts/deploy_kakarot.py b/kakarot_scripts/deploy_kakarot.py index e7f7f6708..7703cda7e 100644 --- a/kakarot_scripts/deploy_kakarot.py +++ b/kakarot_scripts/deploy_kakarot.py @@ -147,7 +147,6 @@ async def main(): await invoke("kakarot", "set_coinbase", int(bridge.address, 16)) coinbase = (await call("kakarot", "get_coinbase")).coinbase - if coinbase == 0: logger.error("❌ Coinbase is set to 0, all transaction fees will be lost") else: diff --git a/tests/end_to_end/test_kakarot.py b/tests/end_to_end/test_kakarot.py index 59243b973..ac6e97a7f 100644 --- a/tests/end_to_end/test_kakarot.py +++ b/tests/end_to_end/test_kakarot.py @@ -4,7 +4,7 @@ import pytest_asyncio from starknet_py.contract import Contract -from kakarot_scripts.constants import NETWORK, RPC_CLIENT +from kakarot_scripts.constants import COINBASE, NETWORK, RPC_CLIENT from kakarot_scripts.utils.kakarot import ( get_eoa, get_solidity_artifacts, @@ -70,6 +70,22 @@ async def origin(evm, max_fee): return evm_address +# Used to fill the coinbase with the constant COINBASE address +# used when generating test cases. +@pytest.fixture(scope="class", autouse=True) +async def setup_and_teardown(owner): + # Setup code + print("Setup before all tests in TestKakarot") + prev_coinbase = (await call("kakarot", "get_coinbase")).coinbase + await invoke("kakarot", "set_coinbase", COINBASE) + + yield + + # Teardown code + print("Teardown after all tests in TestKakarot") + await invoke("kakarot", "set_coinbase", prev_coinbase) + + @pytest.mark.asyncio(scope="session") class TestKakarot: class TestEVM: From 32b5b194c27611186957eac5365c5ae5ad435624 Mon Sep 17 00:00:00 2001 From: enitrat Date: Tue, 24 Sep 2024 15:42:53 +0200 Subject: [PATCH 5/8] set coinbase in EVM fixture --- kakarot_scripts/deploy_kakarot.py | 2 ++ tests/end_to_end/test_kakarot.py | 18 +----------------- tests/fixtures/EVM.cairo | 1 + 3 files changed, 4 insertions(+), 17 deletions(-) diff --git a/kakarot_scripts/deploy_kakarot.py b/kakarot_scripts/deploy_kakarot.py index 7703cda7e..c4eeab6c6 100644 --- a/kakarot_scripts/deploy_kakarot.py +++ b/kakarot_scripts/deploy_kakarot.py @@ -6,6 +6,7 @@ ARACHNID_PROXY_DEPLOYER, ARACHNID_PROXY_SIGNED_TX, BLOCK_GAS_LIMIT, + COINBASE, CREATEX_DEPLOYER, CREATEX_SIGNED_TX, DECLARED_CONTRACTS, @@ -64,6 +65,7 @@ async def main(): class_hash["Cairo1Helpers"], BLOCK_GAS_LIMIT, ) + await invoke("EVM", "set_coinbase", COINBASE) starknet_deployments["Counter"] = await deploy_starknet("Counter") starknet_deployments["MockPragmaOracle"] = await deploy_starknet( "MockPragmaOracle" diff --git a/tests/end_to_end/test_kakarot.py b/tests/end_to_end/test_kakarot.py index ac6e97a7f..59243b973 100644 --- a/tests/end_to_end/test_kakarot.py +++ b/tests/end_to_end/test_kakarot.py @@ -4,7 +4,7 @@ import pytest_asyncio from starknet_py.contract import Contract -from kakarot_scripts.constants import COINBASE, NETWORK, RPC_CLIENT +from kakarot_scripts.constants import NETWORK, RPC_CLIENT from kakarot_scripts.utils.kakarot import ( get_eoa, get_solidity_artifacts, @@ -70,22 +70,6 @@ async def origin(evm, max_fee): return evm_address -# Used to fill the coinbase with the constant COINBASE address -# used when generating test cases. -@pytest.fixture(scope="class", autouse=True) -async def setup_and_teardown(owner): - # Setup code - print("Setup before all tests in TestKakarot") - prev_coinbase = (await call("kakarot", "get_coinbase")).coinbase - await invoke("kakarot", "set_coinbase", COINBASE) - - yield - - # Teardown code - print("Teardown after all tests in TestKakarot") - await invoke("kakarot", "set_coinbase", prev_coinbase) - - @pytest.mark.asyncio(scope="session") class TestKakarot: class TestEVM: diff --git a/tests/fixtures/EVM.cairo b/tests/fixtures/EVM.cairo index 63576efa9..169db874e 100644 --- a/tests/fixtures/EVM.cairo +++ b/tests/fixtures/EVM.cairo @@ -33,6 +33,7 @@ from kakarot.kakarot import ( get_account_contract_class_hash, get_cairo1_helpers_class_hash, get_native_token, + set_coinbase, ) from backend.starknet import Starknet, Internals as StarknetInternals from utils.dict import dict_keys, dict_values From f007fbcd1457ae5ece5dee4833355d3188f15b69 Mon Sep 17 00:00:00 2001 From: enitrat Date: Tue, 24 Sep 2024 16:03:55 +0200 Subject: [PATCH 6/8] set EVM fixture coinbase --- kakarot_scripts/deploy_kakarot.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/kakarot_scripts/deploy_kakarot.py b/kakarot_scripts/deploy_kakarot.py index c4eeab6c6..d87b9060e 100644 --- a/kakarot_scripts/deploy_kakarot.py +++ b/kakarot_scripts/deploy_kakarot.py @@ -65,7 +65,12 @@ async def main(): class_hash["Cairo1Helpers"], BLOCK_GAS_LIMIT, ) - await invoke("EVM", "set_coinbase", COINBASE) + await invoke( + "EVM", + "set_coinbase", + COINBASE, + address=starknet_deployments["EVM"]["address"], + ) starknet_deployments["Counter"] = await deploy_starknet("Counter") starknet_deployments["MockPragmaOracle"] = await deploy_starknet( "MockPragmaOracle" From 4a5bbc3231da70b4cdf921ea528da68a7c056ebf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Walter?= Date: Tue, 24 Sep 2024 16:43:30 +0200 Subject: [PATCH 7/8] Update tests/fixtures/EVM.cairo --- tests/fixtures/EVM.cairo | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/fixtures/EVM.cairo b/tests/fixtures/EVM.cairo index 169db874e..63576efa9 100644 --- a/tests/fixtures/EVM.cairo +++ b/tests/fixtures/EVM.cairo @@ -33,7 +33,6 @@ from kakarot.kakarot import ( get_account_contract_class_hash, get_cairo1_helpers_class_hash, get_native_token, - set_coinbase, ) from backend.starknet import Starknet, Internals as StarknetInternals from utils.dict import dict_keys, dict_values From d256fef3940f63dccaa9bc8a13ae35fba4731e38 Mon Sep 17 00:00:00 2001 From: enitrat Date: Tue, 24 Sep 2024 17:38:27 +0200 Subject: [PATCH 8/8] restore set_coinbase in fixture --- tests/fixtures/EVM.cairo | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/fixtures/EVM.cairo b/tests/fixtures/EVM.cairo index 63576efa9..169db874e 100644 --- a/tests/fixtures/EVM.cairo +++ b/tests/fixtures/EVM.cairo @@ -33,6 +33,7 @@ from kakarot.kakarot import ( get_account_contract_class_hash, get_cairo1_helpers_class_hash, get_native_token, + set_coinbase, ) from backend.starknet import Starknet, Internals as StarknetInternals from utils.dict import dict_keys, dict_values