Merge branch 'master' into ab-erc721-token-balances-fix

pull/1540/head
Victor Baranov 6 years ago committed by GitHub
commit 79865af08b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      apps/block_scout_web/lib/block_scout_web/controllers/address_contract_verification_controller.ex
  2. 5
      apps/block_scout_web/lib/block_scout_web/templates/address_contract_verification/new.html.eex
  3. 43
      apps/block_scout_web/priv/gettext/default.pot
  4. 43
      apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po
  5. 8
      apps/block_scout_web/test/block_scout_web/features/address_contract_verification_test.exs
  6. 2015
      apps/block_scout_web/test/support/fixture/smart_contract/solc_bin.json
  7. 13
      apps/explorer/lib/explorer/smart_contract/solidity/code_compiler.ex
  8. 4
      apps/explorer/lib/explorer/smart_contract/verifier.ex
  9. 3
      apps/explorer/priv/compile_solc.js
  10. 46
      apps/explorer/test/explorer/smart_contract/solidity/code_compiler_test.exs

@ -4,6 +4,8 @@ defmodule BlockScoutWeb.AddressContractVerificationController do
alias Explorer.Chain.SmartContract
alias Explorer.SmartContract.{Publisher, Solidity.CompilerVersion}
@evm_versions ["homestead", "tangerineWhistle", "spuriousDragon", "byzantium", "constantinople"]
def new(conn, %{"address_id" => address_hash_string}) do
changeset =
SmartContract.changeset(
@ -13,7 +15,7 @@ defmodule BlockScoutWeb.AddressContractVerificationController do
{:ok, compiler_versions} = CompilerVersion.fetch_versions()
render(conn, "new.html", changeset: changeset, compiler_versions: compiler_versions)
render(conn, "new.html", changeset: changeset, compiler_versions: compiler_versions, evm_versions: @evm_versions)
end
def create(
@ -21,17 +23,20 @@ defmodule BlockScoutWeb.AddressContractVerificationController do
%{
"address_id" => address_hash_string,
"smart_contract" => smart_contract,
"external_libraries" => external_libraries
"external_libraries" => external_libraries,
"evm_version" => evm_version
}
) do
case Publisher.publish(address_hash_string, smart_contract, external_libraries) do
smart_sontact_with_evm_version = Map.put(smart_contract, "evm_version", evm_version)
case Publisher.publish(address_hash_string, smart_sontact_with_evm_version, external_libraries) do
{:ok, _smart_contract} ->
redirect(conn, to: address_contract_path(conn, :index, address_hash_string))
{:error, changeset} ->
{:ok, compiler_versions} = CompilerVersion.fetch_versions()
render(conn, "new.html", changeset: changeset, compiler_versions: compiler_versions)
render(conn, "new.html", changeset: changeset, compiler_versions: compiler_versions, evm_versions: @evm_versions)
end
end
end

@ -27,6 +27,11 @@
<%= error_tag f, :compiler_version, id: "compiler-help-block", class: "text-danger" %>
</div>
<div class="form-group">
<%= label :evm_version, :evm_version, gettext("EVM Vesion") %>
<%= select :evm_version, :evm_version, @evm_versions, class: "form-control", selected: "byzantium", "aria-describedby": "evm-version-help-block" %>
</div>
<div class="form-group mb-4">
<%= label f, "Optimization" %>

@ -197,7 +197,7 @@ msgid "Blocks Validated"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:125
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:130
#: lib/block_scout_web/templates/api_docs/_action_tile.html.eex:24
msgid "Cancel"
msgstr ""
@ -367,7 +367,7 @@ msgid "ETH"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:47
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:52
msgid "Enter the Solidity Contract Code below"
msgstr ""
@ -603,7 +603,7 @@ msgid "Next Page"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:35
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:40
msgid "No"
msgstr ""
@ -713,7 +713,7 @@ msgid "Request URL"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:123
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:128
msgid "Reset"
msgstr ""
@ -1029,7 +1029,7 @@ msgid "Verify & Publish"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:122
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:127
msgid "Verify & publish"
msgstr ""
@ -1089,7 +1089,7 @@ msgid "Wei"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:40
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:45
msgid "Yes"
msgstr ""
@ -1170,7 +1170,7 @@ msgid "Loading..."
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:120
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:125
msgid "Loading...."
msgstr ""
@ -1587,62 +1587,62 @@ msgid "Genesis Block"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:66
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:71
msgid "1 Library Address"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:61
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:66
msgid "1 Library Name"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:76
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:81
msgid "2 Library Address"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:71
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:76
msgid "2 Library Name"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:86
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:91
msgid "3 Library Address"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:81
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:86
msgid "3 Library Name"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:96
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:101
msgid "4 Library Address"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:91
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:96
msgid "4 Library Name"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:106
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:111
msgid "5 Library Address"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:101
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:106
msgid "5 Library Name"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:58
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:63
msgid "Contract Libraries"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:53
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:58
msgid "Enter contructor arguments if the contract had any"
msgstr ""
@ -1681,3 +1681,8 @@ msgstr ""
#: lib/block_scout_web/templates/admin/dashboard/index.html.eex:21
msgid "Run"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:31
msgid "EVM Vesion"
msgstr ""

@ -197,7 +197,7 @@ msgid "Blocks Validated"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:125
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:130
#: lib/block_scout_web/templates/api_docs/_action_tile.html.eex:24
msgid "Cancel"
msgstr ""
@ -367,7 +367,7 @@ msgid "ETH"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:47
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:52
msgid "Enter the Solidity Contract Code below"
msgstr ""
@ -603,7 +603,7 @@ msgid "Next Page"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:35
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:40
msgid "No"
msgstr ""
@ -713,7 +713,7 @@ msgid "Request URL"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:123
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:128
msgid "Reset"
msgstr ""
@ -1029,7 +1029,7 @@ msgid "Verify & Publish"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:122
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:127
msgid "Verify & publish"
msgstr ""
@ -1089,7 +1089,7 @@ msgid "Wei"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:40
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:45
msgid "Yes"
msgstr ""
@ -1170,7 +1170,7 @@ msgid "Loading..."
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:120
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:125
msgid "Loading...."
msgstr ""
@ -1587,62 +1587,62 @@ msgid "Genesis Block"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:66
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:71
msgid "1 Library Address"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:61
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:66
msgid "1 Library Name"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:76
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:81
msgid "2 Library Address"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:71
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:76
msgid "2 Library Name"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:86
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:91
msgid "3 Library Address"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:81
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:86
msgid "3 Library Name"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:96
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:101
msgid "4 Library Address"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:91
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:96
msgid "4 Library Name"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:106
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:111
msgid "5 Library Address"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:101
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:106
msgid "5 Library Name"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:58
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:63
msgid "Contract Libraries"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:53
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:58
msgid "Enter contructor arguments if the contract had any"
msgstr ""
@ -1681,3 +1681,8 @@ msgstr ""
#: lib/block_scout_web/templates/admin/dashboard/index.html.eex:21
msgid "Run"
msgstr ""
#, elixir-format, fuzzy
#: lib/block_scout_web/templates/address_contract_verification/new.html.eex:31
msgid "EVM Vesion"
msgstr ""

@ -48,7 +48,13 @@ defmodule BlockScoutWeb.AddressContractVerificationTest do
session
|> ContractVerifyPage.visit_page("0x1e0eaa06d02f965be2dfe0bc9ff52b2d82133461")
|> ContractVerifyPage.fill_form(%{contract_name: "", version: nil, optimization: nil, source_code: ""})
|> ContractVerifyPage.fill_form(%{
contract_name: "",
version: nil,
optimization: nil,
source_code: "",
evm_version: "byzantium"
})
|> ContractVerifyPage.verify_and_publish()
|> assert_has(ContractVerifyPage.validation_error())
end

@ -4,6 +4,7 @@ defmodule Explorer.SmartContract.Solidity.CodeCompiler do
"""
@new_contract_name "New.sol"
@allowed_evm_versions ["homestead", "tangerineWhistle", "spuriousDragon", "byzantium", "constantinople"]
@doc """
Compiles a code in the solidity command line.
@ -60,9 +61,16 @@ defmodule Explorer.SmartContract.Solidity.CodeCompiler do
}
}
"""
def run(name, compiler_version, code, optimize, external_libs \\ %{}) do
def run(name, compiler_version, code, optimize, evm_version \\ "byzantium", external_libs \\ %{}) do
external_libs_string = Jason.encode!(external_libs)
evm_version =
if evm_version in @allowed_evm_versions do
evm_version
else
"byzantium"
end
{response, _status} =
System.cmd(
"node",
@ -72,7 +80,8 @@ defmodule Explorer.SmartContract.Solidity.CodeCompiler do
compiler_version,
optimize_value(optimize),
@new_contract_name,
external_libs_string
external_libs_string,
evm_version
]
)

@ -23,8 +23,10 @@ defmodule Explorer.SmartContract.Verifier do
compiler_version = Map.fetch!(params, "compiler_version")
external_libraries = Map.get(params, "external_libraries", %{})
constructor_arguments = Map.get(params, "constructor_arguments", "")
evm_version = Map.get(params, "evm_version", "byzantium")
solc_output = CodeCompiler.run(name, compiler_version, contract_source_code, optimization, external_libraries)
solc_output =
CodeCompiler.run(name, compiler_version, contract_source_code, optimization, evm_version, external_libraries)
compare_bytecodes(solc_output, address_hash, constructor_arguments)
end

@ -7,6 +7,7 @@ var version = process.argv[3];
var optimize = process.argv[4];
var newContractName = process.argv[5];
var externalLibraries = JSON.parse(process.argv[6])
var evmVersion = process.argv[7]
var compiled_code = solc.loadRemoteVersion(version, function (err, solcSnapshot) {
if (err) {
@ -20,7 +21,7 @@ var compiled_code = solc.loadRemoteVersion(version, function (err, solcSnapshot)
}
},
settings: {
evmVersion: 'byzantium',
evmVersion: evmVersion,
optimizer: {
enabled: optimize == '1',
runs: 200

@ -65,6 +65,7 @@ defmodule Explorer.SmartContract.Solidity.CodeCompilerTest do
compiler_version,
contract,
optimize,
"byzantium",
external_libraries
)
@ -75,7 +76,50 @@ defmodule Explorer.SmartContract.Solidity.CodeCompilerTest do
end)
end
test "compile in an older solidity version" do
test "compiles with constantinople evm version" do
optimize = false
name = "MyTest"
code = """
pragma solidity 0.5.2;
contract MyTest {
constructor() public {
}
mapping(address => bytes32) public myMapping;
function contractHash(address _addr) public {
bytes32 hash;
assembly { hash := extcodehash(_addr) }
myMapping[_addr] = hash;
}
function justHash(bytes memory _bytes)
public
pure
returns (bytes32)
{
return keccak256(_bytes);
}
}
"""
version = "v0.5.2+commit.1df8f40c"
evm_version = "constantinople"
response = CodeCompiler.run(name, version, code, optimize, evm_version)
assert {:ok,
%{
"abi" => _,
"bytecode" => _,
"name" => _
}} = response
end
test "compiles in an older solidity version" do
optimize = false
name = "SimpleStorage"

Loading…
Cancel
Save