evm v0.1.11 EVM.Gas

Functions for interacting wth gas and costs of opscodes.

Link to this section Summary

Functions

Returns the cost to execute the given a cycle of the VM. This is defined in Appenix H of the Yellow Paper, Eq.(220) and is denoted C

Paid for every transaction

Paid by all contract-creating transactions after the Homestead transition

Returns the gas cost for G_txdata{zero, nonzero} as defined in Appendix G (Fee Schedule) of the Yellow Paper

Returns the cost of a call to sstore. This is defined in Appenfix H.2. of the Yellow Paper under the definition of SSTORE, referred to as C_SSTORE

Link to this section Types

Link to this type gas_price()
gas_price() :: EVM.Wei.t

Link to this section Functions

Link to this function cost(state, machine_state, operation, inputs)
cost(EVM.state, EVM.MachineState.t, Operation.Metadata.t, [EVM.val]) ::
  t |
  nil

Returns the cost to execute the given a cycle of the VM. This is defined in Appenix H of the Yellow Paper, Eq.(220) and is denoted C.

Examples

# TODO: Figure out how to hand in state
iex> EVM.Gas.cost(%{}, %EVM.MachineState{}, EVM.Operation.metadata(:stop), %EVM.ExecEnv{})
0
Link to this function g_transaction()
g_transaction() :: t

Paid for every transaction.

Link to this function g_txcreate()
g_txcreate() :: t

Paid by all contract-creating transactions after the Homestead transition.

Link to this function g_txdata(data)
g_txdata(binary) :: t

Returns the gas cost for G_txdata{zero, nonzero} as defined in Appendix G (Fee Schedule) of the Yellow Paper.

This implements g_txdatazero and g_txdatanonzero

Examples

iex> EVM.Gas.g_txdata(<<1, 2, 3, 0, 4, 5>>)
5 * 68 + 4

iex> EVM.Gas.g_txdata(<<0>>)
4

iex> EVM.Gas.g_txdata(<<0, 0>>)
8

iex> EVM.Gas.g_txdata(<<>>)
0
Link to this function memory_cost(arg1, arg2, machine_state)
Link to this function memory_expansion_cost(machine_state, offset, length)
Link to this function memory_expansion_value(active_words, offset, length)
Link to this function operation_cost(operation, inputs, state, machine_state)
operation_cost(atom, [EVM.val], EVM.state, EVM.MachineState.t) ::
  t |
  nil

Returns the cost of a call to sstore. This is defined in Appenfix H.2. of the Yellow Paper under the definition of SSTORE, referred to as C_SSTORE.

Examples

iex> state = MerklePatriciaTree.Trie.new(MerklePatriciaTree.Test.random_ets_db(:evm_vm_test)) …> |> MerklePatriciaTree.Trie.update(<<0>>, 1) iex> EVM.Gas.operation_cost(:sstore, [0, 0], state, %EVM.MachineState{}) 5000 iex> EVM.Gas.operation_cost(:sstore, [0, 2], state, %EVM.MachineState{}) 20000

Link to this function quadratic_memory_cost(a)