evm v0.1.12 EVM.Operation.System
Link to this section Summary
Functions
For call: Message-call into an account. For call code: Message-call into this account with an alternative account’s code. For delegate call: Message-call into this account with an alternative account’s code, but persisting the current values for sender and value
Create a new account with associated code
Halt execution returning output data,
Halt execution and register account for later deletion
Link to this section Functions
call(Operation.stack_args, Operation.vm_map) :: Operation.op_result
call(atom, Operation.stack_args, Operation.vm_map) :: Operation.op_result
For call: Message-call into an account. For call code: Message-call into this account with an alternative account’s code. For delegate call: Message-call into this account with an alternative account’s code, but persisting the current values for sender and value.
Examples
# CALL
iex> block_interface = EVM.Interface.Mock.MockBlockInterface.new(%Block.Header{})
iex> account_map = %{<<0::160>> => %{balance: 5_000, nonce: 5}}
iex> account_interface = EVM.Interface.Mock.MockAccountInterface.new(%{account_map: account_map}, %{gas: 500, sub_state: nil, output: "output"})
iex> exec_env = %EVM.ExecEnv{stack_depth: 0, address: <<0::160>>, account_interface: account_interface, block_interface: block_interface}
iex> machine_state = %EVM.MachineState{gas: 300, stack: [1], memory: "________" <> "input"}
iex> %{machine_state: n_machine_state} =
...> EVM.Operation.System.call(
...> :call,
...> [100, <<0x01::160>>, 1_000, 5, 5, 1, 6],
...> %{exec_env: exec_env, machine_state: machine_state})
iex> n_machine_state
%EVM.MachineState{gas: 800, stack: [1, 1], active_words: 1, memory: "_output_input", program_counter: 0}
# CALLCODE
iex> block_interface = EVM.Interface.Mock.MockBlockInterface.new(%Block.Header{})
iex> account_map = %{<<0::160>> => %{balance: 5_000}}
iex> account_interface = EVM.Interface.Mock.MockAccountInterface.new(account_map, %{gas: 500, sub_state: nil, output: "output"})
iex> exec_env = %EVM.ExecEnv{stack_depth: 0, address: <<0::160>>, account_interface: account_interface, block_interface: block_interface}
iex> machine_state = %EVM.MachineState{gas: 300, stack: [1], memory: "________" <> "input"}
iex> %{machine_state: n_machine_state} =
...> EVM.Operation.System.call(
...> :call_code,
...> [100, <<0x01::160>>, 1_000, 5, 5, 1, 6],
...> %{exec_env: exec_env, machine_state: machine_state})
iex> n_machine_state
%EVM.MachineState{gas: 800, stack: [1, 1], active_words: 1, memory: "_output_input"}
# DELEGATECALL
iex> block_interface = EVM.Interface.Mock.MockBlockInterface.new(%Block.Header{})
iex> account_map = %{<<0::160>> => %{balance: 5_000}}
iex> account_interface = EVM.Interface.Mock.MockAccountInterface.new(account_map, %{gas: 500, sub_state: nil, output: "output"})
iex> exec_env = %EVM.ExecEnv{stack_depth: 0, address: <<0::160>>, account_interface: account_interface, block_interface: block_interface}
iex> machine_state = %EVM.MachineState{gas: 300, stack: [1], memory: "________" <> "input"}
iex> %{machine_state: n_machine_state} =
...> EVM.Operation.System.call(
...> :delegate_call,
...> [100, <<0x01::160>>, 5, 5, 1, 6],
...> %{exec_env: exec_env, machine_state: machine_state})
iex> n_machine_state
%EVM.MachineState{gas: 800, stack: [1, 1], active_words: 1, memory: "_output_input"}
create(Operation.stack_args, Operation.vm_map) :: Operation.op_result
Create a new account with associated code.
Examples
iex> block_interface = EVM.Interface.Mock.MockBlockInterface.new(%Block.Header{})
iex> account_map = %{<<100::160>> => %{balance: 5_000, nonce: 5}}
iex> account_interface = EVM.Interface.Mock.MockAccountInterface.new(account_map, %{gas: 500, sub_state: nil, output: "output"})
iex> exec_env = %EVM.ExecEnv{stack_depth: 0, address: <<100::160>>, account_interface: account_interface, block_interface: block_interface}
iex> machine_state = %EVM.MachineState{gas: 300, stack: [1], memory: "________" <> "input"}
iex> %{machine_state: n_machine_state} =
...> EVM.Operation.System.create(
...> [1_000, 5, 5],
...> %{exec_env: exec_env, machine_state: machine_state})
iex> n_machine_state
%EVM.MachineState{gas: 800, stack: [0x601bcc2189b7096d8dfaa6f74efeebef20486d0d, 1], active_words: 1, memory: "________input"}
return(Operation.stack_args, Operation.vm_map) :: Operation.op_result
Halt execution returning output data,
Examples
iex> EVM.Operation.System.return([5, 33], %{machine_state: %EVM.MachineState{active_words: 0}})
%EVM.MachineState{active_words: 2}
iex> EVM.Operation.System.return([5, 33], %{machine_state: %EVM.MachineState{active_words: 5}})
%EVM.MachineState{active_words: 5}
suicide(Operation.stack_args, Operation.vm_map) :: Operation.op_result
Halt execution and register account for later deletion.
Examples
iex> address = 0x0000000000000000000000000000000000000001
iex> suicide_address = 0x0000000000000000000000000000000000000001
iex> account_map = %{address => %{balance: 5_000, nonce: 5}}
iex> account_interface = EVM.Interface.Mock.MockAccountInterface.new(account_map)
iex> account_interface = EVM.Operation.System.suicide([suicide_address], %{stack: [], exec_env: %EVM.ExecEnv{address: address, account_interface: account_interface} })[:exec_env].account_interface
iex> account_interface |> EVM.Interface.AccountInterface.dump_storage |> Map.get(address)
nil