Skip to content
Closed
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
16 changes: 16 additions & 0 deletions crates/core/src/fuel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,4 +334,20 @@ impl Fuel {
self.consume_fuel_unchecked(f(&self.costs))?;
Ok(())
}

/// Traps if fuel is depleted and fuel metering is enabled.
///
/// # Note
///
/// This does nothing if fuel metering is disabled.
///
/// # Errors
///
/// - If fuel is 0 and fuel metering is enabled.
pub fn trap_if_out_of_fuel_if_enabled(&self) -> Result<(), FuelError> {
if self.enabled && self.remaining == 0 {
return Err(FuelError::out_of_fuel(0));
}
Ok(())
}
}
4 changes: 3 additions & 1 deletion crates/wasmi/src/engine/executor/instrs/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,9 @@ impl Executor<'_> {
}
FuncEntity::Host(host_func) => {
let host_func = *host_func;
self.execute_host_func::<C>(store, results, func, host_func)
let res = self.execute_host_func::<C>(store, results, func, host_func)?;
store.inner_mut().fuel_mut().trap_if_out_of_fuel_if_enabled()?;
Ok(res)
}
}
}
Expand Down