Skip to content

feat: disable gas checks #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "trevm"
version = "0.10.1"
version = "0.11.0"
rust-version = "1.79.0"
edition = "2021"
authors = ["init4"]
Expand Down Expand Up @@ -30,14 +30,11 @@ redundant-clone = "warn"
alloy-primitives = "0.8"
alloy-sol-types = "0.8"

alloy-consensus = { version = "0.3", features = ["k256"] }
alloy-eips = "0.3"
alloy-rpc-types-eth = "0.3"
alloy-rpc-types-mev = "0.3"
alloy = { version = "=0.3.6", features = ["rpc-types-mev"] }

revm = { version = "14.0.0", default-features = false, features = ["std"] }

zenith-types = "0.7"
zenith-types = "0.8"

thiserror = "1.0"
alloy-rlp = "0.3"
Expand All @@ -46,13 +43,6 @@ alloy-rlp = "0.3"
revm = { version = "14.0.0", features = ["test-utils", "serde-json", "std", "alloydb"] }
tokio = { version = "1.39", features = ["macros", "rt-multi-thread"] }

# alloydb
alloy-provider = "0.3"
alloy-transport = "0.3"

alloy-signer = { version = "0.3", default-features = false }
alloy-signer-local = { version = "0.3", default-features = false }

alloy-rlp = { version = "0.3", default-features = false }

serde_json = { version = "1.0", default-features = false, features = ["alloc"] }
Expand Down Expand Up @@ -95,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",
]

14 changes: 8 additions & 6 deletions examples/basic_transact.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
//! Simple TREVM example that demonstrates how to execute a transaction on a contract.
//! It simply loads the contract bytecode and executes a transaction.

use revm::{
inspector_handle_register,
inspectors::TracerEip3155,
primitives::{hex, AccountInfo, Address, Bytecode, TransactTo, U256},
EvmBuilder, InMemoryDB,
use trevm::{
revm::{
inspector_handle_register,
inspectors::TracerEip3155,
primitives::{hex, AccountInfo, Address, Bytecode, TransactTo, U256},
EvmBuilder, InMemoryDB,
},
trevm_aliases, NoopBlock, NoopCfg, TrevmBuilder, Tx,
};
use trevm::{trevm_aliases, NoopBlock, NoopCfg, TrevmBuilder, Tx};

/// Foundry's default Counter.sol contract bytecode.
const CONTRACT_BYTECODE: &str = "0x6080604052348015600f57600080fd5b5060043610603c5760003560e01c80633fb5c1cb1460415780638381f58a146053578063d09de08a14606d575b600080fd5b6051604c3660046083565b600055565b005b605b60005481565b60405190815260200160405180910390f35b6051600080549080607c83609b565b9190505550565b600060208284031215609457600080fd5b5035919050565b60006001820160ba57634e487b7160e01b600052601160045260246000fd5b506001019056fea2646970667358221220091e48831e9eee32d4571d6291233a4fdaaa34b7dced8770f36f5368be825c5264736f6c63430008190033";
Expand Down
19 changes: 9 additions & 10 deletions examples/fork_ref_transact.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
//! This example demonstrates how to query storage slots of a contract, using AlloyDB.

use alloy_eips::BlockId;
use alloy_primitives::Address;
use alloy_provider::ProviderBuilder;
use alloy_sol_types::sol;
use alloy_sol_types::SolCall;
use revm::{
db::{AlloyDB, CacheDB},
primitives::{address, TxKind, U256},
Evm,
use alloy::{eips::BlockId, providers::ProviderBuilder};
use alloy_primitives::{address, Address, TxKind, U256};
use alloy_sol_types::{sol, SolCall};
use trevm::{
revm::{
db::{AlloyDB, CacheDB},
Evm,
},
NoopBlock, NoopCfg, TrevmBuilder, Tx,
};
use trevm::{NoopBlock, NoopCfg, TrevmBuilder, Tx};

sol! {
#[allow(missing_docs)]
Expand Down
16 changes: 9 additions & 7 deletions src/driver/alloy.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
use crate::{
trevm_bail, trevm_ensure, unwrap_or_trevm_err, Block, BundleDriver, DriveBundleResult,
};
use alloy_consensus::{Transaction, TxEip4844Variant, TxEnvelope};
use alloy_eips::{eip2718::Decodable2718, BlockNumberOrTag};
use alloy_primitives::{bytes::Buf, keccak256, Address, Bytes, TxKind, U256};
use alloy_rpc_types_mev::{
EthBundleHash, EthCallBundle, EthCallBundleResponse, EthCallBundleTransactionResult,
EthSendBundle,
use alloy::{
consensus::{Transaction, TxEip4844Variant, TxEnvelope},
eips::{eip2718::Decodable2718, BlockNumberOrTag},
rpc::types::mev::{
EthBundleHash, EthCallBundle, EthCallBundleResponse, EthCallBundleTransactionResult,
EthSendBundle,
},
};
use alloy_primitives::{bytes::Buf, keccak256, Address, Bytes, TxKind, U256};
use revm::primitives::{EVMError, ExecutionResult, MAX_BLOB_GAS_PER_BLOCK};
use thiserror::Error;

Expand All @@ -34,7 +36,7 @@ pub enum BundleError<Db: revm::Database> {
UnsupportedTransactionType,
/// An error occurred while decoding a transaction contained in the bundle.
#[error("transaction decoding error")]
TransactionDecodingError(#[from] alloy_eips::eip2718::Eip2718Error),
TransactionDecodingError(#[from] alloy::eips::eip2718::Eip2718Error),
/// An error ocurred while recovering the sender of a transaction
#[error("transaction sender recovery error")]
TransactionSenderRecoveryError(#[from] alloy_primitives::SignatureError),
Expand Down
28 changes: 14 additions & 14 deletions src/fill/alloy.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use alloy_consensus::Signed;
use alloy::consensus::Signed;
use alloy_primitives::U256;
use revm::primitives::{BlobExcessGasAndPrice, BlockEnv, TxEnv};

use crate::{Block, Tx};

impl Tx for Signed<alloy_consensus::TxLegacy> {
impl Tx for Signed<alloy::consensus::TxLegacy> {
fn fill_tx_env(&self, tx_env: &mut revm::primitives::TxEnv) {
let TxEnv {
caller,
Expand Down Expand Up @@ -37,7 +37,7 @@ impl Tx for Signed<alloy_consensus::TxLegacy> {
}
}

impl Tx for Signed<alloy_consensus::TxEip2930> {
impl Tx for Signed<alloy::consensus::TxEip2930> {
fn fill_tx_env(&self, tx_env: &mut revm::primitives::TxEnv) {
let TxEnv {
caller,
Expand Down Expand Up @@ -70,7 +70,7 @@ impl Tx for Signed<alloy_consensus::TxEip2930> {
}
}

impl Tx for Signed<alloy_consensus::TxEip1559> {
impl Tx for Signed<alloy::consensus::TxEip1559> {
fn fill_tx_env(&self, tx_env: &mut revm::primitives::TxEnv) {
let TxEnv {
caller,
Expand Down Expand Up @@ -103,7 +103,7 @@ impl Tx for Signed<alloy_consensus::TxEip1559> {
}
}

impl Tx for Signed<alloy_consensus::TxEip4844> {
impl Tx for Signed<alloy::consensus::TxEip4844> {
fn fill_tx_env(&self, tx_env: &mut revm::primitives::TxEnv) {
let TxEnv {
caller,
Expand Down Expand Up @@ -136,7 +136,7 @@ impl Tx for Signed<alloy_consensus::TxEip4844> {
}
}

impl Tx for Signed<alloy_consensus::TxEip4844WithSidecar> {
impl Tx for Signed<alloy::consensus::TxEip4844WithSidecar> {
fn fill_tx_env(&self, tx_env: &mut revm::primitives::TxEnv) {
let TxEnv {
caller,
Expand Down Expand Up @@ -169,7 +169,7 @@ impl Tx for Signed<alloy_consensus::TxEip4844WithSidecar> {
}
}

impl Tx for Signed<alloy_consensus::TxEip4844Variant> {
impl Tx for Signed<alloy::consensus::TxEip4844Variant> {
fn fill_tx_env(&self, tx_env: &mut revm::primitives::TxEnv) {
let TxEnv {
caller,
Expand All @@ -187,8 +187,8 @@ impl Tx for Signed<alloy_consensus::TxEip4844Variant> {
authorization_list,
} = tx_env;
let tx = match self.tx() {
alloy_consensus::TxEip4844Variant::TxEip4844(tx) => tx,
alloy_consensus::TxEip4844Variant::TxEip4844WithSidecar(tx) => &tx.tx,
alloy::consensus::TxEip4844Variant::TxEip4844(tx) => tx,
alloy::consensus::TxEip4844Variant::TxEip4844WithSidecar(tx) => &tx.tx,
};
*caller = self.recover_signer().unwrap();
*gas_limit = tx.gas_limit as u64;
Expand All @@ -206,7 +206,7 @@ impl Tx for Signed<alloy_consensus::TxEip4844Variant> {
}
}

impl Tx for alloy_consensus::TxEnvelope {
impl Tx for alloy::consensus::TxEnvelope {
fn fill_tx_env(&self, tx_env: &mut revm::primitives::TxEnv) {
match self {
Self::Legacy(t) => t.fill_tx_env(tx_env),
Expand All @@ -218,7 +218,7 @@ impl Tx for alloy_consensus::TxEnvelope {
}
}

impl Block for alloy_consensus::Header {
impl Block for alloy::consensus::Header {
fn fill_block_env(&self, block_env: &mut revm::primitives::BlockEnv) {
let BlockEnv {
number,
Expand Down Expand Up @@ -249,7 +249,7 @@ impl Block for alloy_consensus::Header {
}
}

impl Block for alloy_rpc_types_eth::Header {
impl Block for alloy::rpc::types::eth::Header {
fn fill_block_env(&self, block_env: &mut revm::primitives::BlockEnv) {
let BlockEnv {
number,
Expand All @@ -273,7 +273,7 @@ impl Block for alloy_rpc_types_eth::Header {
}
}

impl<T> Block for alloy_rpc_types_eth::Block<T> {
impl<T> Block for alloy::rpc::types::eth::Block<T> {
fn fill_block_env(&self, block_env: &mut revm::primitives::BlockEnv) {
self.header.fill_block_env(block_env);
}
Expand All @@ -286,7 +286,7 @@ impl<T> Block for alloy_rpc_types_eth::Block<T> {
#[cfg(test)]
mod tests {
use crate::{NoopBlock, NoopCfg, TrevmBuilder};
use alloy_consensus::{Header, TxEnvelope, EMPTY_ROOT_HASH};
use alloy::consensus::{Header, TxEnvelope, EMPTY_ROOT_HASH};

use alloy_rlp::Decodable;

Expand Down
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;
}
}
2 changes: 1 addition & 1 deletion src/fill/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub trait Cfg {

#[cfg(test)]
mod test {
use alloy_consensus::constants::GWEI_TO_WEI;
use alloy::consensus::constants::GWEI_TO_WEI;
use alloy_primitives::{B256, U256};
use revm::primitives::{BlobExcessGasAndPrice, BlockEnv, CfgEnv};

Expand Down
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd also add the nonce validation comment that exists in the above Tx impl

*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();
}
}
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,8 @@
//! [`eip6110`]: crate::system::eip6110
//! [`eip7002`]: crate::system::eip7002
//! [`eip7251`]: crate::system::eip7251
//! [`WithdrawalRequest`]: alloy_eips::eip7002::WithdrawalRequest
//! [`ConsolidationRequest`]: alloy_eips::eip7251::ConsolidationRequest
//! [`WithdrawalRequest`]: alloy::eips::eip7002::WithdrawalRequest
//! [`ConsolidationRequest`]: alloy::eips::eip7251::ConsolidationRequest

#![doc(
html_logo_url = "https://raw.githubusercontent.com/alloy-rs/core/main/assets/alloy.jpg",
Expand All @@ -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
6 changes: 4 additions & 2 deletions src/lifecycle/output.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use alloy_consensus::{ReceiptEnvelope, TxReceipt};
use alloy_eips::eip6110::DepositRequest;
use alloy::{
consensus::{ReceiptEnvelope, TxReceipt},
eips::eip6110::DepositRequest,
};
use alloy_primitives::{Address, Bloom, Log};
use std::sync::OnceLock;

Expand Down
Loading