use evm_interpreter::runtime::RuntimeConfig;
#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct Config {
pub runtime: RuntimeConfig,
pub eip2_no_empty_contract: bool,
pub eip2_create_transaction_increase: bool,
pub eip1884_trie_repricing: bool,
pub eip2200_sstore_gas_metering: bool,
pub eip2200_sstore_revert_under_stipend: bool,
pub eip2929_increase_state_access_gas: bool,
pub eip3529_decrease_clears_refund: bool,
pub eip3541_disallow_executable_format: bool,
pub eip150_gas_increase: bool,
pub eip150_no_err_on_call_with_more_gas: bool,
pub eip150_call_l64_after_gas: bool,
pub eip161_create_increase_nonce: bool,
pub eip170_create_contract_limit: bool,
pub eip3860_max_initcode_size: bool,
pub eip7_delegate_call: bool,
pub eip1014_create2: bool,
pub eip140_revert: bool,
pub eip160_exp_increase: bool,
pub eip211_return_data: bool,
pub eip214_static_call: bool,
pub eip145_bitwise_shifting: bool,
pub eip1344_chain_id: bool,
pub eip1884_self_balance: bool,
pub eip1052_ext_code_hash: bool,
pub eip3198_base_fee: bool,
pub eip3855_push0: bool,
pub eip1153_transient_storage: bool,
pub eip5656_mcopy: bool,
pub eip1559_fee_market: bool,
pub eip2028_transaction_calldata_decrease: bool,
pub eip198_modexp_precompile: bool,
pub eip196_ec_add_mul_precompile: bool,
pub eip197_ec_pairing_precompile: bool,
pub eip152_blake_2f_precompile: bool,
pub eip1108_ec_add_mul_pairing_decrease: bool,
pub eip2565_lower_modexp: bool,
pub eip2930_access_list: bool,
pub eip4844_shard_blob: bool,
pub eip7516_blob_base_fee: bool,
pub eip7623_calldata_floor: bool,
}
impl Config {
pub const fn frontier() -> Config {
Config {
runtime: RuntimeConfig::frontier(),
eip2_no_empty_contract: false,
eip2_create_transaction_increase: false,
eip2200_sstore_gas_metering: false,
eip2200_sstore_revert_under_stipend: false,
eip2929_increase_state_access_gas: false,
eip3529_decrease_clears_refund: false,
eip3541_disallow_executable_format: false,
eip150_no_err_on_call_with_more_gas: false,
eip161_create_increase_nonce: false,
eip150_call_l64_after_gas: false,
eip170_create_contract_limit: false,
eip3860_max_initcode_size: false,
eip7_delegate_call: false,
eip1014_create2: false,
eip140_revert: false,
eip211_return_data: false,
eip145_bitwise_shifting: false,
eip1344_chain_id: false,
eip1884_self_balance: false,
eip1052_ext_code_hash: false,
eip3198_base_fee: false,
eip3855_push0: false,
eip1153_transient_storage: false,
eip5656_mcopy: false,
eip1559_fee_market: false,
eip198_modexp_precompile: false,
eip196_ec_add_mul_precompile: false,
eip197_ec_pairing_precompile: false,
eip152_blake_2f_precompile: false,
eip150_gas_increase: false,
eip160_exp_increase: false,
eip1884_trie_repricing: false,
eip214_static_call: false,
eip1108_ec_add_mul_pairing_decrease: false,
eip2028_transaction_calldata_decrease: false,
eip2565_lower_modexp: false,
eip2930_access_list: false,
eip4844_shard_blob: false,
eip7516_blob_base_fee: false,
eip7623_calldata_floor: false,
}
}
pub const fn homestead() -> Config {
let mut config = Self::frontier();
config.eip2_no_empty_contract = true;
config.eip2_create_transaction_increase = true;
config.eip7_delegate_call = true;
config
}
pub const fn tangerine_whistle() -> Config {
let mut config = Self::homestead();
config.eip150_gas_increase = true;
config.eip150_no_err_on_call_with_more_gas = true;
config.eip150_call_l64_after_gas = true;
config
}
pub const fn spurious_dragon() -> Config {
let mut config = Self::tangerine_whistle();
config.runtime.eip161_empty_check = true;
config.eip161_create_increase_nonce = true;
config.eip160_exp_increase = true;
config.eip170_create_contract_limit = true;
config
}
pub const fn byzantium() -> Config {
let mut config = Self::spurious_dragon();
config.eip140_revert = true;
config.eip196_ec_add_mul_precompile = true;
config.eip197_ec_pairing_precompile = true;
config.eip198_modexp_precompile = true;
config.eip211_return_data = true;
config.eip214_static_call = true;
config
}
pub const fn petersburg() -> Config {
let mut config = Self::byzantium();
config.eip145_bitwise_shifting = true;
config.eip1014_create2 = true;
config.eip1052_ext_code_hash = true;
config
}
pub const fn istanbul() -> Config {
let mut config = Self::petersburg();
config.eip152_blake_2f_precompile = true;
config.eip1108_ec_add_mul_pairing_decrease = true;
config.eip1344_chain_id = true;
config.eip1884_trie_repricing = true;
config.eip1884_self_balance = true;
config.eip2028_transaction_calldata_decrease = true;
config.eip2200_sstore_gas_metering = true;
config.eip2200_sstore_revert_under_stipend = true;
config
}
pub const fn berlin() -> Config {
let mut config = Self::istanbul();
config.eip2565_lower_modexp = true;
config.eip2929_increase_state_access_gas = true;
config.eip2930_access_list = true;
config
}
pub const fn london() -> Config {
let mut config = Self::berlin();
config.eip1559_fee_market = true;
config.eip3198_base_fee = true;
config.eip3529_decrease_clears_refund = true;
config.eip3541_disallow_executable_format = true;
config
}
pub const fn shanghai() -> Config {
let mut config = Self::london();
config.runtime.eip3651_warm_coinbase_address = true;
config.eip3855_push0 = true;
config.eip3860_max_initcode_size = true;
config
}
pub const fn cancun() -> Config {
let mut config = Self::shanghai();
config.eip1153_transient_storage = true;
config.eip5656_mcopy = true;
config.runtime.eip6780_suicide_only_in_same_tx = true;
config.eip4844_shard_blob = true;
config.eip7516_blob_base_fee = true;
config
}
pub const fn prague() -> Config {
let mut config = Self::cancun();
config.eip7623_calldata_floor = true;
config
}
pub fn gas_ext_code(&self) -> u64 {
if self.eip150_gas_increase { 700 } else { 20 }
}
pub fn gas_ext_code_hash(&self) -> u64 {
if self.eip1884_trie_repricing {
700
} else {
400
}
}
pub fn gas_sstore_set(&self) -> u64 {
20000
}
pub fn gas_sstore_reset(&self) -> u64 {
if self.eip2929_increase_state_access_gas {
2900
} else {
5000
}
}
pub fn refund_sstore_clears(&self) -> i64 {
if self.eip3529_decrease_clears_refund {
4800
} else {
15000
}
}
pub fn max_refund_quotient(&self) -> u64 {
if self.eip3529_decrease_clears_refund {
5
} else {
2
}
}
pub fn gas_balance(&self) -> u64 {
if self.eip1884_trie_repricing {
700
} else if self.eip150_gas_increase {
400
} else {
20
}
}
pub fn gas_sload(&self) -> u64 {
if self.eip2929_increase_state_access_gas {
100
} else if self.eip2200_sstore_gas_metering {
800
} else if self.eip150_gas_increase {
200
} else {
50
}
}
pub fn gas_sload_cold(&self) -> u64 {
if self.eip2929_increase_state_access_gas {
2100
} else {
0
}
}
pub fn gas_suicide(&self) -> u64 {
if self.eip150_gas_increase { 5000 } else { 0 }
}
pub fn gas_suicide_new_account(&self) -> u64 {
if self.eip150_gas_increase { 25000 } else { 0 }
}
pub fn gas_call(&self) -> u64 {
if self.eip150_gas_increase { 700 } else { 40 }
}
pub fn gas_expbyte(&self) -> u64 {
if self.eip160_exp_increase { 50 } else { 10 }
}
pub fn gas_transaction_create(&self) -> u64 {
if self.eip2_create_transaction_increase {
53000
} else {
21000
}
}
pub fn gas_transaction_call(&self) -> u64 {
21000
}
pub fn gas_transaction_zero_data(&self) -> u64 {
4
}
pub fn gas_transaction_non_zero_data(&self) -> u64 {
if self.eip2028_transaction_calldata_decrease {
16
} else {
68
}
}
pub fn gas_floor_transaction_zero_data(&self) -> u64 {
if self.eip7623_calldata_floor { 10 } else { 0 }
}
pub fn gas_floor_transaction_non_zero_data(&self) -> u64 {
if self.eip7623_calldata_floor { 40 } else { 0 }
}
pub fn gas_access_list_address(&self) -> u64 {
if self.eip2930_access_list { 2400 } else { 0 }
}
pub fn gas_access_list_storage_key(&self) -> u64 {
if self.eip2930_access_list { 1900 } else { 0 }
}
pub fn gas_account_access_cold(&self) -> u64 {
if self.eip2929_increase_state_access_gas {
2600
} else {
0
}
}
pub fn gas_storage_read_warm(&self) -> u64 {
if self.eip2929_increase_state_access_gas {
100
} else {
0
}
}
pub fn stack_limit(&self) -> usize {
1024
}
pub fn memory_limit(&self) -> usize {
usize::MAX
}
pub fn call_stack_limit(&self) -> usize {
1024
}
pub fn call_stipend(&self) -> u64 {
2300
}
pub fn max_initcode_size(&self) -> Option<usize> {
if self.eip3860_max_initcode_size {
Some(0xc000)
} else {
None
}
}
pub fn create_contract_limit(&self) -> Option<usize> {
if self.eip170_create_contract_limit {
Some(0x6000)
} else {
None
}
}
}