Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Refactore transact_create functions #66

Merged
merged 5 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ keywords.workspace = true
edition.workspace = true

[workspace.dependencies]
evm = { version = "0.46.0", path = "." }
evm-core = { version = "0.46.0", path = "core", default-features = false }
evm-gasometer = { version = "0.46.0", path = "gasometer", default-features = false }
evm-runtime = { version = "0.46.0", path = "runtime", default-features = false }
evm = { version = "0.46.1", path = "." }
evm-core = { version = "0.46.1", path = "core", default-features = false }
evm-gasometer = { version = "0.46.1", path = "gasometer", default-features = false }
evm-runtime = { version = "0.46.1", path = "runtime", default-features = false }
primitive-types = { version = "0.12", default-features = false }
auto_impl = "1.0"
sha3 = { version = "0.10", default-features = false }
Expand Down Expand Up @@ -88,7 +88,7 @@ create-fixed = []
print-debug = ["evm-gasometer/print-debug"]

[workspace.package]
version = "0.46.0"
version = "0.46.1"
license = "Apache-2.0"
authors = ["Aurora Labs <[email protected]>", "Wei Tang <[email protected]>", "Parity Technologies <[email protected]>"]
description = "Portable Ethereum Virtual Machine implementation written in pure Rust."
Expand Down
60 changes: 23 additions & 37 deletions src/executor/stack/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,18 +519,12 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>
gas_limit: u64,
access_list: Vec<(H160, Vec<H256>)>, // See EIP-2930
) -> (ExitReason, Vec<u8>) {
if self.nonce(caller) >= U64_MAX {
aleksuss marked this conversation as resolved.
Show resolved Hide resolved
return (ExitError::MaxNonce.into(), Vec::new());
}

let address = self.create_address(CreateScheme::Legacy { caller });

event!(TransactCreate {
caller,
value,
init_code: &init_code,
gas_limit,
address,
address: self.create_address(CreateScheme::Legacy { caller }),
});

if let Some(limit) = self.config.max_initcode_size {
Expand All @@ -545,7 +539,7 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>
}

// Initialize initial addresses for EIP-2929
self.initialize_addresses(caller, address, access_list);
self.initialize_addresses(&[caller], access_list);

match self.create_inner(
caller,
Expand Down Expand Up @@ -574,24 +568,22 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>
value: U256,
init_code: Vec<u8>,
gas_limit: u64,
access_list: Vec<(H160, Vec<H256>)>, // See EIP-2930
access_list: &[(H160, Vec<H256>)], // See EIP-2930
) -> (ExitReason, Vec<u8>) {
let address = self.create_address(CreateScheme::Fixed(address));

event!(TransactCreate {
caller,
value,
init_code: &init_code,
gas_limit,
address
address: self.create_address(CreateScheme::Fixed(address)),
});

if let Err(e) = self.record_create_transaction_cost(&init_code, &access_list) {
return emit_exit!(e.into(), Vec::new());
}

// Initialize initial addresses for EIP-2929
self.initialize_addresses(caller, address, access_list);
self.initialize_addresses(&[caller], access_list);
mrLSD marked this conversation as resolved.
Show resolved Hide resolved

match self.create_inner(
caller,
Expand All @@ -601,7 +593,7 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>
Some(gas_limit),
false,
) {
Capture::Exit((s, _, v)) => emit_exit!(s, v),
Capture::Exit((s, v)) => emit_exit!(s, v),
Capture::Trap(rt) => {
let mut cs: SmallVec<[TaggedRuntime<'_>; DEFAULT_CALL_STACK_CAPACITY]> =
smallvec!(rt.0);
Expand All @@ -621,34 +613,33 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>
gas_limit: u64,
access_list: Vec<(H160, Vec<H256>)>, // See EIP-2930
) -> (ExitReason, Vec<u8>) {
if let Some(limit) = self.config.max_initcode_size {
if init_code.len() > limit {
self.state.metadata_mut().gasometer.fail();
return emit_exit!(ExitError::CreateContractLimit.into(), Vec::new());
}
}

let code_hash = H256::from_slice(Keccak256::digest(&init_code).as_slice());
let address = self.create_address(CreateScheme::Create2 {
caller,
code_hash,
salt,
});
event!(TransactCreate2 {
caller,
value,
init_code: &init_code,
salt,
gas_limit,
address,
address: self.create_address(CreateScheme::Create2 {
caller,
code_hash,
salt,
}),
});

if let Some(limit) = self.config.max_initcode_size {
if init_code.len() > limit {
self.state.metadata_mut().gasometer.fail();
return emit_exit!(ExitError::CreateContractLimit.into(), Vec::new());
}
}

if let Err(e) = self.record_create_transaction_cost(&init_code, &access_list) {
return emit_exit!(e.into(), Vec::new());
}

// Initialize initial addresses for EIP-2929
self.initialize_addresses(caller, address, access_list);
self.initialize_addresses(&[caller], access_list);

match self.create_inner(
caller,
Expand Down Expand Up @@ -707,7 +698,7 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>
}

// Initialize initial addresses for EIP-2929
self.initialize_addresses(caller, address, access_list);
self.initialize_addresses(&[caller, address], access_list);

if let Err(e) = self.state.inc_nonce(caller) {
return (e.into(), Vec::new());
Expand Down Expand Up @@ -811,23 +802,18 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>
self.state.metadata_mut().access_storages(storage_keys);
}

fn initialize_addresses(
&mut self,
caller: H160,
address: H160,
access_list: Vec<(H160, Vec<H256>)>,
) {
fn initialize_addresses(&mut self, addresses: &[H160], access_list: Vec<(H160, Vec<H256>)>) {
if self.config.increase_state_access_gas {
if self.config.warm_coinbase_address {
// Warm coinbase address for EIP-3651
let coinbase = self.block_coinbase();
self.state
.metadata_mut()
.access_addresses([caller, address, coinbase].iter().copied());
.access_addresses(addresses.iter().copied().chain(Some(coinbase)));
} else {
self.state
.metadata_mut()
.access_addresses([caller, address].iter().copied());
.access_addresses(addresses.iter().copied());
};

self.initialize_with_access_list(access_list);
Expand Down
Loading