wasmi-labs / wasmi

WebAssembly (Wasm) interpreter.

Home Page:https://wasmi-labs.github.io/wasmi/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Improve `FuelConsumptionMode::Lazy`

Robbepop opened this issue · comments

Currently FuelConsumptionMode::Lazy leads to pre-checking if enough fuel is available for a full memory.grow or table.grow operation, even though it is clear that this operation will fail and thus won't be expensive at all.

We implemented this to be conservative.

However, this led us to requiring the FuelConsumptionMode::Eager in order to properly estimate required fuel for Wasm blob execution since with FuelConsumptionMode::Lazy the returned estimated fuel would be lower than what the same mode needed for execution with pre-checking.

The idea now is to remove pre-checking fuel for full execution and instead have an O(1) check to see whether the memory or table can actually grow and only afterwards charge for the full amount and do the operation assuming success.

This way we can remove the FuelConsumptionMode::Eager and thus FuelConsumptionMode entirely since FuelConsumptionMode::Lazy (which will become the default behavior) can handle both execution as well as fuel estimation.

Note: Pre-checking applies to all affected instructions, namely:

  1. memory.{grow, copy, fill}
  2. data.init
  3. table.{grow, copy, fill}
  4. elem.init