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(EOF): EIP-7698 eof creation transaction #1467

Merged
merged 7 commits into from
Jun 3, 2024
Merged
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
cleanup
rakita committed May 30, 2024

Verified

This commit was signed with the committer’s verified signature. The key has expired.
nirinchev Nikola Irinchev
commit 8e7fd69b8c8e57d34e26920447504a9bbcf12415
2 changes: 1 addition & 1 deletion crates/interpreter/src/instructions/contract.rs
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ pub fn eofcreate<H: Host + ?Sized>(interpreter: &mut Interpreter, _host: &mut H)
return;
};

let input = if input_range.is_empty() {
let input = if !input_range.is_empty() {
interpreter
.shared_memory
.slice_range(input_range)
33 changes: 21 additions & 12 deletions crates/interpreter/src/interpreter.rs
Original file line number Diff line number Diff line change
@@ -68,18 +68,6 @@ impl Default for Interpreter {
}
}

/// The result of an interpreter operation.
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))]
pub struct InterpreterResult {
/// The result of the instruction execution.
pub result: InstructionResult,
/// The output of the instruction execution.
pub output: Bytes,
/// The gas usage information.
pub gas: Gas,
}

impl Interpreter {
/// Create new interpreter
pub fn new(contract: Contract, gas_limit: u64, is_static: bool) -> Self {
@@ -388,7 +376,28 @@ impl Interpreter {
}
}

/// The result of an interpreter operation.
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))]
pub struct InterpreterResult {
/// The result of the instruction execution.
pub result: InstructionResult,
/// The output of the instruction execution.
pub output: Bytes,
/// The gas usage information.
pub gas: Gas,
}

impl InterpreterResult {
/// Returns a new `InterpreterResult` with the given values.
pub fn new(result: InstructionResult, output: Bytes, gas: Gas) -> Self {
Self {
result,
output,
gas,
}
}

/// Returns whether the instruction result is a success.
#[inline]
pub const fn is_ok(&self) -> bool {
2 changes: 2 additions & 0 deletions crates/revm/src/context.rs
Original file line number Diff line number Diff line change
@@ -98,6 +98,8 @@ where
}

impl<EXT, DB: Database> Host for Context<EXT, DB> {
/// Returns reference to Environment.
#[inline]
fn env(&self) -> &Env {
&self.evm.env
}
40 changes: 30 additions & 10 deletions crates/revm/src/evm.rs
Original file line number Diff line number Diff line change
@@ -3,11 +3,11 @@ use crate::{
db::{Database, DatabaseCommit, EmptyDB},
handler::Handler,
interpreter::{
analysis::validate_eof, CallInputs, CreateInputs, EOFCreateInput, Host, InterpreterAction,
SharedMemory,
analysis::validate_eof, CallInputs, CreateInputs, EOFCreateInput, EOFCreateOutcome, Gas,
Host, InstructionResult, InterpreterAction, InterpreterResult, SharedMemory,
},
primitives::{
specification::SpecId, BlockEnv, CfgEnv, EVMError, EVMResult, EnvWithHandlerCfg,
specification::SpecId, BlockEnv, Bytes, CfgEnv, EVMError, EVMResult, EnvWithHandlerCfg,
ExecutionResult, HandlerCfg, ResultAndState, TransactTo, TxEnv,
},
Context, ContextWithHandlerCfg, Frame, FrameOrResult, FrameResult,
@@ -326,6 +326,7 @@ impl<EXT, DB: Database> Evm<'_, EXT, DB> {

/// Transact pre-verified transaction.
fn transact_preverified_inner(&mut self, initial_gas_spend: u64) -> EVMResult<DB::Error> {
let spec_id = self.spec_id();
let ctx = &mut self.context;
let pre_exec = self.handler.pre_execution();

@@ -349,11 +350,22 @@ impl<EXT, DB: Database> Evm<'_, EXT, DB> {
CallInputs::new_boxed(&ctx.evm.env.tx, gas_limit).unwrap(),
)?,
TransactTo::Create => {
// if first byte of data is magic 0xEF, then it is EOFCreate.
if matches!(ctx.env().tx.data.get(0), Some(0xEF)) {
// In spec it says 0xEF00 but 0x00 is checked when decoding EOF.

// get nonce from tx (if set) or from account.
// if first byte of data is magic 0xEF00, then it is EOFCreate.
if spec_id.is_enabled_in(SpecId::PRAGUE)
&& ctx
.env()
.tx
.data
.get(0..=1)
.filter(|&t| t == [0xEF, 00])
.is_some()
{
// TODO Should we just check 0xEF it seems excessive to switch to legacy only
// if it 0xEF00?

// get nonce from tx (if set) or from account (if not).
// Nonce for call is bumped in deduct_caller while
// for CREATE it is not (it is done inside exec handlers).
let nonce = ctx.evm.env.tx.nonce.unwrap_or_else(|| {
let caller = ctx.evm.env.tx.caller;
ctx.evm
@@ -370,11 +382,19 @@ impl<EXT, DB: Database> Evm<'_, EXT, DB> {
validate_eof(&eofcreate.eof_init_code).ok()?;
Some(eofcreate)
});

if let Some(eofcreate) = eofcreate {
exec.eofcreate(ctx, eofcreate)?
} else {
// Create Result.
return Err(EVMError::Custom("Invalid EOFCreate".to_string()));
// Return result, as code is invalid.
FrameOrResult::Result(FrameResult::EOFCreate(EOFCreateOutcome::new(
InterpreterResult::new(
InstructionResult::Stop,
Bytes::new(),
Gas::new(gas_limit),
),
ctx.env().tx.caller.create(nonce),
)))
}
} else {
// Safe to unwrap because we are sure that it is create tx.