Skip to content

Commit ed9940d

Browse files
authored
feat: disable gas checks (#54)
* dep: bump alloy to 0.3.6 * fix: doc links * feat: disable gas checks
1 parent 8dd8a4f commit ed9940d

File tree

4 files changed

+103
-3
lines changed

4 files changed

+103
-3
lines changed

Diff for: Cargo.toml

+9
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,12 @@ optional_block_gas_limit = ["revm/optional_block_gas_limit"]
8585
optional_eip3607 = ["revm/optional_eip3607"]
8686
optional_gas_refund = ["revm/optional_gas_refund"]
8787
optional_no_base_fee = ["revm/optional_no_base_fee"]
88+
full_env_cfg = [
89+
"optional_balance_check",
90+
"optional_block_gas_limit",
91+
"optional_eip3607",
92+
"optional_gas_refund",
93+
"optional_no_base_fee",
94+
"optional_beneficiary_reward",
95+
]
96+

Diff for: src/fill/mod.rs

+53
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,56 @@ mod noop;
77
pub use noop::{NoopBlock, NoopCfg};
88

99
mod zenith;
10+
11+
use revm::primitives::{CfgEnv, TxEnv};
12+
13+
/// A [`Cfg`] that disables gas-related checks and payment of the
14+
/// beneficiary reward, while leaving other cfg options unchanged.
15+
///
16+
/// ## Warning
17+
///
18+
/// This filler relies on the following optional features:
19+
/// - `optional_balance_check`
20+
/// - `optional_beneficiary_reward`
21+
/// - `optional_gas_refund`
22+
/// - `optional_no_base_fee`
23+
///
24+
///
25+
/// It will disable the corresponding checks if the features are enabled. **If
26+
/// none of the features are enabled, this filler will do nothing.**
27+
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
28+
pub struct DisableGasChecks;
29+
30+
impl Cfg for DisableGasChecks {
31+
#[allow(unused_variables)]
32+
fn fill_cfg_env(&self, cfg_env: &mut CfgEnv) {
33+
#[cfg(feature = "optional_balance_check")]
34+
{
35+
cfg_env.disable_balance_check = true;
36+
}
37+
#[cfg(feature = "optional_beneficiary_reward")]
38+
{
39+
cfg_env.disable_beneficiary_reward = true;
40+
}
41+
#[cfg(feature = "optional_gas_refund")]
42+
{
43+
cfg_env.disable_gas_refund = true;
44+
}
45+
#[cfg(feature = "optional_no_base_fee")]
46+
{
47+
cfg_env.disable_base_fee = true;
48+
}
49+
}
50+
}
51+
52+
/// A [`Tx`] that disables the nonce check, while leaving other [`TxEnv`]
53+
/// attributes untouched.
54+
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
55+
pub struct DisableNonceCheck;
56+
57+
impl Tx for DisableNonceCheck {
58+
#[allow(unused_variables)]
59+
fn fill_tx_env(&self, tx_env: &mut TxEnv) {
60+
tx_env.nonce = None;
61+
}
62+
}

Diff for: src/fill/zenith.rs

+40-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use crate::Tx;
2-
use alloy_primitives::U256;
2+
use alloy_primitives::{Address, U256};
3+
use alloy_sol_types::SolCall;
34
use revm::primitives::{TransactTo, TxEnv};
4-
use zenith_types::Transactor;
5+
use zenith_types::{Passage::EnterToken, Transactor};
56

67
impl Tx for Transactor::Transact {
78
fn fill_tx_env(&self, tx_env: &mut revm::primitives::TxEnv) {
@@ -41,3 +42,40 @@ impl Tx for Transactor::Transact {
4142
authorization_list.take();
4243
}
4344
}
45+
46+
impl Tx for EnterToken {
47+
fn fill_tx_env(&self, tx_env: &mut TxEnv) {
48+
let TxEnv {
49+
caller,
50+
gas_limit,
51+
gas_price,
52+
transact_to,
53+
value,
54+
data,
55+
nonce,
56+
chain_id,
57+
access_list,
58+
gas_priority_fee,
59+
blob_hashes,
60+
max_fee_per_blob_gas,
61+
authorization_list,
62+
} = tx_env;
63+
64+
*caller = zenith_types::MINTER_ADDRESS;
65+
*gas_limit = 1_000_000;
66+
*gas_price = U256::ZERO;
67+
// This is deliberately not set, as it is not known by the event.
68+
*transact_to = Address::ZERO.into();
69+
*value = U256::ZERO;
70+
*data = zenith_types::mintCall { amount: self.amount(), to: self.rollupRecipient }
71+
.abi_encode()
72+
.into();
73+
*nonce = None;
74+
*chain_id = Some(self.rollup_chain_id());
75+
*access_list = vec![];
76+
*gas_priority_fee = Some(U256::ZERO);
77+
blob_hashes.clear();
78+
max_fee_per_blob_gas.take();
79+
authorization_list.take();
80+
}
81+
}

Diff for: src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ mod ext;
375375
pub use ext::EvmExtUnchecked;
376376

377377
mod fill;
378-
pub use fill::{Block, Cfg, NoopBlock, NoopCfg, Tx};
378+
pub use fill::{Block, Cfg, DisableGasChecks, DisableNonceCheck, NoopBlock, NoopCfg, Tx};
379379

380380
pub mod journal;
381381

0 commit comments

Comments
 (0)