Skip to content

Commit

Permalink
fix: max gas allowed per transaction (#940)
Browse files Browse the repository at this point in the history
  • Loading branch information
dinhani-cw authored May 28, 2024
1 parent 1a861cf commit dd874b1
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/eth/evm/revm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//! interacting with the project's storage backend to manage state. `Revm` embodies the practical application
//! of the `Evm` trait, serving as a bridge between Ethereum's abstract operations and Stratus's storage mechanisms.
use std::cmp::min;
use std::collections::HashMap;
use std::collections::HashSet;
use std::sync::Arc;
Expand Down Expand Up @@ -54,6 +55,9 @@ use crate::ext::OptionExt;
#[cfg(feature = "metrics")]
use crate::infra::metrics;

/// Maximum gas limit allowed for a transaction. Prevents a transaction from consuming too many resources.
const GAS_MAX_LIMIT: u64 = 1_000_000_000;

/// Implementation of EVM using [`revm`](https://crates.io/crates/revm).
pub struct Revm {
evm: RevmEvm<'static, (), RevmSession>,
Expand Down Expand Up @@ -128,7 +132,7 @@ impl Evm for Revm {
Some(contract) => TransactTo::Call(contract.into()),
None => TransactTo::Create(CreateScheme::Create),
};
tx_env.gas_limit = input.gas_limit.into();
tx_env.gas_limit = min(input.gas_limit.into(), GAS_MAX_LIMIT);
tx_env.gas_price = input.gas_price.into();
tx_env.chain_id = input.chain_id.map_into();
tx_env.nonce = input.nonce.map_into();
Expand Down

0 comments on commit dd874b1

Please sign in to comment.