diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c9add09bb..fbf41bcaa9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -66,6 +66,7 @@ - [#1900](https://github.com/poanetwork/blockscout/pull/1900) - SUPPORTED_CHAINS ENV var - [#1892](https://github.com/poanetwork/blockscout/pull/1892) - Remove temporary worker modules - [#1958](https://github.com/poanetwork/blockscout/pull/1958) - Default value for release link env var +- [#1964](https://github.com/poanetwork/blockscout/pull/1964) - ALLOWED_EVM_VERSIONS env var - [#1975](https://github.com/poanetwork/blockscout/pull/1975) - add log index to transaction view - [#1988](https://github.com/poanetwork/blockscout/pull/1988) - Fix wrong parity tasks names in Circle CI diff --git a/apps/explorer/config/config.exs b/apps/explorer/config/config.exs index 0ba1a960c7..94a1d79c6d 100644 --- a/apps/explorer/config/config.exs +++ b/apps/explorer/config/config.exs @@ -9,7 +9,10 @@ use Mix.Config config :explorer, ecto_repos: [Explorer.Repo], coin: System.get_env("COIN") || "POA", - token_functions_reader_max_retries: 3 + token_functions_reader_max_retries: 3, + allowed_evm_versions: + System.get_env("ALLOWED_EVM_VERSIONS") || + "homestead,tangerineWhistle,spuriousDragon,byzantium,constantinople,petersburg" config :explorer, Explorer.Counters.AverageBlockTime, enabled: true diff --git a/apps/explorer/lib/explorer/smart_contract/solidity/code_compiler.ex b/apps/explorer/lib/explorer/smart_contract/solidity/code_compiler.ex index 656f1b9734..3e41bb08fa 100644 --- a/apps/explorer/lib/explorer/smart_contract/solidity/code_compiler.ex +++ b/apps/explorer/lib/explorer/smart_contract/solidity/code_compiler.ex @@ -8,7 +8,6 @@ defmodule Explorer.SmartContract.Solidity.CodeCompiler do require Logger @new_contract_name "New.sol" - @allowed_evm_versions ["homestead", "tangerineWhistle", "spuriousDragon", "byzantium", "constantinople", "petersburg"] @doc """ Compiles a code in the solidity command line. @@ -72,13 +71,13 @@ defmodule Explorer.SmartContract.Solidity.CodeCompiler do code = Keyword.fetch!(params, :code) optimize = Keyword.fetch!(params, :optimize) optimization_runs = params |> Keyword.get(:optimization_runs, 200) |> Integer.to_string() - evm_version = Keyword.get(params, :evm_version, List.last(@allowed_evm_versions)) + evm_version = Keyword.get(params, :evm_version, List.last(allowed_evm_versions())) external_libs = Keyword.get(params, :external_libs, %{}) external_libs_string = Jason.encode!(external_libs) checked_evm_version = - if evm_version in @allowed_evm_versions do + if evm_version in allowed_evm_versions() do evm_version else "byzantium" @@ -125,7 +124,12 @@ defmodule Explorer.SmartContract.Solidity.CodeCompiler do end end - def allowed_evm_versions, do: @allowed_evm_versions + def allowed_evm_versions do + :explorer + |> Application.get_env(:allowed_evm_versions) + |> String.split(",") + |> Enum.map(fn version -> String.trim(version) end) + end def get_contract_info(contracts, _) when contracts == %{}, do: {:error, :compilation} diff --git a/apps/explorer/test/explorer/smart_contract/solidity/code_compiler_test.exs b/apps/explorer/test/explorer/smart_contract/solidity/code_compiler_test.exs index 57f15577ac..be68a03a0e 100644 --- a/apps/explorer/test/explorer/smart_contract/solidity/code_compiler_test.exs +++ b/apps/explorer/test/explorer/smart_contract/solidity/code_compiler_test.exs @@ -310,6 +310,34 @@ defmodule Explorer.SmartContract.Solidity.CodeCompilerTest do end end + # describe "allowed_evm_versions/0" do + # test "returns allowed evm versions defined by ALLOWED_EVM_VERSIONS env var" do + # Application.put_env(:explorer, :allowed_evm_versions, "CustomEVM1,CustomEVM2,CustomEVM3") + # response = CodeCompiler.allowed_evm_versions() + + # assert ["CustomEVM1", "CustomEVM2", "CustomEVM3"] = response + # end + + # test "returns allowed evm versions defined by not trimmed ALLOWED_EVM_VERSIONS env var" do + # Application.put_env(:explorer, :allowed_evm_versions, "CustomEVM1, CustomEVM2, CustomEVM3") + # response = CodeCompiler.allowed_evm_versions() + + # assert ["CustomEVM1", "CustomEVM2", "CustomEVM3"] = response + # end + + # test "returns default_allowed_evm_versions" do + # Application.put_env( + # :explorer, + # :allowed_evm_versions, + # "homestead,tangerineWhistle,spuriousDragon,byzantium,constantinople,petersburg" + # ) + + # response = CodeCompiler.allowed_evm_versions() + + # assert ["homestead", "tangerineWhistle", "spuriousDragon", "byzantium", "constantinople", "petersburg"] = response + # end + # end + defp remove_init_data_and_whisper_data(code) do {res, _} = code