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

Properly return retval in TransactValue #272

Merged
merged 1 commit into from
Jan 28, 2024
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
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//! for the function.
//!
//! * Select an [Invoker]. The invoker defines all details of the execution
//! environment except the external backend. [standard::SimpleInvoker] is
//! environment except the external backend. [standard::Invoker] is
//! probably want you want if you are not extending EVM.
//! * For the standard invoker, select a [standard::Config], which represents
//! different Ethereum hard forks.
Expand Down
55 changes: 42 additions & 13 deletions src/standard/invoker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,24 @@ pub enum SubstackInvoke {
Create { trap: CreateTrapData, address: H160 },
}

/// Return value of a transaction.
pub enum TransactValue {
Call {
/// The exit result. If we return a value, then it will be an
/// `ExitSucceed`.
succeed: ExitSucceed,
/// The return value, if any.
retval: Vec<u8>,
},
Create {
/// The exit result. If we return a value, then it will be an
/// `ExitSucceed`.
succeed: ExitSucceed,
/// The contract address created.
address: H160,
},
}

/// The invoke used in a top-layer transaction stack.
pub struct TransactInvoke {
pub create_address: Option<H160>,
Expand Down Expand Up @@ -165,7 +183,7 @@ where
type Interrupt = Tr::Rest;
type TransactArgs = TransactArgs;
type TransactInvoke = TransactInvoke;
type TransactValue = (ExitSucceed, Option<H160>);
type TransactValue = TransactValue;
type SubstackInvoke = SubstackInvoke;

fn new_transact(
Expand Down Expand Up @@ -335,21 +353,32 @@ where
let left_gas = substate.effective_gas();

let work = || -> Result<Self::TransactValue, ExitError> {
if result.is_ok() {
if let Some(address) = invoke.create_address {
let retbuf = retval;
match result {
Ok(result) => {
if let Some(address) = invoke.create_address {
let retbuf = retval;

routines::deploy_create_code(
self.config,
address,
retbuf,
&mut substate,
handler,
)?;
routines::deploy_create_code(
self.config,
address,
retbuf,
&mut substate,
handler,
)?;

Ok(TransactValue::Create {
succeed: result,
address,
})
} else {
Ok(TransactValue::Call {
succeed: result,
retval,
})
}
}
Err(result) => Err(result),
}

result.map(|s| (s, invoke.create_address))
};

let result = work();
Expand Down