Skip to content

Instantly share code, notes, and snippets.

@vyzo
Created March 8, 2023 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vyzo/781c081cc9769e2f99a087a5886cfc2b to your computer and use it in GitHub Desktop.
Save vyzo/781c081cc9769e2f99a087a5886cfc2b to your computer and use it in GitHub Desktop.
Gas in FEVM

How Gas works in FEVM

Gas in FEVM works quite differently from the EVM. Instead of assigning a fixed gas cost in each instruction, FEVM charges FVM/FIL gas based on WASM code execution of the FEVM interpreter.

When executing a message that invokes an EVM contract, the FVM charges for the message chain inclusion (when the message originates off chain) and then invokes the actor that hosts the contract. The actor is an instance of the EVM actor, which uses the FEVM interpreter to execute the contract.

The FEVM interpreter must first load its state (including the contract state) which costs additional gas, and then begins execution of the contract bytecode. Each opcode interpreted may perform computation, syscalls, state i/o and send new messages, which are all charged with FIL gas. Finally, if the contract state is modified, the interpreter must flush it to the blockstore, which costs additional gas.

Thus in general it is not possible to compute gas costs for a contract invocation, without using gas estimation through speculative execution.

Additional Resources

Gas FIPs:

Primitive Gas Price list:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment