Skip to content

Commit

Permalink
Cfg choose create analysis, option on bytecode size limit (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
rakita authored Sep 10, 2022
1 parent 9f1932d commit 0e84424
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 15 deletions.
2 changes: 1 addition & 1 deletion bins/revm-test/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "revm-test"
version = "0.1.0"
edition = "2018"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion bins/revme/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
authors = ["Dragan Rakita <dragan0rakita@gmail.com>"]
edition = "2018"
edition = "2021"
name = "revme"
keywords = ["ethereum", "evm"]
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion crates/revm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
authors = ["Dragan Rakita <dragan0rakita@gmail.com>"]
description = "REVM - Rust Ethereum Virtual Machine"
edition = "2018"
edition = "2021"
keywords = ["no_std", "ethereum", "evm", "revm"]
license = "MIT"
name = "revm"
Expand Down
13 changes: 9 additions & 4 deletions crates/revm/src/evm_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use crate::{
interpreter::{Contract, Interpreter},
journaled_state::{Account, JournaledState, State},
models::SelfDestructResult,
return_ok, return_revert, CallContext, CallInputs, CallScheme, CreateInputs, CreateScheme, Env,
ExecutionResult, Gas, Inspector, Log, Return, Spec,
return_ok, return_revert, AnalysisKind, CallContext, CallInputs, CallScheme, CreateInputs,
CreateScheme, Env, ExecutionResult, Gas, Inspector, Log, Return, Spec,
SpecId::{self, *},
TransactOut, TransactTo, Transfer, KECCAK_EMPTY,
};
Expand Down Expand Up @@ -482,7 +482,7 @@ impl<'a, GSPEC: Spec, DB: Database, const INSPECT: bool> EVMImpl<'a, GSPEC, DB,
// EIP-170: Contract code size limit
// By default limit is 0x6000 (~25kb)
if SPEC::enabled(SPURIOUS_DRAGON)
&& bytes.len() > self.data.env.cfg.limit_contract_code_size
&& bytes.len() > self.data.env.cfg.limit_contract_code_size.unwrap_or(0x6000)
{
self.data.journaled_state.checkpoint_revert(checkpoint);
return (Return::CreateContractLimit, ret, interp.gas, b);
Expand All @@ -505,7 +505,12 @@ impl<'a, GSPEC: Spec, DB: Database, const INSPECT: bool> EVMImpl<'a, GSPEC, DB,
// if we have enought gas
self.data.journaled_state.checkpoint_commit();
// Do analasis of bytecode streight away.
let bytecode = Bytecode::new_raw(bytes).to_analysed::<SPEC>();
let bytecode = match self.data.env.cfg.perf_analyse_created_bytecodes {
AnalysisKind::Raw => Bytecode::new_raw(bytes),
AnalysisKind::Check => Bytecode::new_raw(bytes).to_checked(),
AnalysisKind::Analyse => Bytecode::new_raw(bytes).to_analysed::<SPEC>(),
};

self.data
.journaled_state
.set_code(created_address, bytecode);
Expand Down
23 changes: 17 additions & 6 deletions crates/revm/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,13 @@ pub struct CfgEnv {
/// safe to be set to `true`, depending on the chain.
pub perf_all_precompiles_have_balance: bool,
/// Bytecode that is created with CREATE/CREATE2 is by default analysed and jumptable is created.
/// This is very benefitial for testing and speeds up execution of that bytecode when
pub perf_analyse_created_bytecodes: bool,
/// Effects EIP-170: Contract code size limit. Usefull to increase this because of tests.
/// This is very benefitial for testing and speeds up execution of that bytecode when.
/// It will have side effect if it is enabled in client that switches between forks.
/// Default: Analyse
pub perf_analyse_created_bytecodes: AnalysisKind,
/// If some it will effects EIP-170: Contract code size limit. Usefull to increase this because of tests.
/// By default it is 0x6000 (~25kb).
pub limit_contract_code_size: usize,
pub limit_contract_code_size: Option<usize>,
/// A hard memory limit in bytes beyond which [Memory] cannot be resized.
///
/// In cases where the gas limit may be extraordinarily high, it is recommended to set this to
Expand All @@ -240,14 +242,23 @@ pub struct CfgEnv {
pub memory_limit: u64,
}

#[derive(Clone, Default, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "with-serde", derive(serde::Serialize, serde::Deserialize))]
pub enum AnalysisKind {
Raw,
Check,
#[default]
Analyse,
}

impl Default for CfgEnv {
fn default() -> CfgEnv {
CfgEnv {
chain_id: 1.into(),
spec_id: SpecId::LATEST,
perf_all_precompiles_have_balance: false,
perf_analyse_created_bytecodes: true,
limit_contract_code_size: 0x6000,
perf_analyse_created_bytecodes: Default::default(),
limit_contract_code_size: None,
#[cfg(feature = "memory_limit")]
memory_limit: 2u64.pow(32) - 1,
}
Expand Down
2 changes: 1 addition & 1 deletion crates/revm_precompiles/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
authors = ["Dragan Rakita <dragan0rakita@gmail.com>"]
description = "REVM Precompiles - Ethereum compatible precompiled contracts"
edition = "2018"
edition = "2021"
keywords = ["no_std", "ethereum", "evm", "precompiles"]
license = "MIT"
name = "revm_precompiles"
Expand Down
2 changes: 1 addition & 1 deletion crates/revmjs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
authors = ["Dragan Rakita <dragan0rakita@gmail.com>"]
description = "REVM WASM - Rust Ethereum Virtual Machine Web Assembly lib"
edition = "2018"
edition = "2021"
keywords = ["ethereum", "evm", "rust"]
license = "MIT"
name = "revmjs"
Expand Down

0 comments on commit 0e84424

Please sign in to comment.