Skip to content
Merged
Changes from 3 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
18 changes: 14 additions & 4 deletions src/executor/stack/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,28 @@ pub struct PrecompileOutput {
pub logs: Vec<Log>,
}

/// Precompiles function signature. Expected input arguments are:
/// * Address
/// * Input
/// * Context
/// * State
/// * Is static
type PrecompileFn<S> = fn(H160, &[u8], Option<u64>, &Context, &mut S, bool) -> Option<Result<PrecompileOutput, ExitError>>;

/// Stack-based executor.
pub struct StackExecutor<'config, S> {
config: &'config Config,
precompile: fn(H160, &[u8], Option<u64>, &Context) -> Option<Result<PrecompileOutput, ExitError>>,
precompile: PrecompileFn<S>,
state: S,
}

fn no_precompile(
fn no_precompile<S>(
_address: H160,
_input: &[u8],
_target_gas: Option<u64>,
_context: &Context,
_state: &mut S,
Comment thread
mfornet marked this conversation as resolved.
Outdated
_is_static: bool,
) -> Option<Result<PrecompileOutput, ExitError>> {
None
}
Expand All @@ -123,7 +133,7 @@ impl<'config, S: StackState<'config>> StackExecutor<'config, S> {
pub fn new_with_precompile(
state: S,
config: &'config Config,
precompile: fn(H160, &[u8], Option<u64>, &Context) -> Option<Result<PrecompileOutput, ExitError>>,
precompile: PrecompileFn<S>,
) -> Self {
Self {
config,
Expand Down Expand Up @@ -531,7 +541,7 @@ impl<'config, S: StackState<'config>> StackExecutor<'config, S> {
}
}

if let Some(ret) = (self.precompile)(code_address, &input, Some(gas_limit), &context) {
if let Some(ret) = (self.precompile)(code_address, &input, Some(gas_limit), &context, &mut self.state, is_static) {
match ret {
Ok(PrecompileOutput { exit_status , output, cost, logs }) => {
for Log { address, topics, data} in logs {
Expand Down