diff --git a/cairo_zero/kakarot/interfaces/interfaces.cairo b/cairo_zero/kakarot/interfaces/interfaces.cairo index c551275cf..4a31631cd 100644 --- a/cairo_zero/kakarot/interfaces/interfaces.cairo +++ b/cairo_zero/kakarot/interfaces/interfaces.cairo @@ -172,15 +172,9 @@ namespace IKakarot { func register_account(evm_address: felt) { } - func write_account_bytecode(evm_address: felt, bytecode_len: felt, bytecode: felt*) { - } - func upgrade_account(evm_address: felt, new_class: felt) { } - func write_account_nonce(evm_address: felt, nonce: felt) { - } - func set_authorized_pre_eip155_tx(sender_address: felt, msg_hash: felt) { } diff --git a/cairo_zero/kakarot/kakarot.cairo b/cairo_zero/kakarot/kakarot.cairo index 4e24db82b..98ba8fb15 100644 --- a/cairo_zero/kakarot/kakarot.cairo +++ b/cairo_zero/kakarot/kakarot.cairo @@ -290,19 +290,6 @@ func register_account{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_chec return Kakarot.register_account(evm_address); } -// @notice Writes to an account's bytecode -// @dev Writes the bytecode to the account's storage. -// @param evm_address The evm address of the account. -// @param bytecode_len The length of the bytecode. -// @param bytecode The bytecode to write. -@external -func write_account_bytecode{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - evm_address: felt, bytecode_len: felt, bytecode: felt* -) { - Ownable.assert_only_owner(); - return Kakarot.write_account_bytecode(evm_address, bytecode_len, bytecode); -} - // @notice Upgrades the class of an account. // @param evm_address The evm address of the account. // @param new_class_hash The new class hash. @@ -314,18 +301,6 @@ func upgrade_account{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check return Kakarot.upgrade_account(evm_address, new_class_hash); } -// @notice Writes to an account's nonce -// @dev Writes the nonce to the account's storage. -// @param evm_address The evm address of the account. -// @param nonce The nonce to write. -@external -func write_account_nonce{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - evm_address: felt, nonce: felt -) { - Ownable.assert_only_owner(); - return Kakarot.write_account_nonce(evm_address, nonce); -} - // @notice Authorizes a pre-EIP155 transaction for a specific sender // @param sender_address The EVM address of the sender // @param msg_hash The hash of the message to be authorized diff --git a/cairo_zero/kakarot/library.cairo b/cairo_zero/kakarot/library.cairo index acc3e0984..f84baf409 100644 --- a/cairo_zero/kakarot/library.cairo +++ b/cairo_zero/kakarot/library.cairo @@ -323,33 +323,6 @@ namespace Kakarot { return (); } - // @notice Writes to an account's bytecode - // @param evm_address The evm address of the account. - // @param bytecode_len The length of the bytecode. - // @param bytecode The bytecode to write. - func write_account_bytecode{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - evm_address: felt, bytecode_len: felt, bytecode: felt* - ) { - alloc_locals; - let starknet_address = Account.get_starknet_address(evm_address); - IAccount.write_bytecode(starknet_address, bytecode_len, bytecode); - let code_hash = Account.compute_code_hash(bytecode_len, bytecode); - IAccount.set_code_hash(starknet_address, code_hash); - return (); - } - - // @notice Writes to an account's nonce - // @param evm_address The evm address of the account. - // @param nonce The nonce to write. - func write_account_nonce{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( - evm_address: felt, nonce: felt - ) { - alloc_locals; - let starknet_address = Account.get_starknet_address(evm_address); - IAccount.set_nonce(starknet_address, nonce); - return (); - } - // @notice Upgrades an account to a new contract implementation. // @param evm_address The evm address of the account. // @param new_class_hash The new class hash of the account. diff --git a/tests/end_to_end/test_kakarot.py b/tests/end_to_end/test_kakarot.py index bccd225b3..632440db8 100644 --- a/tests/end_to_end/test_kakarot.py +++ b/tests/end_to_end/test_kakarot.py @@ -5,11 +5,8 @@ from starknet_py.contract import Contract from kakarot_scripts.constants import NETWORK, RPC_CLIENT -from kakarot_scripts.utils.kakarot import ( - get_eoa, - get_solidity_artifacts, - get_starknet_address, -) +from kakarot_scripts.utils.kakarot import get_contract as get_solidity_contract +from kakarot_scripts.utils.kakarot import get_deployments, get_eoa, get_starknet_address from kakarot_scripts.utils.starknet import ( call, deploy_starknet_account, @@ -19,7 +16,7 @@ wait_for_transaction, ) from tests.end_to_end.bytecodes import test_cases -from tests.utils.constants import TRANSACTION_GAS_LIMIT +from tests.utils.constants import TRANSACTION_GAS_LIMIT, ZERO_ADDRESS from tests.utils.helpers import ( extract_memory_from_execute, generate_random_evm_address, @@ -169,86 +166,6 @@ async def test_should_fail_when_account_is_already_registered(self, new_eoa): assert "Kakarot: account already registered" in receipt.revert_reason class TestSetAccountStorage: - class TestWriteAccountBytecode: - async def test_should_set_account_bytecode(self, new_eoa): - counter_artifacts = get_solidity_artifacts("PlainOpcodes", "Counter") - eoa = await new_eoa() - bytecode = list( - bytes.fromhex(counter_artifacts["bytecode"]["object"][2:]) - ) - - await invoke( - "kakarot", "write_account_bytecode", int(eoa.address, 16), bytecode - ) - - stored_code = ( - await call( - "account_contract", - "bytecode", - address=eoa.starknet_contract.address, - ) - ).bytecode - assert stored_code == bytecode - - async def test_should_fail_not_owner(self, new_eoa, other): - counter_artifacts = get_solidity_artifacts("PlainOpcodes", "Counter") - eoa = await new_eoa() - bytecode = list( - bytes.fromhex(counter_artifacts["bytecode"]["object"][2:]) - ) - - tx_hash = await invoke( - "kakarot", - "write_account_bytecode", - int(eoa.address, 16), - bytecode, - account=other, - ) - - receipt = await RPC_CLIENT.get_transaction_receipt(tx_hash) - assert receipt.execution_status.name == "REVERTED" - assert "Ownable: caller is not the owner" in receipt.revert_reason - - class TestWriteAccountNonce: - async def test_should_set_account_nonce(self, new_eoa): - eoa = await new_eoa() - prev_nonce = ( - await call( - "account_contract", - "get_nonce", - address=eoa.starknet_contract.address, - ) - ).nonce - - await invoke( - "kakarot", - "write_account_nonce", - int(eoa.address, 16), - prev_nonce + 0xABDE1, - ) - - stored_nonce = ( - await call( - "account_contract", - "get_nonce", - address=eoa.starknet_contract.address, - ) - ).nonce - assert stored_nonce == prev_nonce + 0xABDE1 - - async def test_should_fail_not_owner(self, new_eoa, other): - eoa = await new_eoa() - tx_hash = await invoke( - "kakarot", - "write_account_nonce", - int(eoa.address, 16), - 0xABDE1, - account=other, - ) - receipt = await RPC_CLIENT.get_transaction_receipt(tx_hash) - assert receipt.execution_status.name == "REVERTED" - assert "Ownable: caller is not the owner" in receipt.revert_reason - class TestSetAuthorizedPreEip155Tx: async def test_should_fail_not_owner(self, new_eoa, other): eoa = await new_eoa() @@ -418,13 +335,20 @@ async def test_should_return_native_balance_of(self, new_eoa): assert balance == 0x1234 async def test_should_return_transaction_count(self, new_eoa): - eoa = await new_eoa() + eoa = await new_eoa(1) tx_count = ( await call("kakarot", "eth_get_transaction_count", int(eoa.address, 16)) ).tx_count assert tx_count == 0 - await invoke("kakarot", "write_account_nonce", int(eoa.address, 16), 1) + kakarot_eth = await get_solidity_contract( + "CairoPrecompiles", + "DualVmToken", + address=get_deployments()["KakarotETH"]["address"], + ) + await kakarot_eth.functions["transfer(address,uint256)"]( + ZERO_ADDRESS, 1, caller_eoa=eoa.starknet_contract + ) tx_count = ( await call("kakarot", "eth_get_transaction_count", int(eoa.address, 16))