Skip to content

Commit

Permalink
feat: remove 'compute_starknet_address' (#1436)
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 #<Issue number>

## What is the new behavior?

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

- Remove this entrypoint, deprecated in favor of `get_starknet_address`
-
-

<!-- 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/1436)
<!-- Reviewable:end -->

---------

Co-authored-by: Clément Walter <[email protected]>
  • Loading branch information
enitrat and ClementWalter committed Sep 24, 2024
1 parent 1b92042 commit 87153b8
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 37 deletions.
12 changes: 0 additions & 12 deletions kakarot_scripts/utils/kakarot.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,18 +677,6 @@ async def send_starknet_transaction(
return receipt, response, success, gas_used


async def compute_starknet_address(address: Union[str, int]):
"""
Compute the Starknet address of an EVM address.
Warning: use get_starknet_address for getting the actual address of an account.
"""
evm_address = int(address, 16) if isinstance(address, str) else address
kakarot_contract = _get_starknet_contract("kakarot")
return (
await kakarot_contract.functions["compute_starknet_address"].call(evm_address)
).contract_address


async def get_starknet_address(address: Union[str, int]):
"""
Get the registered Starknet address of an EVM address, or the one it would get
Expand Down
3 changes: 0 additions & 3 deletions src/kakarot/interfaces/interfaces.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,6 @@ namespace IKakarot {
func deploy_externally_owned_account(evm_address: felt) {
}

func compute_starknet_address(evm_address: felt) -> (contract_address: felt) {
}

func get_account_contract_class_hash() -> (account_contract_class_hash: felt) {
}

Expand Down
11 changes: 0 additions & 11 deletions src/kakarot/kakarot.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -191,17 +191,6 @@ func get_block_gas_limit{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_c
return Kakarot.get_block_gas_limit();
}

// @notice Compute the starknet address of a contract given its EVM address
// @param evm_address The EVM address of the contract
// @return contract_address The starknet address of the contract
@view
func compute_starknet_address{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
evm_address: felt
) -> (contract_address: felt) {
let starknet_address = Account.compute_starknet_address(evm_address);
return (contract_address=starknet_address);
}

// @notice Return the account implementation class hash
// @return account_contract_class_hash The account implementation class hash
@view
Expand Down
15 changes: 9 additions & 6 deletions tests/end_to_end/test_kakarot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

from kakarot_scripts.constants import NETWORK, RPC_CLIENT
from kakarot_scripts.utils.kakarot import (
compute_starknet_address,
get_eoa,
get_solidity_artifacts,
get_starknet_address,
)
from kakarot_scripts.utils.starknet import (
call,
Expand Down Expand Up @@ -85,7 +85,7 @@ async def test_execute(
access_list=[],
)
origin_starknet_address = (
await evm.functions["compute_starknet_address"].call(origin)
await evm.functions["get_starknet_address"].call(origin)
).contract_address
self_balance = (
await eth.functions["balanceOf"].call(origin_starknet_address)
Expand Down Expand Up @@ -133,10 +133,10 @@ async def test_execute(
if event.from_address != eth.address
] == events

class TestComputeStarknetAddress:
class TestGetStarknetAddress:
async def test_should_return_same_as_deployed_address(self, new_eoa):
eoa = await new_eoa()
starknet_address = await compute_starknet_address(eoa.address)
starknet_address = await get_starknet_address(eoa.address)
assert eoa.starknet_contract.address == starknet_address

class TestDeployExternallyOwnedAccount:
Expand Down Expand Up @@ -305,9 +305,12 @@ async def test_eth_call_should_handle_uninitialized_class_update(
"set_uninitialized_account_class_hash",
class_hashes["uninitialized_account_fixture"],
)

# Verifying that when updating the uninitialized account class hash, the starknet address
# of an already deployed account is not impacted
assert (
await call("kakarot", "compute_starknet_address", int(eoa.address, 16))
) != eoa.starknet_contract.address
await call("kakarot", "get_starknet_address", int(eoa.address, 16))
).starknet_address == eoa.starknet_contract.address

result = await kakarot.functions["eth_call"].call(
nonce=0,
Expand Down
11 changes: 6 additions & 5 deletions tests/fixtures/EVM.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,15 @@ func is_deployed{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr
return (deployed=1);
}

// @notice Compute the starknet address of a contract given its EVM address
// @param evm_address The EVM address of the contract
// @return contract_address The starknet address of the contract
// @notice Returns the corresponding Starknet address for a given EVM address.
// @dev Returns the registered address if there is one, otherwise returns the deterministic address got when Kakarot deploys an account.
// @param evm_address The EVM address to transform to a starknet address
// @return starknet_address The Starknet Account Contract address
@view
func compute_starknet_address{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
func get_starknet_address{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
evm_address: felt
) -> (contract_address: felt) {
let starknet_address = Account.compute_starknet_address(evm_address);
let starknet_address = Account.get_starknet_address(evm_address);
return (contract_address=starknet_address);
}

Expand Down

0 comments on commit 87153b8

Please sign in to comment.