Skip to content

Commit ebb5d95

Browse files
FredCoenroyvardhan
authored andcommitted
chore: Move CfgEnv from context-interface to context crate (bluealloy#1910)
* move CfgEnv * crago fmt * remove glitch in matrix * fix docs path
1 parent 984dfb7 commit ebb5d95

File tree

11 files changed

+192
-195
lines changed

11 files changed

+192
-195
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bins/revme/src/cmd/statetest/runner.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ use indicatif::{ProgressBar, ProgressDrawTarget};
77
use inspector::{inspector_handler, inspectors::TracerEip3155, InspectorContext, InspectorMainEvm};
88
use revm::{
99
bytecode::Bytecode,
10-
context::{block::BlockEnv, tx::TxEnv},
10+
context::{block::BlockEnv, cfg::CfgEnv, tx::TxEnv},
1111
context_interface::{
1212
block::calc_excess_blob_gas,
1313
result::{EVMError, ExecutionResult, HaltReason, InvalidTransaction},
14-
Cfg, CfgEnv,
14+
Cfg,
1515
},
1616
database_interface::EmptyDB,
1717
handler::EthHandler,

crates/context/Cargo.toml

+16-8
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ bytecode.workspace = true
3333

3434
# misc
3535
derive-where.workspace = true
36+
cfg-if.workspace = true
3637

3738
# Optional
3839
serde = { version = "1.0", default-features = false, features = [
@@ -44,13 +45,20 @@ serde = { version = "1.0", default-features = false, features = [
4445
database.workspace = true
4546

4647
[features]
48+
# Implementation-specific features
4749
default = ["std"]
48-
std = ["serde?/std"]
49-
serde = [
50-
"dep:serde",
51-
"primitives/serde",
52-
"specification/serde",
53-
"state/serde",
54-
"context-interface/serde",
50+
std = []
51+
dev = [
52+
"memory_limit",
53+
"optional_balance_check",
54+
"optional_block_gas_limit",
55+
"optional_eip3607",
56+
"optional_gas_refund",
57+
"optional_no_base_fee",
5558
]
56-
serde-json = ["serde"]
59+
memory_limit = []
60+
optional_balance_check = []
61+
optional_block_gas_limit = []
62+
optional_eip3607 = []
63+
optional_gas_refund = []
64+
optional_no_base_fee = []

crates/context/interface/Cargo.toml

-18
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ state.workspace = true
2929
specification.workspace = true
3030

3131
# mics
32-
cfg-if.workspace = true
3332
auto_impl.workspace = true
3433

3534
# Optional
@@ -47,20 +46,3 @@ std = ["serde?/std"]
4746
serde = ["dep:serde", "primitives/serde", "specification/serde", "state/serde"]
4847
serde-json = ["serde"]
4948

50-
# Enable additional features for development
51-
# They add functions to Cfg trait.
52-
dev = [
53-
"memory_limit",
54-
"optional_balance_check",
55-
"optional_block_gas_limit",
56-
"optional_eip3607",
57-
"optional_gas_refund",
58-
"optional_no_base_fee",
59-
60-
]
61-
memory_limit = []
62-
optional_balance_check = []
63-
optional_block_gas_limit = []
64-
optional_eip3607 = []
65-
optional_gas_refund = []
66-
optional_no_base_fee = []

crates/context/interface/src/cfg.rs

+1-148
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use auto_impl::auto_impl;
22
use core::fmt::Debug;
33
use core::hash::Hash;
44
use primitives::{TxKind, U256};
5-
use specification::{constants::MAX_CODE_SIZE, hardfork::SpecId};
5+
use specification::hardfork::SpecId;
66

77
#[auto_impl(&, &mut, Box, Arc)]
88
pub trait Cfg {
@@ -39,153 +39,6 @@ pub enum AnalysisKind {
3939
Analyse,
4040
}
4141

42-
/// EVM configuration.
43-
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
44-
#[derive(Clone, Debug, Eq, PartialEq)]
45-
#[non_exhaustive]
46-
pub struct CfgEnv<SPEC: Into<SpecId> = SpecId> {
47-
/// Chain ID of the EVM, it will be compared to the transaction's Chain ID.
48-
/// Chain ID is introduced EIP-155
49-
pub chain_id: u64,
50-
/// Specification for EVM represent the hardfork.
51-
pub spec: SPEC,
52-
/// If some it will effects EIP-170: Contract code size limit. Useful to increase this because of tests.
53-
/// By default it is 0x6000 (~25kb).
54-
pub limit_contract_code_size: Option<usize>,
55-
/// Skips the nonce validation against the account's nonce.
56-
pub disable_nonce_check: bool,
57-
/// A hard memory limit in bytes beyond which [crate::result::OutOfGasError::Memory] cannot be resized.
58-
///
59-
/// In cases where the gas limit may be extraordinarily high, it is recommended to set this to
60-
/// a sane value to prevent memory allocation panics. Defaults to `2^32 - 1` bytes per
61-
/// EIP-1985.
62-
#[cfg(feature = "memory_limit")]
63-
pub memory_limit: u64,
64-
/// Skip balance checks if true. Adds transaction cost to balance to ensure execution doesn't fail.
65-
#[cfg(feature = "optional_balance_check")]
66-
pub disable_balance_check: bool,
67-
/// There are use cases where it's allowed to provide a gas limit that's higher than a block's gas limit. To that
68-
/// end, you can disable the block gas limit validation.
69-
/// By default, it is set to `false`.
70-
#[cfg(feature = "optional_block_gas_limit")]
71-
pub disable_block_gas_limit: bool,
72-
/// EIP-3607 rejects transactions from senders with deployed code. In development, it can be desirable to simulate
73-
/// calls from contracts, which this setting allows.
74-
/// By default, it is set to `false`.
75-
#[cfg(feature = "optional_eip3607")]
76-
pub disable_eip3607: bool,
77-
/// Disables all gas refunds. This is useful when using chains that have gas refunds disabled e.g. Avalanche.
78-
/// Reasoning behind removing gas refunds can be found in EIP-3298.
79-
/// By default, it is set to `false`.
80-
#[cfg(feature = "optional_gas_refund")]
81-
pub disable_gas_refund: bool,
82-
/// Disables base fee checks for EIP-1559 transactions.
83-
/// This is useful for testing method calls with zero gas price.
84-
/// By default, it is set to `false`.
85-
#[cfg(feature = "optional_no_base_fee")]
86-
pub disable_base_fee: bool,
87-
}
88-
89-
impl CfgEnv {
90-
pub fn with_chain_id(mut self, chain_id: u64) -> Self {
91-
self.chain_id = chain_id;
92-
self
93-
}
94-
}
95-
96-
impl<SPEC: Into<SpecId> + Copy> Cfg for CfgEnv<SPEC> {
97-
type Spec = SPEC;
98-
99-
fn chain_id(&self) -> u64 {
100-
self.chain_id
101-
}
102-
103-
fn spec(&self) -> Self::Spec {
104-
self.spec
105-
}
106-
107-
fn max_code_size(&self) -> usize {
108-
self.limit_contract_code_size.unwrap_or(MAX_CODE_SIZE)
109-
}
110-
111-
fn is_eip3607_disabled(&self) -> bool {
112-
cfg_if::cfg_if! {
113-
if #[cfg(feature = "optional_eip3607")] {
114-
self.disable_eip3607
115-
} else {
116-
false
117-
}
118-
}
119-
}
120-
121-
fn is_balance_check_disabled(&self) -> bool {
122-
cfg_if::cfg_if! {
123-
if #[cfg(feature = "optional_balance_check")] {
124-
self.disable_balance_check
125-
} else {
126-
false
127-
}
128-
}
129-
}
130-
131-
fn is_gas_refund_disabled(&self) -> bool {
132-
cfg_if::cfg_if! {
133-
if #[cfg(feature = "optional_gas_refund")] {
134-
self.disable_gas_refund
135-
} else {
136-
false
137-
}
138-
}
139-
}
140-
141-
fn is_block_gas_limit_disabled(&self) -> bool {
142-
cfg_if::cfg_if! {
143-
if #[cfg(feature = "optional_block_gas_limit")] {
144-
self.disable_block_gas_limit
145-
} else {
146-
false
147-
}
148-
}
149-
}
150-
151-
fn is_nonce_check_disabled(&self) -> bool {
152-
self.disable_nonce_check
153-
}
154-
155-
fn is_base_fee_check_disabled(&self) -> bool {
156-
cfg_if::cfg_if! {
157-
if #[cfg(feature = "optional_no_base_fee")] {
158-
self.disable_base_fee
159-
} else {
160-
false
161-
}
162-
}
163-
}
164-
}
165-
166-
impl Default for CfgEnv {
167-
fn default() -> Self {
168-
Self {
169-
chain_id: 1,
170-
limit_contract_code_size: None,
171-
spec: SpecId::PRAGUE,
172-
disable_nonce_check: false,
173-
#[cfg(feature = "memory_limit")]
174-
memory_limit: (1 << 32) - 1,
175-
#[cfg(feature = "optional_balance_check")]
176-
disable_balance_check: false,
177-
#[cfg(feature = "optional_block_gas_limit")]
178-
disable_block_gas_limit: false,
179-
#[cfg(feature = "optional_eip3607")]
180-
disable_eip3607: false,
181-
#[cfg(feature = "optional_gas_refund")]
182-
disable_gas_refund: false,
183-
#[cfg(feature = "optional_no_base_fee")]
184-
disable_base_fee: false,
185-
}
186-
}
187-
}
188-
18942
/// Transaction destination
19043
pub type TransactTo = TxKind;
19144

crates/context/interface/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub mod result;
1313
pub mod transaction;
1414

1515
pub use block::{Block, BlockGetter};
16-
pub use cfg::{Cfg, CfgEnv, CfgGetter, CreateScheme, TransactTo};
16+
pub use cfg::{Cfg, CfgGetter, CreateScheme, TransactTo};
1717
pub use database_interface::{DBErrorMarker, Database, DatabaseGetter};
1818
pub use errors::ErrorGetter;
1919
pub use journaled_state::{JournalStateGetter, JournalStateGetterDBError, JournaledState};

0 commit comments

Comments
 (0)