Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EIP 145 #417

Merged
merged 10 commits into from
Sep 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions .dialyzer.ignore-warnings
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,21 @@

# evm warnings

apps/evm/lib/evm/functions.ex:172: Function 'not_enough_gas?'/2 has no local return
apps/evm/lib/evm/functions.ex:184: Function 'is_invalid_jump_destination?'/3 will never be called
apps/evm/lib/evm/functions.ex:194: Function 'static_state_modification?'/2 will never be called
apps/evm/lib/evm/gas.ex:134: Function cost/2 has no local return
apps/evm/lib/evm/gas.ex:134: Function cost/3 has no local return
apps/evm/lib/evm/gas.ex:139: The call 'Elixir.EVM.Gas':operation_cost(atom(),_inputs@1::[integer()],_machine_state@1::#{'__struct__':='Elixir.EVM.MachineState', 'active_words':=integer(), 'gas':=integer(), 'last_return_data':=binary(), 'memory':=binary(), 'previously_active_words':=integer(), 'program_counter':=integer(), 'stack':=[integer()]},_exec_env@1::#{'__struct__':='Elixir.EVM.ExecEnv', 'account_interface':=atom(), 'address':=<<_:160>>, 'block_interface':=atom(), 'config':=atom(), 'data':=binary(), 'gas_price':=integer(), 'machine_code':=binary(), 'originator':=<<_:160>>, 'sender':=<<_:160>>, 'stack_depth':=integer(), 'static':=boolean(), 'value_in_wei':=integer()}) breaks the contract (atom(),['Elixir.EVM':val()],['Elixir.EVM':val()],'Elixir.EVM.MachineState':t()) -> t() | 'nil'
apps/evm/lib/evm/gas.ex:300: Function operation_cost/0 has no local return
apps/evm/lib/evm/gas.ex:300: The call 'Elixir.EVM.Gas':operation_cost('nil','nil','nil','nil') breaks the contract (atom(),['Elixir.EVM':val()],['Elixir.EVM':val()],'Elixir.EVM.MachineState':t()) -> t() | 'nil'
apps/evm/lib/evm/gas.ex:300: Function operation_cost/1 has no local return
apps/evm/lib/evm/gas.ex:300: The call 'Elixir.EVM.Gas':operation_cost(__@1::any(),'nil','nil','nil') breaks the contract (atom(),['Elixir.EVM':val()],['Elixir.EVM':val()],'Elixir.EVM.MachineState':t()) -> t() | 'nil'
apps/evm/lib/evm/gas.ex:300: Function operation_cost/2 has no local return
apps/evm/lib/evm/gas.ex:300: The call 'Elixir.EVM.Gas':operation_cost(__@1::any(),__@2::any(),'nil','nil') breaks the contract (atom(),['Elixir.EVM':val()],['Elixir.EVM':val()],'Elixir.EVM.MachineState':t()) -> t() | 'nil'
apps/evm/lib/evm/gas.ex:300: Function operation_cost/3 has no local return
apps/evm/lib/evm/gas.ex:300: The call 'Elixir.EVM.Gas':operation_cost(__@1::any(),__@2::any(),__@3::any(),'nil') breaks the contract (atom(),['Elixir.EVM':val()],['Elixir.EVM':val()],'Elixir.EVM.MachineState':t()) -> t() | 'nil'
apps/evm/lib/evm/gas.ex:559: Function gas_cost_for_nested_operation/2 will never be called
apps/evm/lib/evm/functions.ex:181: Function 'not_enough_gas?'/2 has no local return
apps/evm/lib/evm/functions.ex:193: Function 'is_invalid_jump_destination?'/3 will never be called
apps/evm/lib/evm/functions.ex:203: Function 'static_state_modification?'/2 will never be called
apps/evm/lib/evm/gas.ex:137: Function cost/2 has no local return
apps/evm/lib/evm/gas.ex:137: Function cost/3 has no local return
apps/evm/lib/evm/gas.ex:142: The call 'Elixir.EVM.Gas':operation_cost(atom(),_inputs@1::[integer()],_machine_state@1::#{'__struct__':='Elixir.EVM.MachineState', 'active_words':=integer(), 'gas':=integer(), 'last_return_data':=binary(), 'memory':=binary(), 'previously_active_words':=integer(), 'program_counter':=integer(), 'stack':=[integer()]},_exec_env@1::#{'__struct__':='Elixir.EVM.ExecEnv', 'account_interface':=atom(), 'address':=<<_:160>>, 'block_interface':=atom(), 'config':=atom(), 'data':=binary(), 'gas_price':=integer(), 'machine_code':=binary(), 'originator':=<<_:160>>, 'sender':=<<_:160>>, 'stack_depth':=integer(), 'static':=boolean(), 'value_in_wei':=integer()}) breaks the contract (atom(),['Elixir.EVM':val()],['Elixir.EVM':val()],'Elixir.EVM.MachineState':t()) -> t() | 'nil'
apps/evm/lib/evm/gas.ex:303: Function operation_cost/0 has no local return
apps/evm/lib/evm/gas.ex:303: The call 'Elixir.EVM.Gas':operation_cost('nil','nil','nil','nil') breaks the contract (atom(),['Elixir.EVM':val()],['Elixir.EVM':val()],'Elixir.EVM.MachineState':t()) -> t() | 'nil'
apps/evm/lib/evm/gas.ex:303: Function operation_cost/1 has no local return
apps/evm/lib/evm/gas.ex:303: The call 'Elixir.EVM.Gas':operation_cost(__@1::any(),'nil','nil','nil') breaks the contract (atom(),['Elixir.EVM':val()],['Elixir.EVM':val()],'Elixir.EVM.MachineState':t()) -> t() | 'nil'
apps/evm/lib/evm/gas.ex:303: Function operation_cost/2 has no local return
apps/evm/lib/evm/gas.ex:303: The call 'Elixir.EVM.Gas':operation_cost(__@1::any(),__@2::any(),'nil','nil') breaks the contract (atom(),['Elixir.EVM':val()],['Elixir.EVM':val()],'Elixir.EVM.MachineState':t()) -> t() | 'nil'
apps/evm/lib/evm/gas.ex:303: Function operation_cost/3 has no local return
apps/evm/lib/evm/gas.ex:303: The call 'Elixir.EVM.Gas':operation_cost(__@1::any(),__@2::any(),__@3::any(),'nil') breaks the contract (atom(),['Elixir.EVM':val()],['Elixir.EVM':val()],'Elixir.EVM.MachineState':t()) -> t() | 'nil'
apps/evm/lib/evm/gas.ex:562: Function gas_cost_for_nested_operation/2 will never be called
apps/evm/lib/evm/machine_state.ex:53: Function subtract_gas/2 has no local return
apps/evm/lib/evm/operation/environmental_information.ex:114: Function calldataload/2 has no local return
apps/evm/lib/evm/operation/environmental_information.ex:117: The call 'Elixir.EVM.Helpers':decode_signed(binary()) breaks the contract (integer() | 'nil') -> 'Elixir.EVM':val() | 'nil'
Expand Down
2 changes: 2 additions & 0 deletions apps/blockchain/config/test.exs
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
use Mix.Config

config :ex_unit, case_load_timeout: 120_000
8 changes: 7 additions & 1 deletion apps/blockchain/scripts/generate_blockchain_tests.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule GenerateBlockchainTests do
alias Block.Header

@base_path System.cwd() <> "/../../ethereum_common_tests/BlockchainTests/"
@allowed_forks ["Byzantium", "Frontier", "Homestead", "EIP150", "EIP158"]
@allowed_forks ["Constantinople", "Byzantium", "Frontier", "Homestead", "EIP150", "EIP158"]
@byzantium_failing_tests_path System.cwd() <> "/test/support/byzantium_failing_tests.txt"
@initial_pass_fail {[], []}
@number_of_test_groups 20
Expand Down Expand Up @@ -164,6 +164,9 @@ defmodule GenerateBlockchainTests do
"Byzantium" ->
Chain.load_chain(:byzantium_test, config)

"Constantinople" ->
Chain.load_chain(:constantinople_test, config)

_ ->
nil
end
Expand All @@ -186,6 +189,9 @@ defmodule GenerateBlockchainTests do
"Byzantium" ->
EVM.Configuration.Byzantium.new()

"Constantinople" ->
EVM.Configuration.Constantinople.new()

_ ->
nil
end
Expand Down
11 changes: 8 additions & 3 deletions apps/blockchain/scripts/generate_state_tests.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,24 @@ defmodule GenerateStateTests do

use EthCommonTest.Harness

@hardforks ["EIP158", "EIP150", "Homestead", "Frontier", "Byzantium"]
@hardforks ["EIP158", "EIP150", "Homestead", "Frontier", "Byzantium", "Constantinople"]
@twenty_minutes 60 * 20 * 1000
@initial_state %{
passing: %{
"Homestead" => [],
"Frontier" => [],
"EIP150" => [],
"EIP158" => [],
"Byzantium" => []
"Byzantium" => [],
"Constantinople" => []
},
failing: %{
"Homestead" => [],
"Frontier" => [],
"EIP150" => [],
"EIP158" => [],
"Byzantium" => []
"Byzantium" => [],
"Constantinople" => []
}
}

Expand Down Expand Up @@ -204,6 +206,9 @@ defmodule GenerateStateTests do
"Byzantium" ->
EVM.Configuration.Byzantium.new()

"Constantinople" ->
EVM.Configuration.Constantinople.new()

_ ->
nil
end
Expand Down
10 changes: 10 additions & 0 deletions apps/blockchain/test/blockchain/state_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ defmodule Blockchain.StateTest do
"stTransactionTest/EmptyTransaction2",
"stZeroKnowledge2/ecmul_0-3_5616_28000_96"
],
"Constantinople" => [
"stCreateTest/CreateOOGafterInitCodeReturndata",
"stReturnDataTest/returndatacopy_following_failing_call",
"stReturnDataTest/returndatacopy_initial_256",
"stRevertTest/RevertOpcodeMultipleSubCalls",
"stZeroKnowledge2/ecmul_0-3_5616_28000_96"
],
"EIP150" => [
"stInitCodeTest/NotEnoughCashContractCreation",
"stInitCodeTest/OutOfGasContractCreation",
Expand Down Expand Up @@ -359,6 +366,9 @@ defmodule Blockchain.StateTest do
"Byzantium" ->
EVM.Configuration.Byzantium.new()

"Constantinople" ->
EVM.Configuration.Constantinople.new()

_ ->
nil
end
Expand Down
14 changes: 13 additions & 1 deletion apps/blockchain/test/blockchain_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@ defmodule BlockchainTest do
"GeneralStateTests/stSpecialTest/failed_tx_xcf416c53_d0g0v0.json"
],
"Byzantium" => String.split(@failing_byzantium_tests, "\n"),
"Constantinople" => [
"GeneralStateTests/stCreateTest/CreateOOGafterInitCodeReturndata_d0g1v0.json",
"GeneralStateTests/stReturnDataTest/modexp_modsize0_returndatasize_d0g1v0.json",
"GeneralStateTests/stReturnDataTest/modexp_modsize0_returndatasize_d0g2v0.json",
"GeneralStateTests/stReturnDataTest/modexp_modsize0_returndatasize_d0g3v0.json",
"bcStateTests/blockhashNonConstArg.json"
],
# the rest are not implemented yet
"Constantinople" => [],
"EIP158ToByzantiumAt5" => [],
"FrontierToHomesteadAt5" => [],
"HomesteadToDaoAt5" => [],
Expand Down Expand Up @@ -158,6 +164,9 @@ defmodule BlockchainTest do
"Byzantium" ->
Chain.load_chain(:byzantium_test, config)

"Constantinople" ->
Chain.load_chain(:constantinople_test, config)

_ ->
nil
end
Expand All @@ -180,6 +189,9 @@ defmodule BlockchainTest do
"Byzantium" ->
EVM.Configuration.Byzantium.new()

"Constantinople" ->
EVM.Configuration.Constantinople.new()

_ ->
nil
end
Expand Down
4 changes: 4 additions & 0 deletions apps/evm/lib/evm/configuration.ex
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,8 @@ defprotocol EVM.Configuration do
# EIP198
@spec has_mod_exp_builtin?(t) :: boolean()
def has_mod_exp_builtin?(t)

# EIP145
@spec has_shift_operations?(t) :: boolean()
def has_shift_operations?(t)
end
4 changes: 4 additions & 0 deletions apps/evm/lib/evm/configuration/byzantium.ex
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,8 @@ defimpl EVM.Configuration, for: EVM.Configuration.Byzantium do

@spec has_ec_pairing_builtin?(Configuration.t()) :: boolean()
def has_ec_pairing_builtin?(config), do: config.has_ec_pairing_builtin

@spec has_shift_operations?(Configuration.t()) :: boolean()
def has_shift_operations?(config),
do: Configuration.has_shift_operations?(config.fallback_config)
end
95 changes: 95 additions & 0 deletions apps/evm/lib/evm/configuration/constantinople.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
defmodule EVM.Configuration.Constantinople do
defstruct fallback_config: EVM.Configuration.Byzantium.new(),
has_shift_operations: true

def new do
%__MODULE__{}
end
end

defimpl EVM.Configuration, for: EVM.Configuration.Constantinople do
alias EVM.Configuration

@spec contract_creation_cost(Configuration.t()) :: integer()
def contract_creation_cost(config),
do: Configuration.contract_creation_cost(config.fallback_config)

@spec has_delegate_call?(Configuration.t()) :: boolean()
def has_delegate_call?(config), do: Configuration.has_delegate_call?(config.fallback_config)

@spec max_signature_s(Configuration.t()) :: atom()
def max_signature_s(config), do: Configuration.max_signature_s(config.fallback_config)

@spec fail_contract_creation_lack_of_gas?(Configuration.t()) :: boolean()
def fail_contract_creation_lack_of_gas?(config),
do: Configuration.fail_contract_creation_lack_of_gas?(config.fallback_config)

@spec extcodesize_cost(Configuration.t()) :: integer()
def extcodesize_cost(config), do: Configuration.extcodesize_cost(config.fallback_config)

@spec extcodecopy_cost(Configuration.t()) :: integer()
def extcodecopy_cost(config), do: Configuration.extcodecopy_cost(config.fallback_config)

@spec balance_cost(Configuration.t()) :: integer()
def balance_cost(config), do: Configuration.balance_cost(config.fallback_config)

@spec sload_cost(Configuration.t()) :: integer()
def sload_cost(config), do: Configuration.sload_cost(config.fallback_config)

@spec call_cost(Configuration.t()) :: integer()
def call_cost(config), do: Configuration.call_cost(config.fallback_config)

@spec selfdestruct_cost(Configuration.t(), keyword()) :: integer()
def selfdestruct_cost(config, params),
do: Configuration.selfdestruct_cost(config.fallback_config, params)

@spec fail_nested_operation_lack_of_gas?(Configuration.t()) :: boolean()
def fail_nested_operation_lack_of_gas?(config),
do: Configuration.fail_nested_operation_lack_of_gas?(config.fallback_config)

@spec exp_byte_cost(Configuration.t()) :: integer()
def exp_byte_cost(config), do: Configuration.exp_byte_cost(config.fallback_config)

@spec limit_contract_code_size?(Configuration.t(), integer()) :: boolean()
def limit_contract_code_size?(config, size),
do: Configuration.limit_contract_code_size?(config.fallback_config, size)

@spec increment_nonce_on_create?(Configuration.t()) :: boolean()
def increment_nonce_on_create?(config),
do: Configuration.increment_nonce_on_create?(config.fallback_config)

@spec empty_account_value_transfer?(Configuration.t()) :: boolean()
def empty_account_value_transfer?(config),
do: Configuration.empty_account_value_transfer?(config.fallback_config)

@spec clean_touched_accounts?(Configuration.t()) :: boolean()
def clean_touched_accounts?(config),
do: Configuration.clean_touched_accounts?(config.fallback_config)

@spec has_revert?(Configuration.t()) :: boolean()
def has_revert?(config), do: Configuration.has_revert?(config.fallback_config)

@spec has_static_call?(Configuration.t()) :: boolean()
def has_static_call?(config), do: Configuration.has_static_call?(config.fallback_config)

@spec support_variable_length_return_value?(Configuration.t()) :: boolean()
def support_variable_length_return_value?(config),
do: Configuration.support_variable_length_return_value?(config.fallback_config)

@spec has_mod_exp_builtin?(Configuration.t()) :: boolean()
def has_mod_exp_builtin?(config), do: Configuration.has_mod_exp_builtin?(config.fallback_config)

@spec has_ec_add_builtin?(Configuration.t()) :: boolean()
def has_ec_add_builtin?(config), do: Configuration.has_ec_add_builtin?(config.fallback_config)

@spec has_ec_mult_builtin?(Configuration.t()) :: boolean()
def has_ec_mult_builtin?(config), do: Configuration.has_ec_mult_builtin?(config.fallback_config)

@spec has_ec_pairing_builtin?(Configuration.t()) :: boolean()
def has_ec_pairing_builtin?(config),
do: Configuration.has_ec_pairing_builtin?(config.fallback_config)

@spec has_shift_operations?(Configuration.t()) :: boolean()
def has_shift_operations?(config),
do: config.has_shift_operations
end
4 changes: 4 additions & 0 deletions apps/evm/lib/evm/configuration/eip150.ex
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,8 @@ defimpl EVM.Configuration, for: EVM.Configuration.EIP150 do
@spec has_ec_pairing_builtin?(Configuration.t()) :: boolean()
def has_ec_pairing_builtin?(config),
do: Configuration.has_ec_pairing_builtin?(config.fallback_config)

@spec has_shift_operations?(Configuration.t()) :: boolean()
def has_shift_operations?(config),
do: Configuration.has_shift_operations?(config.fallback_config)
end
4 changes: 4 additions & 0 deletions apps/evm/lib/evm/configuration/eip158.ex
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,8 @@ defimpl EVM.Configuration, for: EVM.Configuration.EIP158 do
@spec has_ec_pairing_builtin?(Configuration.t()) :: boolean()
def has_ec_pairing_builtin?(config),
do: Configuration.has_ec_pairing_builtin?(config.fallback_config)

@spec has_shift_operations?(Configuration.t()) :: boolean()
def has_shift_operations?(config),
do: Configuration.has_shift_operations?(config.fallback_config)
end
6 changes: 5 additions & 1 deletion apps/evm/lib/evm/configuration/frontier.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ defmodule EVM.Configuration.Frontier do
has_mod_exp_builtin: false,
has_ec_add_builtin: false,
has_ec_mult_builtin: false,
has_ec_pairing_builtin: false
has_ec_pairing_builtin: false,
has_shift_operations: false

def new do
%__MODULE__{}
Expand Down Expand Up @@ -100,4 +101,7 @@ defimpl EVM.Configuration, for: EVM.Configuration.Frontier do

@spec has_ec_pairing_builtin?(Configuration.t()) :: boolean()
def has_ec_pairing_builtin?(config), do: config.has_ec_pairing_builtin

@spec has_shift_operations?(Configuration.t()) :: boolean()
def has_shift_operations?(config), do: config.has_shift_operations
end
4 changes: 4 additions & 0 deletions apps/evm/lib/evm/configuration/homestead.ex
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,8 @@ defimpl EVM.Configuration, for: EVM.Configuration.Homestead do
@spec has_ec_pairing_builtin?(Configuration.t()) :: boolean()
def has_ec_pairing_builtin?(config),
do: Configuration.has_ec_pairing_builtin?(config.fallback_config)

@spec has_shift_operations?(Configuration.t()) :: boolean()
def has_shift_operations?(config),
do: Configuration.has_shift_operations?(config.fallback_config)
end
21 changes: 15 additions & 6 deletions apps/evm/lib/evm/functions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule EVM.Functions do
fit in other modules.
"""

alias EVM.{ExecEnv, MachineCode, MachineState, Operation, Stack, Gas}
alias EVM.{ExecEnv, MachineCode, MachineState, Operation, Stack, Gas, Configuration}
alias EVM.Operation.Metadata

@max_stack 1024
Expand Down Expand Up @@ -146,22 +146,31 @@ defmodule EVM.Functions do

case operation_metadata.sym do
:delegatecall ->
if EVM.Configuration.has_delegate_call?(config), do: operation_metadata
if Configuration.has_delegate_call?(config), do: operation_metadata

:revert ->
if EVM.Configuration.has_revert?(config), do: operation_metadata
if Configuration.has_revert?(config), do: operation_metadata

:staticcall ->
if EVM.Configuration.has_static_call?(config), do: operation_metadata
if Configuration.has_static_call?(config), do: operation_metadata

:returndatasize ->
if EVM.Configuration.support_variable_length_return_value?(config),
if Configuration.support_variable_length_return_value?(config),
do: operation_metadata

:returndatacopy ->
if EVM.Configuration.support_variable_length_return_value?(config),
if Configuration.support_variable_length_return_value?(config),
do: operation_metadata

:shl ->
if Configuration.has_shift_operations?(config), do: operation_metadata

:shr ->
if Configuration.has_shift_operations?(config), do: operation_metadata

:sar ->
if Configuration.has_shift_operations?(config), do: operation_metadata

_ ->
operation_metadata
end
Expand Down
5 changes: 4 additions & 1 deletion apps/evm/lib/evm/gas.ex
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ defmodule EVM.Gas do
:calldataload,
:mload,
:mstore,
:mstore8
:mstore8,
:shl,
:shr,
:sar
] ++ @push_instrs ++ @dup_instrs ++ @swap_instrs
@w_low_instr [:mul, :div, :sdiv, :mod, :smod, :signextend]
@w_mid_instr [:addmod, :mulmod, :jump]
Expand Down
Loading