Skip to content

Questions on instruction gas cost #154

Description

@lxfind

A few questions around how we chose the gas cost for some of the instructions.
In this table:

pub fn bytecode_instruction_costs() -> Vec<(Bytecode, GasCost)> {

  1. MoveTo writes new data into the storage, while MoveFrom removes data from storage. However, MoveFrom (459) is significantly more expensive than MoveTo (13). Why is MoveTo so cheap? What's the rationale behind this choice? Isn't MoveFrom considered as data deletion and should be encouraged instead of punished?
  2. Why is MoveFromGeneric (13) significantly cheaper than MoveFrom (459)?
  3. Why is ImmBorrowGlobal (23) more expensive than MutBorrowGlobal (21)? Should mutable borrows be more expensive since we expect mutations?
  4. We don't seem to distinguish the cost between global storage accesses and stack memory accesses. For instance, when we compute the cost of WriteRef, we don't really look at whether the reference is pointing to the stack or to a global storage. This makes the cost of global storage accesses (both reads and writes) way too cheap than it should be. Is this intentional?
  5. When we compute the gas cost for a native function call (
    let gas_amt = table.native_cost(native_table_idx.into());
    let memory_size = AbstractMemorySize::new(std::cmp::max(1, size) as GasCarrier);
    debug_assert!(memory_size.get() > 0);
    gas_amt.total().mul(memory_size)
    ), we are first adding the computation cost and memory cost, and then multiply the sum with the memory size. Shouldn't we only multiple the memory cost with memory size? Is this a bug?

cc @tzakian

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions