evm v0.1.11 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> db = MerklePatriciaTree.Test.random_ets_db()
iex> state = MerklePatriciaTree.Trie.new(db)
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})
iex> contract_interface = EVM.Interface.Mock.MockContractInterface.new(state, 500, nil, "output")
iex> exec_env = %EVM.ExecEnv{stack_depth: 0, address: <<0::160>>, account_interface: account_interface, contract_interface: contract_interface, block_interface: block_interface}
iex> machine_state = %EVM.MachineState{gas: 300, stack: [1], memory: "________" <> "input"}
iex> %{machine_state: n_machine_state, state: n_state} =
...> EVM.Operation.System.call(
...> :call,
...> [100, <<0x01::160>>, 1_000, 5, 5, 1, 6],
...> %{state: state, 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}
iex> n_state == state
true
# CALLCODE
iex> db = MerklePatriciaTree.Test.random_ets_db()
iex> state = MerklePatriciaTree.Trie.new(db)
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: account_map})
iex> contract_interface = EVM.Interface.Mock.MockContractInterface.new(state, 500, nil, "output")
iex> exec_env = %EVM.ExecEnv{stack_depth: 0, address: <<0::160>>, account_interface: account_interface, contract_interface: contract_interface, block_interface: block_interface}
iex> machine_state = %EVM.MachineState{gas: 300, stack: [1], memory: "________" <> "input"}
iex> %{machine_state: n_machine_state, state: n_state} =
...> EVM.Operation.System.call(
...> :call_code,
...> [100, <<0x01::160>>, 1_000, 5, 5, 1, 6],
...> %{state: state, 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"}
iex> n_state == state
true
# DELEGATECALL
iex> db = MerklePatriciaTree.Test.random_ets_db()
iex> state = MerklePatriciaTree.Trie.new(db)
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: account_map})
iex> contract_interface = EVM.Interface.Mock.MockContractInterface.new(state, 500, nil, "output")
iex> exec_env = %EVM.ExecEnv{stack_depth: 0, address: <<0::160>>, account_interface: account_interface, contract_interface: contract_interface, block_interface: block_interface}
iex> machine_state = %EVM.MachineState{gas: 300, stack: [1], memory: "________" <> "input"}
iex> %{machine_state: n_machine_state, state: n_state} =
...> EVM.Operation.System.call(
...> :delegate_call,
...> [100, <<0x01::160>>, 5, 5, 1, 6],
...> %{state: state, 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"}
iex> n_state == state
true
create(Operation.stack_args, Operation.vm_map) :: Operation.op_result
Create a new account with associated code.
Examples
iex> db = MerklePatriciaTree.Test.random_ets_db()
iex> state = MerklePatriciaTree.Trie.new(db)
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: account_map})
iex> contract_interface = EVM.Interface.Mock.MockContractInterface.new(state, 500, nil, "output")
iex> exec_env = %EVM.ExecEnv{stack_depth: 0, address: <<100::160>>, account_interface: account_interface, contract_interface: contract_interface, block_interface: block_interface}
iex> machine_state = %EVM.MachineState{gas: 300, stack: [1], memory: "________" <> "input"}
iex> %{machine_state: n_machine_state, state: n_state} =
...> EVM.Operation.System.create(
...> [1_000, 5, 5],
...> %{state: state, exec_env: exec_env, machine_state: machine_state})
iex> n_machine_state
%EVM.MachineState{gas: 800, stack: [EVM.Helpers.left_pad_bytes(100, 20), 1], active_words: 1, memory: "________input"}
iex> n_state == state
true
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.
TODO: Implement opcode
Examples
iex> EVM.Operation.System.suicide([], %{stack: []})
:unimplemented