Skip to content

Commit ae47a7a

Browse files
authored
Skip gas and balance checks for l1 message (#2)
* skip gas check * do not check l1 msg balance * fix fmt * fix test * fix clippy --------- Co-authored-by: chengwenxi <[email protected]>
1 parent f5f08b9 commit ae47a7a

File tree

2 files changed

+35
-11
lines changed

2 files changed

+35
-11
lines changed

crates/primitives/src/env.rs

+22-9
Original file line numberDiff line numberDiff line change
@@ -274,17 +274,30 @@ impl Env {
274274
// Check if account has enough balance for gas_limit*gas_price and value transfer.
275275
// Transfer will be done inside `*_inner` functions.
276276
if balance_check > account.info.balance {
277-
if self.cfg.is_balance_check_disabled() {
278-
// Add transaction cost to balance to ensure execution doesn't fail.
279-
account.info.balance = balance_check;
280-
} else {
281-
return Err(InvalidTransaction::LackOfFundForMaxFee {
282-
fee: Box::new(balance_check),
283-
balance: Box::new(account.info.balance),
284-
});
277+
cfg_if::cfg_if! {
278+
if #[cfg(not(feature = "morph"))] {
279+
if self.cfg.is_balance_check_disabled() {
280+
// Add transaction cost to balance to ensure execution doesn't fail.
281+
account.info.balance = balance_check;
282+
} else {
283+
return Err(InvalidTransaction::LackOfFundForMaxFee {
284+
fee: Box::new(balance_check),
285+
balance: Box::new(account.info.balance),
286+
});
287+
}
288+
} else {
289+
if self.cfg.is_balance_check_disabled() || self.tx.morph.is_l1_msg {
290+
// Add transaction cost to balance to ensure execution doesn't fail.
291+
account.info.balance = balance_check;
292+
} else {
293+
return Err(InvalidTransaction::LackOfFundForMaxFee {
294+
fee: Box::new(balance_check),
295+
balance: Box::new(account.info.balance),
296+
});
297+
}
298+
}
285299
}
286300
}
287-
288301
Ok(())
289302
}
290303
}

crates/revm/src/handler/mainnet/validation.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub fn validate_initial_tx_gas<SPEC: Spec, DB: Database>(
4949
.map(|l| l.len() as u64)
5050
.unwrap_or_default();
5151

52-
let initial_gas_spend = gas::validate_initial_tx_gas(
52+
let mut initial_gas_spend = gas::validate_initial_tx_gas(
5353
SPEC::SPEC_ID,
5454
input,
5555
is_create,
@@ -59,7 +59,18 @@ pub fn validate_initial_tx_gas<SPEC: Spec, DB: Database>(
5959

6060
// Additional check to see if limit is big enough to cover initial gas.
6161
if initial_gas_spend > env.tx.gas_limit {
62-
return Err(InvalidTransaction::CallGasCostMoreThanGasLimit.into());
62+
cfg_if::cfg_if! {
63+
if #[cfg(not(feature = "morph"))] {
64+
return Err(InvalidTransaction::CallGasCostMoreThanGasLimit.into());
65+
} else {
66+
// reset initial gas spend for l1 message to ensure execution doesn't fail
67+
if env.tx.morph.is_l1_msg {
68+
initial_gas_spend = env.tx.gas_limit
69+
} else {
70+
return Err(InvalidTransaction::CallGasCostMoreThanGasLimit.into());
71+
}
72+
}
73+
}
6374
}
6475
Ok(initial_gas_spend)
6576
}

0 commit comments

Comments
 (0)