add external libraries to smart contract verifier

pull/1410/head
Ayrat Badykov 6 years ago
parent dcca791ebf
commit 0021d40344
No known key found for this signature in database
GPG Key ID: B44668E265E9396F
  1. 12
      apps/explorer/lib/explorer/smart_contract/verifier.ex
  2. 28
      apps/explorer/test/explorer/smart_contract/verifier_test.exs

@ -15,6 +15,18 @@ defmodule Explorer.SmartContract.Verifier do
def evaluate_authenticity(_, %{"contract_source_code" => ""}),
do: {:error, :contract_source_code}
def evaluate_authenticity(address_hash, %{
"name" => name,
"contract_source_code" => contract_source_code,
"optimization" => optimization,
"compiler_version" => compiler_version,
"external_libraries" => external_libraries
}) do
solc_output = CodeCompiler.run(name, compiler_version, contract_source_code, optimization, external_libraries)
compare_bytecodes(solc_output, address_hash)
end
def evaluate_authenticity(address_hash, %{
"name" => name,
"contract_source_code" => contract_source_code,

@ -28,6 +28,34 @@ defmodule Explorer.SmartContract.VerifierTest do
assert abi != nil
end
test "verifies the generated bytecode with external libraries" do
contract_data =
"#{System.cwd!()}/test/support/fixture/smart_contract/compiler_tests.json"
|> File.read!()
|> Jason.decode!()
|> List.first()
compiler_version = contract_data["compiler_version"]
external_libraries = contract_data["external_libraries"]
name = contract_data["name"]
optimize = contract_data["optimize"]
contract = contract_data["contract"]
expected_bytecode = contract_data["expected_bytecode"]
contract_address = insert(:contract_address, contract_code: "0x" <> expected_bytecode)
params = %{
"contract_source_code" => contract,
"compiler_version" => compiler_version,
"name" => name,
"optimization" => optimize,
"external_libraries" => external_libraries
}
assert {:ok, %{abi: abi}} = Verifier.evaluate_authenticity(contract_address.hash, params)
assert abi != nil
end
test "returns error when bytecode doesn't match", %{contract_code_info: contract_code_info} do
contract_address = insert(:contract_address, contract_code: contract_code_info.bytecode)

Loading…
Cancel
Save