Skip to content

Commit

Permalink
refactor: remove deprecated entrypoints (#1572)
Browse files Browse the repository at this point in the history
<!--- Please provide a general summary of your changes in the title
above -->

<!-- Give an estimate of the time you spent on this PR in terms of work
days.
Did you spend 0.5 days on this PR or rather 2 days?  -->

Time spent on this PR:

## Pull request type

<!-- Please try to limit your pull request to one type,
submit multiple pull requests if needed. -->

Please check the type of change your PR introduces:

- [ ] Bugfix
- [ ] Feature
- [ ] Code style update (formatting, renaming)
- [ ] Refactoring (no functional changes, no api changes)
- [ ] Build related changes
- [ ] Documentation content changes
- [ ] Other (please describe):

## What is the current behavior?

<!-- Please describe the current behavior that you are modifying,
or link to a relevant issue. -->

Resolves #1507

## What is the new behavior?

<!-- Please describe the behavior or changes that are being added by
this PR. -->

Remove deprecated entrypoints

<!-- 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/1572)
<!-- Reviewable:end -->
  • Loading branch information
obatirou authored Nov 4, 2024
1 parent f599f71 commit 5c96bb7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 146 deletions.
6 changes: 0 additions & 6 deletions cairo_zero/kakarot/interfaces/interfaces.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
}

Expand Down
25 changes: 0 additions & 25 deletions cairo_zero/kakarot/kakarot.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
27 changes: 0 additions & 27 deletions cairo_zero/kakarot/library.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
100 changes: 12 additions & 88 deletions tests/end_to_end/test_kakarot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 5c96bb7

Please sign in to comment.