.. py:module:: ethereum.frontier.vm.gas Ethereum Virtual Machine (EVM) Gas ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. contents:: Table of Contents :backlinks: none :local: Introduction ------------ EVM gas constants and calculators. .. only:: stage1 Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: ethereum.frontier.vm.gas.ExtendMemory ethereum.frontier.vm.gas.MessageCallGas Functions ~~~~~~~~~ .. autoapisummary:: :nosignatures: ethereum.frontier.vm.gas.charge_gas ethereum.frontier.vm.gas.calculate_memory_gas_cost ethereum.frontier.vm.gas.calculate_gas_extend_memory ethereum.frontier.vm.gas.calculate_message_call_gas Attributes ~~~~~~~~~~ .. autoapisummary:: ethereum.frontier.vm.gas.GAS_JUMPDEST ethereum.frontier.vm.gas.GAS_BASE ethereum.frontier.vm.gas.GAS_VERY_LOW ethereum.frontier.vm.gas.GAS_SLOAD ethereum.frontier.vm.gas.GAS_STORAGE_SET ethereum.frontier.vm.gas.GAS_STORAGE_UPDATE ethereum.frontier.vm.gas.GAS_STORAGE_CLEAR_REFUND ethereum.frontier.vm.gas.GAS_LOW ethereum.frontier.vm.gas.GAS_MID ethereum.frontier.vm.gas.GAS_HIGH ethereum.frontier.vm.gas.GAS_EXPONENTIATION ethereum.frontier.vm.gas.GAS_EXPONENTIATION_PER_BYTE ethereum.frontier.vm.gas.GAS_MEMORY ethereum.frontier.vm.gas.GAS_KECCAK256 ethereum.frontier.vm.gas.GAS_KECCAK256_WORD ethereum.frontier.vm.gas.GAS_COPY ethereum.frontier.vm.gas.GAS_BLOCK_HASH ethereum.frontier.vm.gas.GAS_EXTERNAL ethereum.frontier.vm.gas.GAS_BALANCE ethereum.frontier.vm.gas.GAS_LOG ethereum.frontier.vm.gas.GAS_LOG_DATA ethereum.frontier.vm.gas.GAS_LOG_TOPIC ethereum.frontier.vm.gas.GAS_CREATE ethereum.frontier.vm.gas.GAS_CODE_DEPOSIT ethereum.frontier.vm.gas.GAS_ZERO ethereum.frontier.vm.gas.GAS_CALL ethereum.frontier.vm.gas.GAS_NEW_ACCOUNT ethereum.frontier.vm.gas.GAS_CALL_VALUE ethereum.frontier.vm.gas.GAS_CALL_STIPEND ethereum.frontier.vm.gas.REFUND_SELF_DESTRUCT ethereum.frontier.vm.gas.GAS_ECRECOVER ethereum.frontier.vm.gas.GAS_SHA256 ethereum.frontier.vm.gas.GAS_SHA256_WORD ethereum.frontier.vm.gas.GAS_RIPEMD160 ethereum.frontier.vm.gas.GAS_RIPEMD160_WORD ethereum.frontier.vm.gas.GAS_IDENTITY ethereum.frontier.vm.gas.GAS_IDENTITY_WORD Module Details --------------- GAS_JUMPDEST ~~~~~~~~~~~~ .. py:data:: GAS_JUMPDEST .. undocinclude:: /../src/ethereum/frontier/vm/gas.py :language: python :lines: 25-25 GAS_BASE ~~~~~~~~ .. py:data:: GAS_BASE .. undocinclude:: /../src/ethereum/frontier/vm/gas.py :language: python :lines: 26-26 GAS_VERY_LOW ~~~~~~~~~~~~ .. py:data:: GAS_VERY_LOW .. undocinclude:: /../src/ethereum/frontier/vm/gas.py :language: python :lines: 27-27 GAS_SLOAD ~~~~~~~~~ .. py:data:: GAS_SLOAD .. undocinclude:: /../src/ethereum/frontier/vm/gas.py :language: python :lines: 28-28 GAS_STORAGE_SET ~~~~~~~~~~~~~~~ .. py:data:: GAS_STORAGE_SET .. undocinclude:: /../src/ethereum/frontier/vm/gas.py :language: python :lines: 29-29 GAS_STORAGE_UPDATE ~~~~~~~~~~~~~~~~~~ .. py:data:: GAS_STORAGE_UPDATE .. undocinclude:: /../src/ethereum/frontier/vm/gas.py :language: python :lines: 30-30 GAS_STORAGE_CLEAR_REFUND ~~~~~~~~~~~~~~~~~~~~~~~~ .. py:data:: GAS_STORAGE_CLEAR_REFUND .. undocinclude:: /../src/ethereum/frontier/vm/gas.py :language: python :lines: 31-31 GAS_LOW ~~~~~~~ .. py:data:: GAS_LOW .. undocinclude:: /../src/ethereum/frontier/vm/gas.py :language: python :lines: 32-32 GAS_MID ~~~~~~~ .. py:data:: GAS_MID .. undocinclude:: /../src/ethereum/frontier/vm/gas.py :language: python :lines: 33-33 GAS_HIGH ~~~~~~~~ .. py:data:: GAS_HIGH .. undocinclude:: /../src/ethereum/frontier/vm/gas.py :language: python :lines: 34-34 GAS_EXPONENTIATION ~~~~~~~~~~~~~~~~~~ .. py:data:: GAS_EXPONENTIATION .. undocinclude:: /../src/ethereum/frontier/vm/gas.py :language: python :lines: 35-35 GAS_EXPONENTIATION_PER_BYTE ~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. py:data:: GAS_EXPONENTIATION_PER_BYTE .. undocinclude:: /../src/ethereum/frontier/vm/gas.py :language: python :lines: 36-36 GAS_MEMORY ~~~~~~~~~~ .. py:data:: GAS_MEMORY .. undocinclude:: /../src/ethereum/frontier/vm/gas.py :language: python :lines: 37-37 GAS_KECCAK256 ~~~~~~~~~~~~~ .. py:data:: GAS_KECCAK256 .. undocinclude:: /../src/ethereum/frontier/vm/gas.py :language: python :lines: 38-38 GAS_KECCAK256_WORD ~~~~~~~~~~~~~~~~~~ .. py:data:: GAS_KECCAK256_WORD .. undocinclude:: /../src/ethereum/frontier/vm/gas.py :language: python :lines: 39-39 GAS_COPY ~~~~~~~~ .. py:data:: GAS_COPY .. undocinclude:: /../src/ethereum/frontier/vm/gas.py :language: python :lines: 40-40 GAS_BLOCK_HASH ~~~~~~~~~~~~~~ .. py:data:: GAS_BLOCK_HASH .. undocinclude:: /../src/ethereum/frontier/vm/gas.py :language: python :lines: 41-41 GAS_EXTERNAL ~~~~~~~~~~~~ .. py:data:: GAS_EXTERNAL .. undocinclude:: /../src/ethereum/frontier/vm/gas.py :language: python :lines: 42-42 GAS_BALANCE ~~~~~~~~~~~ .. py:data:: GAS_BALANCE .. undocinclude:: /../src/ethereum/frontier/vm/gas.py :language: python :lines: 43-43 GAS_LOG ~~~~~~~ .. py:data:: GAS_LOG .. undocinclude:: /../src/ethereum/frontier/vm/gas.py :language: python :lines: 44-44 GAS_LOG_DATA ~~~~~~~~~~~~ .. py:data:: GAS_LOG_DATA .. undocinclude:: /../src/ethereum/frontier/vm/gas.py :language: python :lines: 45-45 GAS_LOG_TOPIC ~~~~~~~~~~~~~ .. py:data:: GAS_LOG_TOPIC .. undocinclude:: /../src/ethereum/frontier/vm/gas.py :language: python :lines: 46-46 GAS_CREATE ~~~~~~~~~~ .. py:data:: GAS_CREATE .. undocinclude:: /../src/ethereum/frontier/vm/gas.py :language: python :lines: 47-47 GAS_CODE_DEPOSIT ~~~~~~~~~~~~~~~~ .. py:data:: GAS_CODE_DEPOSIT .. undocinclude:: /../src/ethereum/frontier/vm/gas.py :language: python :lines: 48-48 GAS_ZERO ~~~~~~~~ .. py:data:: GAS_ZERO .. undocinclude:: /../src/ethereum/frontier/vm/gas.py :language: python :lines: 49-49 GAS_CALL ~~~~~~~~ .. py:data:: GAS_CALL .. undocinclude:: /../src/ethereum/frontier/vm/gas.py :language: python :lines: 50-50 GAS_NEW_ACCOUNT ~~~~~~~~~~~~~~~ .. py:data:: GAS_NEW_ACCOUNT .. undocinclude:: /../src/ethereum/frontier/vm/gas.py :language: python :lines: 51-51 GAS_CALL_VALUE ~~~~~~~~~~~~~~ .. py:data:: GAS_CALL_VALUE .. undocinclude:: /../src/ethereum/frontier/vm/gas.py :language: python :lines: 52-52 GAS_CALL_STIPEND ~~~~~~~~~~~~~~~~ .. py:data:: GAS_CALL_STIPEND .. undocinclude:: /../src/ethereum/frontier/vm/gas.py :language: python :lines: 53-53 REFUND_SELF_DESTRUCT ~~~~~~~~~~~~~~~~~~~~ .. py:data:: REFUND_SELF_DESTRUCT .. undocinclude:: /../src/ethereum/frontier/vm/gas.py :language: python :lines: 54-54 GAS_ECRECOVER ~~~~~~~~~~~~~ .. py:data:: GAS_ECRECOVER .. undocinclude:: /../src/ethereum/frontier/vm/gas.py :language: python :lines: 55-55 GAS_SHA256 ~~~~~~~~~~ .. py:data:: GAS_SHA256 .. undocinclude:: /../src/ethereum/frontier/vm/gas.py :language: python :lines: 56-56 GAS_SHA256_WORD ~~~~~~~~~~~~~~~ .. py:data:: GAS_SHA256_WORD .. undocinclude:: /../src/ethereum/frontier/vm/gas.py :language: python :lines: 57-57 GAS_RIPEMD160 ~~~~~~~~~~~~~ .. py:data:: GAS_RIPEMD160 .. undocinclude:: /../src/ethereum/frontier/vm/gas.py :language: python :lines: 58-58 GAS_RIPEMD160_WORD ~~~~~~~~~~~~~~~~~~ .. py:data:: GAS_RIPEMD160_WORD .. undocinclude:: /../src/ethereum/frontier/vm/gas.py :language: python :lines: 59-59 GAS_IDENTITY ~~~~~~~~~~~~ .. py:data:: GAS_IDENTITY .. undocinclude:: /../src/ethereum/frontier/vm/gas.py :language: python :lines: 60-60 GAS_IDENTITY_WORD ~~~~~~~~~~~~~~~~~ .. py:data:: GAS_IDENTITY_WORD .. undocinclude:: /../src/ethereum/frontier/vm/gas.py :language: python :lines: 61-61 ExtendMemory ~~~~~~~~~~~~ Define the parameters for memory extension in opcodes `cost`: `ethereum.base_types.Uint` The gas required to perform the extension `expand_by`: `ethereum.base_types.Uint` The size by which the memory will be extended .. class:: ExtendMemory .. py:attribute:: cost :annotation: :ethereum.base_types.Uint .. py:attribute:: expand_by :annotation: :ethereum.base_types.Uint MessageCallGas ~~~~~~~~~~~~~~ Define the gas cost and stipend for executing the call opcodes. `cost`: `ethereum.base_types.Uint` The non-refundable portion of gas reserved for executing the call opcode. `stipend`: `ethereum.base_types.Uint` The portion of gas available to sub-calls that is refundable if not consumed .. class:: MessageCallGas .. py:attribute:: cost :annotation: :ethereum.base_types.Uint .. py:attribute:: stipend :annotation: :ethereum.base_types.Uint charge_gas ~~~~~~~~~~ .. function:: charge_gas(evm: ethereum.frontier.vm.Evm, amount: ethereum.base_types.Uint) -> None :noindexentry: Subtracts `amount` from `evm.gas_left`. :param evm: The current EVM. :param amount: The amount of gas the current operation requires. .. undocinclude:: /../src/ethereum/frontier/vm/gas.py :language: python :pyobject: charge_gas calculate_memory_gas_cost ~~~~~~~~~~~~~~~~~~~~~~~~~ .. function:: calculate_memory_gas_cost(size_in_bytes: ethereum.base_types.Uint) -> ethereum.base_types.Uint :noindexentry: Calculates the gas cost for allocating memory to the smallest multiple of 32 bytes, such that the allocated size is at least as big as the given size. :param size_in_bytes: The size of the data in bytes. :returns: **total_gas_cost** -- The gas cost for storing data in memory. :rtype: `ethereum.base_types.Uint` .. undocinclude:: /../src/ethereum/frontier/vm/gas.py :language: python :pyobject: calculate_memory_gas_cost calculate_gas_extend_memory ~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. function:: calculate_gas_extend_memory(memory: bytearray, extensions: List[Tuple[ethereum.base_types.U256, ethereum.base_types.U256]]) -> ExtendMemory :noindexentry: Calculates the gas amount to extend memory :param memory: Memory contents of the EVM. :param extensions: List of extensions to be made to the memory. Consists of a tuple of start position and size. :returns: **extend_memory** :rtype: `ExtendMemory` .. undocinclude:: /../src/ethereum/frontier/vm/gas.py :language: python :pyobject: calculate_gas_extend_memory calculate_message_call_gas ~~~~~~~~~~~~~~~~~~~~~~~~~~ .. function:: calculate_message_call_gas(state: ethereum.frontier.state.State, gas: ethereum.base_types.Uint, to: ethereum.frontier.eth_types.Address, value: ethereum.base_types.U256) -> MessageCallGas :noindexentry: Calculates the gas amount for executing Opcodes `CALL` and `CALLCODE`. :param state: The current state. :param gas: The amount of gas provided to the message-call. :param to: The address of the recipient account. :param value: The amount of `ETH` that needs to be transferred. :returns: **message_call_gas** :rtype: `MessageCallGas` .. undocinclude:: /../src/ethereum/frontier/vm/gas.py :language: python :pyobject: calculate_message_call_gas