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

revm: Return bytes in Create calls #289

Merged
merged 1 commit into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
17 changes: 9 additions & 8 deletions crates/revm/src/evm_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,14 +495,13 @@ impl<'a, GSPEC: Spec, DB: Database, const INSPECT: bool> EVMImpl<'a, GSPEC, DB,
// Host error if present on execution\
let (ret, address, gas, out) = match exit_reason {
return_ok!() => {
let b = Bytes::new();
// if ok, check contract creation limit and calculate gas deduction on output len.
let mut bytes = interpreter.return_value();

// EIP-3541: Reject new contract code starting with the 0xEF byte
if GSPEC::enabled(LONDON) && !bytes.is_empty() && bytes.first() == Some(&0xEF) {
self.data.journaled_state.checkpoint_revert(checkpoint);
return (Return::CreateContractWithEF, ret, interpreter.gas, b);
return (Return::CreateContractWithEF, ret, interpreter.gas, bytes);
}

// EIP-170: Contract code size limit
Expand All @@ -511,7 +510,7 @@ impl<'a, GSPEC: Spec, DB: Database, const INSPECT: bool> EVMImpl<'a, GSPEC, DB,
&& bytes.len() > self.data.env.cfg.limit_contract_code_size.unwrap_or(0x6000)
{
self.data.journaled_state.checkpoint_revert(checkpoint);
return (Return::CreateContractLimit, ret, interpreter.gas, b);
return (Return::CreateContractLimit, ret, interpreter.gas, bytes);
}
if crate::USE_GAS {
let gas_for_code = bytes.len() as u64 * crate::gas::CODEDEPOSIT;
Expand All @@ -522,7 +521,7 @@ impl<'a, GSPEC: Spec, DB: Database, const INSPECT: bool> EVMImpl<'a, GSPEC, DB,
// creation fails (i.e. goes out-of-gas) rather than leaving an empty contract.
if GSPEC::enabled(HOMESTEAD) {
self.data.journaled_state.checkpoint_revert(checkpoint);
return (Return::OutOfGas, ret, interpreter.gas, b);
return (Return::OutOfGas, ret, interpreter.gas, bytes);
} else {
bytes = Bytes::new();
}
Expand All @@ -532,15 +531,17 @@ impl<'a, GSPEC: Spec, DB: Database, const INSPECT: bool> EVMImpl<'a, GSPEC, DB,
self.data.journaled_state.checkpoint_commit();
// Do analasis of bytecode streight away.
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::<GSPEC>(),
AnalysisKind::Raw => Bytecode::new_raw(bytes.clone()),
AnalysisKind::Check => Bytecode::new_raw(bytes.clone()).to_checked(),
AnalysisKind::Analyse => {
Bytecode::new_raw(bytes.clone()).to_analysed::<GSPEC>()
}
};

self.data
.journaled_state
.set_code(created_address, bytecode);
(Return::Continue, ret, interpreter.gas, b)
(Return::Continue, ret, interpreter.gas, bytes)
}
_ => {
self.data.journaled_state.checkpoint_revert(checkpoint);
Expand Down
7 changes: 6 additions & 1 deletion crates/revm/src/instructions/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,12 @@ pub fn create<const IS_CREATE2: bool, SPEC: Spec>(
};

let (return_reason, address, gas, return_data) = host.create(&mut create_input);
interpreter.return_data_buffer = return_data;
interpreter.return_data_buffer = match return_reason {
// Save data to return data buffer if the create reverted
return_revert!() => return_data,
// Otherwise clear it
_ => Bytes::new(),
};

match return_reason {
return_ok!() => {
Expand Down