evm v0.1.14 EVM.Operation.EnvironmentalInformation

Link to this section Summary

Functions

Get address of currently executing account

Get balance of the given account

Copy input data in current environment to memory

Get input data of current environment

Get size of input data in current environment

Get caller address

Get deposited value by the instruction / transaction responsible for this execution

Copy code running in current environment to memory

Get size of code running in current environment

Copy an account’s code to memory

Get size of an account’s code

Get price of gas in current environment

Get execution origination address

Link to this section Functions

Get address of currently executing account.

Examples

iex> EVM.Operation.EnvironmentalInformation.address([], %{exec_env: %EVM.ExecEnv{address: <<01, 00>>}})
<<1, 0>>

Get balance of the given account.

Examples

iex> db = MerklePatriciaTree.Test.random_ets_db()
iex> state = MerklePatriciaTree.Trie.new(db)
iex> account_interface = EVM.Interface.Mock.MockAccountInterface.new(%{123 => %{balance: 500}})
iex> exec_env = %EVM.ExecEnv{account_interface: account_interface}
iex> EVM.Operation.EnvironmentalInformation.balance([123], %{state: state, exec_env: exec_env, machine_state: %EVM.MachineState{}}).machine_state.stack
[500]

iex> db = MerklePatriciaTree.Test.random_ets_db()
iex> state = MerklePatriciaTree.Trie.new(db)
iex> account_map = %{123 => %{balance: nil}}
iex> account_interface = EVM.Interface.Mock.MockAccountInterface.new(%{account_map: account_map})
iex> exec_env = %EVM.ExecEnv{account_interface: account_interface}
iex> EVM.Operation.EnvironmentalInformation.balance([123], %{state: state, exec_env: exec_env, machine_state: %EVM.MachineState{}}).machine_state.stack
[0]

Copy input data in current environment to memory.

TODO: Implement opcode

Examples

iex> code = <<54>>
iex> EVM.Operation.EnvironmentalInformation.calldatacopy([0, 0, 1], %{exec_env: %EVM.ExecEnv{data: code}, machine_state: %EVM.MachineState{}})
%{machine_state: %EVM.MachineState{active_words: 1, gas: nil, memory: <<54>> <> <<0::248>>, program_counter: 0, previously_active_words: 0, stack: []}}

Get input data of current environment.

TODO: Implement opcode

Examples

iex> EVM.Operation.EnvironmentalInformation.calldataload([0], %{exec_env: %{data: (for _ <- 1..50, into: <<>>, do: <<255>>)}})
-1

iex> EVM.Operation.EnvironmentalInformation.calldataload([0], %{exec_env: %{data: (for _ <- 1..3, into: <<>>, do: <<1>>)}})
<<1::8, 1::8, 1::8, 0::232>> |> EVM.Helpers.decode_signed

iex> EVM.Operation.EnvironmentalInformation.calldataload([100], %{exec_env: %{data: (for _ <- 1..3, into: <<>>, do: <<1>>)}})
0

Get size of input data in current environment.

Examples

iex> exec_env = %EVM.ExecEnv{data: "hello world"}
iex> EVM.Operation.EnvironmentalInformation.calldatasize([], %{exec_env: exec_env})
11

Get caller address.

This is the address of the account that is directly responsible for this execution.

Examples

iex> exec_env = %EVM.ExecEnv{originator: <<1::160>>, sender: <<2::160>>}
iex> EVM.Operation.EnvironmentalInformation.caller([], %{exec_env: exec_env, machine_state: %EVM.MachineState{}})
<<2::160>>

Get deposited value by the instruction / transaction responsible for this execution.

Examples

iex> exec_env = %EVM.ExecEnv{value_in_wei: 1_000}
iex> EVM.Operation.EnvironmentalInformation.callvalue([], %{exec_env: exec_env})
1_000

Copy code running in current environment to memory.

Examples

iex> code = <<54>>
iex> EVM.Operation.EnvironmentalInformation.codecopy([0, 0, 1], %{exec_env: %EVM.ExecEnv{machine_code: code}, machine_state: %EVM.MachineState{}})
%{machine_state: %EVM.MachineState{active_words: 1, gas: nil, memory: <<54>> <> <<0::248>>, program_counter: 0, previously_active_words: 0, stack: []}}

Get size of code running in current environment.

Examples

iex> EVM.Operation.EnvironmentalInformation.codesize([], %{exec_env: %{machine_code: <<0::256>>}})
32

Copy an account’s code to memory.

Examples

iex> db = MerklePatriciaTree.Test.random_ets_db()
iex> state = MerklePatriciaTree.Trie.new(db)
iex> code = <<54>>
iex> account_map = %{<<0::160>> => %{code: code}}
iex> account_interface = EVM.Interface.Mock.MockAccountInterface.new(account_map)
iex> EVM.Operation.EnvironmentalInformation.extcodecopy([<<0::160>>, 0, 0, 1], %{exec_env: %EVM.ExecEnv{account_interface: account_interface}, machine_state: %EVM.MachineState{}, state: state})[:machine_state]
%EVM.MachineState{active_words: 1, gas: nil, memory: <<54>> <> <<0::248>>, program_counter: 0, previously_active_words: 0, stack: []}

Get size of an account’s code.

Examples

iex> account_interface = EVM.Interface.Mock.MockAccountInterface.new(%{0x01 => %{code: <<0x11, 0x22, 0x33, 0x44>>}})
iex> db = MerklePatriciaTree.Test.random_ets_db()
iex> state = MerklePatriciaTree.Trie.new(db)
iex> exec_env = %EVM.ExecEnv{account_interface: account_interface}
iex> EVM.Operation.EnvironmentalInformation.extcodesize([0x01], %{exec_env: exec_env, state: state, machine_state: %EVM.MachineState{}}).machine_state.stack
[4]

Get price of gas in current environment.

Examples

iex> EVM.Operation.EnvironmentalInformation.gasprice([], %{exec_env: %{gas_price: 98}})
98

Get execution origination address.

This is the sender of original transaction; it is never an account with non-empty associated code.

Examples

iex> exec_env = %EVM.ExecEnv{originator: <<1::160>>, sender: <<2::160>>}
iex> EVM.Operation.EnvironmentalInformation.origin([], %{exec_env: exec_env})
<<1::160>>