Skip to content

Commit bb8cece

Browse files
ilitterijrchatruc
andauthored
refactor(levm,l2): hooks (#2508)
**Motivation** - Remove duplicated code between `DefaultHook` and `L2Hook` implementations. - Use the `L2Hook` for every tx (regular ETH txs and L2's privilege txs) when running the L2. **Description** This PR: - Generates abstractions to be used in `DefaultHook` and `L2Hook` to remove repeated code. - Adds the `is_privilege` field to LEVM's `Environment` only compiled under the `l2` feature flag. - `L2Hook` now supports executing every tx (before only privileged). --------- Co-authored-by: Javier Rodríguez Chatruc <[email protected]>
1 parent 084204c commit bb8cece

File tree

9 files changed

+481
-459
lines changed

9 files changed

+481
-459
lines changed

cmd/ef_tests/state/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ path = "./lib.rs"
4141
default = ["c-kzg", "blst"]
4242
c-kzg = ["ethrex-vm/c-kzg", "ethrex-levm/c-kzg", "ethrex-common/c-kzg"]
4343
blst = ["ethrex-vm/blst"]
44+
l2 = ["ethrex-vm/l2", "ethrex-levm/l2"]
4445

4546
[[test]]
4647
name = "all"

cmd/ef_tests/state/runner/levm_runner.rs

+1
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ pub fn prepare_vm_for_tx<'a>(
188188
tx_nonce: test_tx.nonce,
189189
block_gas_limit: test.env.current_gas_limit,
190190
transient_storage: HashMap::new(),
191+
is_privileged: false,
191192
},
192193
db,
193194
&tx,

crates/vm/backends/levm/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ impl LEVM {
132132
block_gas_limit: block_header.gas_limit,
133133
transient_storage: HashMap::new(),
134134
difficulty: block_header.difficulty,
135+
is_privileged: matches!(tx, Transaction::PrivilegedL2Transaction(_)),
135136
};
136137

137138
let mut vm = VM::new(env, db, tx)?;
@@ -721,6 +722,7 @@ fn env_from_generic(
721722
block_gas_limit: header.gas_limit,
722723
transient_storage: HashMap::new(),
723724
difficulty: header.difficulty,
725+
is_privileged: false,
724726
})
725727
}
726728

crates/vm/levm/src/environment.rs

+1
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@ pub struct Environment {
3131
pub tx_nonce: u64,
3232
pub block_gas_limit: u64,
3333
pub transient_storage: TransientStorage,
34+
pub is_privileged: bool,
3435
}

crates/vm/levm/src/errors.rs

+2
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ pub enum InternalError {
194194
InvalidSpecId,
195195
#[error("Account should had been delegated")]
196196
AccountNotDelegated,
197+
#[error("No recipient found for privilege transaction")]
198+
RecipientNotFoundForPrivilegeTransaction,
197199
}
198200

199201
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error, Serialize, Deserialize)]

0 commit comments

Comments
 (0)