diff --git a/crates/contracts/src/kakarot_core/kakarot.cairo b/crates/contracts/src/kakarot_core/kakarot.cairo index 3bfca48be..730e781ce 100644 --- a/crates/contracts/src/kakarot_core/kakarot.cairo +++ b/crates/contracts/src/kakarot_core/kakarot.cairo @@ -19,6 +19,7 @@ mod KakarotCore { use contracts::components::ownable::{ownable_component}; use contracts::components::upgradeable::{IUpgradeable, upgradeable_component}; use contracts::contract_account::{IContractAccountDispatcher, IContractAccountDispatcherTrait}; + use contracts::eoa::{IExternallyOwnedAccountDispatcher, IExternallyOwnedAccountDispatcherTrait}; use contracts::kakarot_core::interface::IKakarotCore; use contracts::kakarot_core::interface; use core::starknet::SyscallResultTrait; @@ -32,8 +33,8 @@ mod KakarotCore { use evm::model::{ExecutionResult, Address, AddressTrait}; use evm::state::StateTrait; use starknet::{ - EthAddress, ContractAddress, ClassHash, get_tx_info, get_contract_address, - get_caller_address, deploy_syscall + EthAddress, ContractAddress, ClassHash, get_tx_info, get_contract_address, deploy_syscall, + get_caller_address }; use super::{INVOKE_ETH_CALL_FORBIDDEN}; use super::{StoredAccountType}; @@ -254,17 +255,7 @@ mod KakarotCore { let from = Address { evm: from, starknet: self.compute_starknet_address(from) }; - let to = match to { - Option::Some(to) => { - let target_starknet_address = self.compute_starknet_address(to); - Option::Some(Address { evm: to, starknet: target_starknet_address }) - }, - Option::None => Option::None - }; - - let result = KakarotInternal::handle_execute( - :from, :to, :gas_limit, :gas_price, :value, :data - ); + let result = self.handle_call(:from, :to, :gas_limit, :gas_price, :value, :data); match result { Result::Ok(result) => result.return_data, // TODO: Return the error message as Bytes in the response @@ -295,17 +286,7 @@ mod KakarotCore { .expect('Fetching EOA failed'); assert(caller_account_type == AccountType::EOA, 'Caller is not an EOA'); - let to = match to { - Option::Some(to) => { - let target_starknet_address = self.compute_starknet_address(to); - Option::Some(Address { evm: to, starknet: target_starknet_address }) - }, - Option::None(_) => Option::None(()) - }; - - let mut result = KakarotInternal::handle_execute( - :from, :to, :gas_limit, :gas_price, :value, :data - ); + let mut result = self.handle_call(:from, :to, :gas_limit, :gas_price, :value, :data); match result { Result::Ok(result) => { let mut state = result.state; @@ -357,14 +338,32 @@ mod KakarotCore { } } - mod KakarotInternal { - use evm::errors::EVMError; - use evm::execution::execute; - use evm::model::{ExecutionResult, Address, AccountTrait}; + #[generate_trait] + impl KakarotCoreInternalImpl of KakarotCoreInternal { + fn is_view(self: @ContractState) -> bool { + let tx_info = get_tx_info().unbox(); + + // If the account that originated the transaction is not zero, this means we + // are in an invoke transaction instead of a call; therefore, `eth_call` is being wrongly called + // For invoke transactions, `eth_send_transaction` must be used + if !tx_info.account_contract_address.is_zero() { + return false; + } + true + } - fn handle_execute( + /// Maps an EVM address to a Starknet address + /// Triggerred when deployment of an EOA or CA is successful + fn set_address_registry( + ref self: ContractState, evm_address: EthAddress, account: StoredAccountType + ) { + self.address_registry.write(evm_address, account); + } + + fn handle_call( + self: @ContractState, from: Address, - to: Option
, + to: Option