Skip to content

Commit fbfe149

Browse files
authored
fix(levm): improve get state transitions LEVM (#2518)
**Motivation** <!-- Why does this pull request exist? What are its goals? --> - Make `get_state_transitions` we use un LEVM return the same as the one in REVM. **Description** <!-- A clear and concise general description of the changes this PR introduces --> - I made changes in the past to make `get_state_transitions` for both LEVM and REVM the same for comparison but I missed one aspect. We only want to show the code in an `AccountUpdate` if the code itself has been modified, not just the `AccountInfo`. Before we were returning the code in the `AccountUpdate` even if only the nonce of the contract changed for example. <!-- Link to issues: Resolves #111, Resolves #222 --> Closes #issue_number
1 parent 35ca6af commit fbfe149

File tree

2 files changed

+26
-23
lines changed

2 files changed

+26
-23
lines changed

cmd/ef_tests/blockchain/test_runner.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{
66
};
77
use ethrex_blockchain::{fork_choice::apply_fork_choice, Blockchain};
88
use ethrex_common::types::{
9-
Account as CoreAccount, Block as CoreBlock, BlockHeader as CoreBlockHeader,
9+
Account as CoreAccount, Block as CoreBlock, BlockHeader as CoreBlockHeader, EMPTY_KECCACK_HASH,
1010
};
1111
use ethrex_rlp::decode::RLPDecode;
1212
use ethrex_storage::{EngineType, Store};
@@ -177,16 +177,19 @@ async fn check_poststate_against_db(test_key: &str, test: &TestUnit, db: &Store)
177177
);
178178
// Check code
179179
let code_hash = expected_account.info.code_hash;
180-
let db_account_code = db
181-
.get_account_code(code_hash)
182-
.expect("Failed to read from DB")
183-
.unwrap_or_else(|| {
184-
panic!("Account code for code hash {code_hash} not found in DB test:{test_key}")
185-
});
186-
assert_eq!(
187-
db_account_code, expected_account.code,
188-
"Mismatched account code for code hash {code_hash} test:{test_key}"
189-
);
180+
if code_hash != *EMPTY_KECCACK_HASH {
181+
// We don't want to get account code if there's no code.
182+
let db_account_code = db
183+
.get_account_code(code_hash)
184+
.expect("Failed to read from DB")
185+
.unwrap_or_else(|| {
186+
panic!("Account code for code hash {code_hash} not found in DB test:{test_key}")
187+
});
188+
assert_eq!(
189+
db_account_code, expected_account.code,
190+
"Mismatched account code for code hash {code_hash} test:{test_key}"
191+
);
192+
}
190193
// Check storage
191194
for (key, value) in expected_account.storage {
192195
let db_storage_value = db

crates/vm/backends/levm/mod.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,12 @@ impl LEVM {
185185
}
186186

187187
let new_state_code_hash = code_hash(&new_state_account.info.bytecode);
188-
if initial_state_account.bytecode_hash() != new_state_code_hash {
188+
let code = if initial_state_account.bytecode_hash() != new_state_code_hash {
189189
acc_info_updated = true;
190-
}
190+
Some(new_state_account.info.bytecode.clone())
191+
} else {
192+
None
193+
};
191194

192195
// 2. Storage has been updated if the current value is different from the one before execution.
193196
let mut added_storage = HashMap::new();
@@ -199,17 +202,14 @@ impl LEVM {
199202
}
200203
}
201204

202-
let (info, code) = if acc_info_updated {
203-
(
204-
Some(AccountInfo {
205-
code_hash: new_state_code_hash,
206-
balance: new_state_account.info.balance,
207-
nonce: new_state_account.info.nonce,
208-
}),
209-
Some(new_state_account.info.bytecode.clone()),
210-
)
205+
let info = if acc_info_updated {
206+
Some(AccountInfo {
207+
code_hash: new_state_code_hash,
208+
balance: new_state_account.info.balance,
209+
nonce: new_state_account.info.nonce,
210+
})
211211
} else {
212-
(None, None)
212+
None
213213
};
214214

215215
let mut removed = !initial_state_account.is_empty() && new_state_account.is_empty();

0 commit comments

Comments
 (0)