Skip to content

Commit

Permalink
feat: fix coinbase
Browse files Browse the repository at this point in the history
  • Loading branch information
Harsh Bajpai authored and Harsh Bajpai committed Nov 27, 2023
1 parent 71ddcd6 commit 0fbb0e4
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
3 changes: 2 additions & 1 deletion crates/contracts/src/kakarot_core/kakarot.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ mod KakarotCore {
new_class_hash: ClassHash,
}

// TODO: add ability to pass Span<EthAddress>, which should be deployed along with Kakarot
// this can be done once https://github.com/starkware-libs/cairo/issues/4488 is resolved
#[constructor]
fn constructor(
ref self: ContractState,
Expand Down Expand Up @@ -188,7 +190,6 @@ mod KakarotCore {
}
}


fn contract_account_nonce(self: @ContractState, evm_address: EthAddress) -> u64 {
let ca_address = ContractAccountTrait::at(evm_address)
.expect('Fetching CA failed')
Expand Down
6 changes: 0 additions & 6 deletions crates/contracts/src/tests/test_eoa.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ mod test_external_owned_account {
use core::starknet::account::{Call, AccountContractDispatcher, AccountContractDispatcherTrait};


//todo(harsh): remove
use debug::PrintTrait;

use evm::model::{Address, AddressTrait, ContractAccountTrait};
use evm::tests::test_utils::{
kakarot_address, evm_address, other_evm_address, eoa_address, chain_id, gas_limit, gas_price
Expand Down Expand Up @@ -110,9 +107,6 @@ mod test_external_owned_account {
let evm_address = evm_address();
let eoa = kakarot_core.deploy_eoa(evm_address);

//todo(harsh): remove
other_evm_address().print();

let kakarot_address = kakarot_core.contract_address;

let account = deploy_contract_account(other_evm_address(), counter_evm_bytecode());
Expand Down
14 changes: 11 additions & 3 deletions crates/contracts/src/tests/test_kakarot_core.cairo
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
use contracts::contract_account::ContractAccount::TEST_CLASS_HASH as ContractAccountTestClassHash;
use contracts::contract_account::ContractAccount;
use contracts::contract_account::{IContractAccountDispatcher, IContractAccountDispatcherTrait};
use contracts::eoa::ExternallyOwnedAccount;
use contracts::kakarot_core::interface::IExtendedKakarotCoreDispatcherTrait;
use contracts::eoa::{
ExternallyOwnedAccount, IExternallyOwnedAccountDispatcher,
IExternallyOwnedAccountDispatcherTrait
};
use contracts::kakarot_core::interface::IKakarotCore;
use contracts::kakarot_core::interface::{
IExtendedKakarotCoreDispatcher, IExtendedKakarotCoreDispatcherTrait
};
use contracts::kakarot_core::kakarot::StoredAccountType;
use contracts::kakarot_core::{
interface::IExtendedKakarotCoreDispatcherImpl, KakarotCore, KakarotCore::{KakarotCoreInternal},
Expand All @@ -14,6 +20,9 @@ use contracts::tests::test_upgradeable::{
};
use contracts::tests::test_utils as contract_utils;
use contracts::uninitialized_account::UninitializedAccount;
use core::option::OptionTrait;


use core::traits::TryInto;
use evm::machine::Status;
use evm::model::contract_account::ContractAccountTrait;
Expand Down Expand Up @@ -490,4 +499,3 @@ fn test_eoa_class_hash() {
assert(event.old_class_hash == class_hash, 'wrong old hash');
assert(event.new_class_hash == kakarot_core.eoa_class_hash(), 'wrong new hash');
}

11 changes: 6 additions & 5 deletions crates/evm/src/instructions/block_information.cairo
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use contracts::eoa::{IExternallyOwnedAccountDispatcher, IExternallyOwnedAccountDispatcherTrait};
//! Block Information.

use contracts::kakarot_core::{KakarotCore, IKakarotCore};
Expand Down Expand Up @@ -54,11 +55,11 @@ impl BlockInformation of BlockInformationTrait {
let execution_info = get_execution_info_syscall()
.map_err(EVMError::SyscallFailed(EXECUTION_INFO_SYSCALL_FAILED))?
.unbox();
let coinbase: EthAddress = execution_info
.block_info
.unbox()
.sequencer_address
.try_into_result()?;

let coinbase = execution_info.block_info.unbox().sequencer_address;
let eoa = IExternallyOwnedAccountDispatcher { contract_address: coinbase };

let coinbase = eoa.evm_address();
self.stack.push(coinbase.into())
}

Expand Down
2 changes: 2 additions & 0 deletions crates/evm/src/model/eoa.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use contracts::kakarot_core::{IKakarotCore, KakarotCore, KakarotCore::KakarotCor
use contracts::uninitialized_account::{
IUninitializedAccountDispatcher, IUninitializedAccountDispatcherTrait
};

use evm::errors::{EVMError, CONTRACT_SYSCALL_FAILED, EOA_EXISTS};
use evm::model::{Address, AddressTrait};
use starknet::{EthAddress, ContractAddress, get_contract_address, deploy_syscall};
Expand All @@ -29,6 +30,7 @@ impl EOAImpl of EOATrait {
let calldata: Span<felt252> = array![kakarot_address.into(), evm_address.into()].span();

let maybe_address = deploy_syscall(account_class_hash, evm_address.into(), calldata, false);

// Panic with err as syscall failure can't be caught, so we can't manage
// the error
match maybe_address {
Expand Down

0 comments on commit 0fbb0e4

Please sign in to comment.