Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
simplify
  • Loading branch information
rakita committed Jul 12, 2024
commit 63d5b997b0bb2ee6ae51b0eac199f4a66b851211
10 changes: 8 additions & 2 deletions crates/primitives/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ pub use handler_cfg::{CfgEnvWithHandlerCfg, EnvWithHandlerCfg, HandlerCfg};

use crate::{
calc_blob_gasprice, AccessListItem, Account, Address, Bytes, InvalidHeader, InvalidTransaction,
Spec, SpecId, B256, GAS_PER_BLOB, KECCAK_EMPTY, MAX_BLOB_NUMBER_PER_BLOCK, MAX_INITCODE_SIZE,
U256, VERSIONED_HASH_VERSION_KZG,
Spec, SpecId, B256, GAS_PER_BLOB, KECCAK_EMPTY, MAX_BLOB_NUMBER_PER_BLOCK, MAX_CODE_SIZE,
MAX_INITCODE_SIZE, U256, VERSIONED_HASH_VERSION_KZG,
};
use alloy_primitives::TxKind;
use core::cmp::{min, Ordering};
Expand Down Expand Up @@ -323,6 +323,12 @@ pub struct CfgEnv {
}

impl CfgEnv {
/// Returns max code size from [`Self::limit_contract_code_size`] if set
/// or default [`MAX_CODE_SIZE`] value.
pub fn max_code_size(&self) -> usize {
self.limit_contract_code_size.unwrap_or(MAX_CODE_SIZE)
}

pub fn with_chain_id(mut self, chain_id: u64) -> Self {
self.chain_id = chain_id;
self
Expand Down
15 changes: 6 additions & 9 deletions crates/revm/src/context/inner_evm_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
db::Database,
interpreter::{
analysis::to_analysed, gas, return_ok, InstructionResult, InterpreterResult,
LoadAccountResult, SStoreResult, SelfDestructResult, MAX_CODE_SIZE,
LoadAccountResult, SStoreResult, SelfDestructResult,
},
journaled_state::JournaledState,
primitives::{
Expand Down Expand Up @@ -276,8 +276,7 @@ impl<DB: Database> InnerEvmContext<DB> {
return;
}

let max_code_size = self.cfg().limit_contract_code_size.unwrap_or(MAX_CODE_SIZE);
if interpreter_result.output.len() > max_code_size {
if interpreter_result.output.len() > self.cfg().max_code_size() {
self.journaled_state.checkpoint_revert(journal_checkpoint);
interpreter_result.result = InstructionResult::CreateContractSizeLimit;
return;
Expand Down Expand Up @@ -335,19 +334,17 @@ impl<DB: Database> InnerEvmContext<DB> {
// if ok, check contract creation limit and calculate gas deduction on output len.
//
// EIP-3541: Reject new contract code starting with the 0xEF byte
if SPEC::enabled(LONDON)
&& !interpreter_result.output.is_empty()
&& interpreter_result.output.first() == Some(&0xEF)
{
if SPEC::enabled(LONDON) && interpreter_result.output.first() == Some(&0xEF) {
self.journaled_state.checkpoint_revert(journal_checkpoint);
interpreter_result.result = InstructionResult::CreateContractStartingWithEF;
return;
}

// EIP-170: Contract code size limit
// By default limit is 0x6000 (~25kb)
let max_code_size = self.cfg().limit_contract_code_size.unwrap_or(MAX_CODE_SIZE);
if SPEC::enabled(SPURIOUS_DRAGON) && interpreter_result.output.len() > max_code_size {
if SPEC::enabled(SPURIOUS_DRAGON)
&& interpreter_result.output.len() > self.cfg().max_code_size()
{
self.journaled_state.checkpoint_revert(journal_checkpoint);
interpreter_result.result = InstructionResult::CreateContractSizeLimit;
return;
Expand Down