Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(levm): initialize cache with sender, recipient and coinbase accounts #1114

Open
wants to merge 2 commits into
base: levm_fixes
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions crates/vm/levm/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ impl Account {
}
}

/// New account with info and empty storage
pub fn new_with_info(info: AccountInfo) -> Self {
Self {
info,
storage: HashMap::new(),
}
}

pub fn has_code(&self) -> bool {
!(self.info.bytecode.is_empty()
|| self.bytecode_hash() == H256::from_str(EMPTY_CODE_HASH_STR).unwrap())
Expand Down
24 changes: 21 additions & 3 deletions crates/vm/levm/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,34 @@ impl VM {
) -> Self {
// Maybe this decision should be made in an upper layer

// Add sender, coinbase and recipient (in the case of a Call) to cache [https://www.evm.codes/about#access_list]
let sender_account_info = db.get_account_info(env.origin);
cache.add_account(
&env.origin,
&Account::new_with_info(sender_account_info.clone()),
);

let coinbase_account_info = db.get_account_info(env.coinbase);
cache.add_account(
&env.coinbase,
&Account::new_with_info(coinbase_account_info),
);

match to {
TxKind::Call(address_to) => {
// add address_to to cache
let recipient_account_info = db.get_account_info(address_to);
cache.add_account(
&address_to,
&Account::new_with_info(recipient_account_info.clone()),
);

// CALL tx
let initial_call_frame = CallFrame::new(
env.origin,
address_to,
address_to,
db.get_account_info(address_to).bytecode,
recipient_account_info.bytecode,
value,
calldata.clone(),
false,
Expand All @@ -93,8 +113,6 @@ impl VM {
}
TxKind::Create => {
// CREATE tx
let sender_account_info = db.get_account_info(env.origin);
// Note that this is a copy of account, not the real one

// (2)
let new_contract_address =
Expand Down
Loading