Skip to content

Commit

Permalink
feat: disable gas checks (#54)
Browse files Browse the repository at this point in the history
* dep: bump alloy to 0.3.6

* fix: doc links

* feat: disable gas checks
  • Loading branch information
prestwich authored Sep 19, 2024
1 parent 8dd8a4f commit ed9940d
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 3 deletions.
9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,12 @@ optional_block_gas_limit = ["revm/optional_block_gas_limit"]
optional_eip3607 = ["revm/optional_eip3607"]
optional_gas_refund = ["revm/optional_gas_refund"]
optional_no_base_fee = ["revm/optional_no_base_fee"]
full_env_cfg = [
"optional_balance_check",
"optional_block_gas_limit",
"optional_eip3607",
"optional_gas_refund",
"optional_no_base_fee",
"optional_beneficiary_reward",
]

53 changes: 53 additions & 0 deletions src/fill/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,56 @@ mod noop;
pub use noop::{NoopBlock, NoopCfg};

mod zenith;

use revm::primitives::{CfgEnv, TxEnv};

/// A [`Cfg`] that disables gas-related checks and payment of the
/// beneficiary reward, while leaving other cfg options unchanged.
///
/// ## Warning
///
/// This filler relies on the following optional features:
/// - `optional_balance_check`
/// - `optional_beneficiary_reward`
/// - `optional_gas_refund`
/// - `optional_no_base_fee`
///
///
/// It will disable the corresponding checks if the features are enabled. **If
/// none of the features are enabled, this filler will do nothing.**
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub struct DisableGasChecks;

impl Cfg for DisableGasChecks {
#[allow(unused_variables)]
fn fill_cfg_env(&self, cfg_env: &mut CfgEnv) {
#[cfg(feature = "optional_balance_check")]
{
cfg_env.disable_balance_check = true;
}
#[cfg(feature = "optional_beneficiary_reward")]
{
cfg_env.disable_beneficiary_reward = true;
}
#[cfg(feature = "optional_gas_refund")]
{
cfg_env.disable_gas_refund = true;
}
#[cfg(feature = "optional_no_base_fee")]
{
cfg_env.disable_base_fee = true;
}
}
}

/// A [`Tx`] that disables the nonce check, while leaving other [`TxEnv`]
/// attributes untouched.
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub struct DisableNonceCheck;

impl Tx for DisableNonceCheck {
#[allow(unused_variables)]
fn fill_tx_env(&self, tx_env: &mut TxEnv) {
tx_env.nonce = None;
}
}
42 changes: 40 additions & 2 deletions src/fill/zenith.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::Tx;
use alloy_primitives::U256;
use alloy_primitives::{Address, U256};
use alloy_sol_types::SolCall;
use revm::primitives::{TransactTo, TxEnv};
use zenith_types::Transactor;
use zenith_types::{Passage::EnterToken, Transactor};

impl Tx for Transactor::Transact {
fn fill_tx_env(&self, tx_env: &mut revm::primitives::TxEnv) {
Expand Down Expand Up @@ -41,3 +42,40 @@ impl Tx for Transactor::Transact {
authorization_list.take();
}
}

impl Tx for EnterToken {
fn fill_tx_env(&self, tx_env: &mut TxEnv) {
let TxEnv {
caller,
gas_limit,
gas_price,
transact_to,
value,
data,
nonce,
chain_id,
access_list,
gas_priority_fee,
blob_hashes,
max_fee_per_blob_gas,
authorization_list,
} = tx_env;

*caller = zenith_types::MINTER_ADDRESS;
*gas_limit = 1_000_000;
*gas_price = U256::ZERO;
// This is deliberately not set, as it is not known by the event.
*transact_to = Address::ZERO.into();
*value = U256::ZERO;
*data = zenith_types::mintCall { amount: self.amount(), to: self.rollupRecipient }
.abi_encode()
.into();
*nonce = None;
*chain_id = Some(self.rollup_chain_id());
*access_list = vec![];
*gas_priority_fee = Some(U256::ZERO);
blob_hashes.clear();
max_fee_per_blob_gas.take();
authorization_list.take();
}
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ mod ext;
pub use ext::EvmExtUnchecked;

mod fill;
pub use fill::{Block, Cfg, NoopBlock, NoopCfg, Tx};
pub use fill::{Block, Cfg, DisableGasChecks, DisableNonceCheck, NoopBlock, NoopCfg, Tx};

pub mod journal;

Expand Down

0 comments on commit ed9940d

Please sign in to comment.