Skip to content

Commit

Permalink
revm: Return bytes in Create calls
Browse files Browse the repository at this point in the history
  • Loading branch information
ngotchac committed Dec 8, 2022
1 parent 54e0333 commit 798e0e0
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions crates/revm/src/evm_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,14 +497,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 = interp.return_value();

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

// EIP-170: Contract code size limit
Expand All @@ -513,7 +512,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, interp.gas, b);
return (Return::CreateContractLimit, ret, interp.gas, bytes);
}
if crate::USE_GAS {
let gas_for_code = bytes.len() as u64 * crate::gas::CODEDEPOSIT;
Expand All @@ -524,7 +523,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 SPEC::enabled(HOMESTEAD) {
self.data.journaled_state.checkpoint_revert(checkpoint);
return (Return::OutOfGas, ret, interp.gas, b);
return (Return::OutOfGas, ret, interp.gas, bytes);
} else {
bytes = Bytes::new();
}
Expand All @@ -534,15 +533,15 @@ 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::<SPEC>(),
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::<SPEC>(),
};

self.data
.journaled_state
.set_code(created_address, bytecode);
(Return::Continue, ret, interp.gas, b)
(Return::Continue, ret, interp.gas, bytes)
}
_ => {
self.data.journaled_state.checkpoint_revert(checkpoint);
Expand Down

0 comments on commit 798e0e0

Please sign in to comment.