Skip to content
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

fix: max gas allowed per transaction #940

Merged
merged 1 commit into from
May 28, 2024
Merged
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
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
Loading