runtime: Disallow `eth_call` on wasm start
@@ -427,40 +427,22 @@ impl WasmInstance {
for module in modules {
let func_shared_ctx = Rc::downgrade(&shared_ctx);
- let valid_module = valid_module.cheap_clone();
- let host_metrics = host_metrics.cheap_clone();
- let timeout_stopwatch = timeout_stopwatch.cheap_clone();
- let ctx = ctx.cheap_clone();
- linker.func(
- module,
- "ethereum.call",
- move |caller: wasmtime::Caller, call_ptr: u32| {
+ linker.func(module, "ethereum.call", move |call_ptr: u32| {
let start = Instant::now();
let instance = func_shared_ctx.upgrade().unwrap();
let mut instance = instance.borrow_mut();
- // Happens when calling a host fn in Wasm start.
- if instance.is_none() {
- error!(
- ctx.borrow().as_ref().unwrap().logger,
- "contract calls in globals are deprecated"
- );
+ let instance = match &mut *instance {
+ Some(instance) => instance,
- *instance = Some(
- WasmInstanceContext::from_caller(
- caller,
- ctx.borrow_mut().take().unwrap(),
- valid_module.cheap_clone(),
- host_metrics.cheap_clone(),
- timeout,
- timeout_stopwatch.cheap_clone(),
- experimental_features.clone(),
- )
- .unwrap(),
+ // Happens when calling a host fn in Wasm start.
+ None => {
+ return Err(
+ anyhow!("ethereum.call is not allowed in global variables").into()
)
}
+ };
- let instance = instance.as_mut().unwrap();
let stopwatch = &instance.host_metrics.stopwatch;
let _section = stopwatch.start_section("host_export_ethereum_call");
@@ -487,13 +469,11 @@ impl WasmInstance {
HostExportError::Unknown(e) => e,
})?
.wasm_ptr();
- instance.host_metrics.observe_host_fn_execution_time(
- start.elapsed().as_secs_f64(),
- "ethereum_call",
- );
+ instance
+ .host_metrics
+ .observe_host_fn_execution_time(start.elapsed().as_secs_f64(), "ethereum_call");
Ok(ret)
- },
- )?;
+ })?;
}
link!("abort", abort, message_ptr, file_name_ptr, line, column);
