Skip to content

Commit

Permalink
feat: allow configuring max initcode size
Browse files Browse the repository at this point in the history
  • Loading branch information
agostbiro authored and Wodann committed Oct 5, 2023
1 parent f14e47a commit af48dcf
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions crates/primitives/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ pub struct CfgEnv {
/// If some it will effects EIP-170: Contract code size limit. Useful to increase this because of tests.
/// By default it is 0x6000 (~25kb).
pub limit_contract_code_size: Option<usize>,
/// Override the max initcode size introduced in EIP-3860. This is useful for testing.
/// By default it's twice the contract code size limit.
pub max_initcode_size: Option<usize>,
/// Disables the coinbase tip during the finalization of the transaction. This is useful for
/// rollups that redirect the tip to the sequencer.
pub disable_coinbase_tip: bool,
Expand Down Expand Up @@ -192,6 +195,7 @@ impl Default for CfgEnv {
spec_id: SpecId::LATEST,
perf_analyse_created_bytecodes: Default::default(),
limit_contract_code_size: None,
max_initcode_size: None,
disable_coinbase_tip: false,
#[cfg(feature = "memory_limit")]
memory_limit: 2u64.pow(32) - 1,
Expand Down Expand Up @@ -296,11 +300,12 @@ impl Env {

// EIP-3860: Limit and meter initcode
if SPEC::enabled(SpecId::SHANGHAI) && is_create {
let max_initcode_size = self
.cfg
.limit_contract_code_size
.map(|limit| limit.saturating_mul(2))
.unwrap_or(MAX_INITCODE_SIZE);
let max_initcode_size = self.cfg.max_initcode_size.unwrap_or_else(|| {
self.cfg
.limit_contract_code_size
.map(|limit| limit.saturating_mul(2))
.unwrap_or(MAX_INITCODE_SIZE)
});
if self.tx.data.len() > max_initcode_size {
return Err(InvalidTransaction::CreateInitcodeSizeLimit);
}
Expand Down

0 comments on commit af48dcf

Please sign in to comment.