Skip to content

Commit f897535

Browse files
JereSalotomip01
andauthored
fix(levm, l1): fix hive tests rpc (#2176)
**Motivation** - When executing ethereum/rpc simulation with LEVM we have errors in a lot of tests. The error is when executing the blocks for the setup for these tests and how we created the withdrawals requests introduced in EIP-7002 **Description** - First, when we execute the transactions, we weren't handling if the account was delegated and we weren't using the correct bytecode. For this, we add the check for delegated accounts and get the bytecode. This is made when creating a new VM and using the function `eip7702_get_code()`. - Second, when creating the withdrawals requests, we were overwritting and loosing some of the new values in the account updates. We now merge both updates. - When running the system contract for the withdrawals requests introduced in EIP 7002, we were creating a new `CacheDB` instead of using the one with updated values. **Status** - All RPC Hive tests were passing, but with the changed made [here](#2179), 12 are failing due to a new missing implementation. Links to #2158 --------- Co-authored-by: Tomás Paradelo <[email protected]>
1 parent c1adf82 commit f897535

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

crates/vm/backends/levm/mod.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ pub fn generic_system_contract_levm(
452452
U256::zero(),
453453
calldata.into(),
454454
store_wrapper,
455-
CacheDB::new(),
455+
new_state.clone(),
456456
vec![],
457457
None,
458458
)
@@ -463,9 +463,7 @@ pub fn generic_system_contract_levm(
463463
report.new_state.remove(&system_address);
464464

465465
match report.result {
466-
TxResult::Success => {
467-
new_state.extend(report.new_state.clone());
468-
}
466+
TxResult::Success => {}
469467
_ => {
470468
return Err(EvmError::Custom(
471469
"ERROR in generic_system_contract_levm(). TX didn't succeed.".to_owned(),
@@ -474,6 +472,14 @@ pub fn generic_system_contract_levm(
474472
}
475473

476474
// new_state is a CacheDB coming from outside the function
475+
for (address, account) in report.new_state.iter_mut() {
476+
if let Some(existing_account) = new_state.get(address) {
477+
let mut existing_storage = existing_account.storage.clone();
478+
existing_storage.extend(account.storage.clone());
479+
account.storage = existing_storage;
480+
account.info.balance = existing_account.info.balance;
481+
}
482+
}
477483
new_state.extend(report.new_state.clone());
478484

479485
Ok(report)

crates/vm/levm/src/vm.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,15 @@ impl VM {
233233
TxKind::Call(address_to) => {
234234
default_touched_accounts.insert(address_to);
235235

236-
let bytecode = get_account_no_push_cache(&cache, db.clone(), address_to)
237-
.info
238-
.bytecode;
236+
let mut substate = Substate {
237+
selfdestruct_set: HashSet::new(),
238+
touched_accounts: default_touched_accounts,
239+
touched_storage_slots: default_touched_storage_slots,
240+
created_accounts: HashSet::new(),
241+
};
242+
243+
let (_is_delegation, _eip7702_gas_consumed, _code_address, bytecode) =
244+
eip7702_get_code(&mut cache, db.clone(), &mut substate, address_to)?;
239245

240246
// CALL tx
241247
let initial_call_frame = CallFrame::new(
@@ -252,13 +258,6 @@ impl VM {
252258
false,
253259
);
254260

255-
let substate = Substate {
256-
selfdestruct_set: HashSet::new(),
257-
touched_accounts: default_touched_accounts,
258-
touched_storage_slots: default_touched_storage_slots,
259-
created_accounts: HashSet::new(),
260-
};
261-
262261
Ok(Self {
263262
call_frames: vec![initial_call_frame],
264263
db,

0 commit comments

Comments
 (0)