diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index 62260df046..e58953404d 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -1892,7 +1892,8 @@ defmodule Explorer.Chain do !is_nil(transaction.contracts_creation_transaction) -> Data.to_string(transaction.contracts_creation_transaction.input) - true -> "" + true -> + "" end end diff --git a/apps/explorer/lib/explorer/smart_contract/verifier.ex b/apps/explorer/lib/explorer/smart_contract/verifier.ex index e7cc8c78a4..b72aa470f8 100644 --- a/apps/explorer/lib/explorer/smart_contract/verifier.ex +++ b/apps/explorer/lib/explorer/smart_contract/verifier.ex @@ -44,7 +44,7 @@ defmodule Explorer.SmartContract.Verifier do generated_bytecode != blockchain_bytecode -> {:error, :generated_bytecode} - !ConstructorArguments.verify(address_hash, bytecode, arguments_data) -> + !ConstructorArguments.verify(address_hash, blockchain_bytecode, arguments_data) -> {:error, :constructor_arguments} true -> diff --git a/apps/explorer/test/explorer/smart_contract/verifier_test.exs b/apps/explorer/test/explorer/smart_contract/verifier_test.exs index 7d5a14be0e..a536532739 100644 --- a/apps/explorer/test/explorer/smart_contract/verifier_test.exs +++ b/apps/explorer/test/explorer/smart_contract/verifier_test.exs @@ -56,6 +56,57 @@ defmodule Explorer.SmartContract.VerifierTest do assert abi != nil end + test "verifies smart contract with constructor arguments", %{ + contract_code_info: contract_code_info + } do + contract_address = insert(:contract_address, contract_code: contract_code_info.bytecode) + + constructor_arguments = "0102030405" + + params = %{ + "contract_source_code" => contract_code_info.source_code, + "compiler_version" => contract_code_info.version, + "name" => contract_code_info.name, + "optimization" => contract_code_info.optimized, + "constructor_arguments" => constructor_arguments + } + + :transaction + |> insert( + created_contract_address_hash: contract_address.hash, + input: Verifier.extract_bytecode(contract_code_info.bytecode) <> constructor_arguments + ) + |> with_block() + + assert {:ok, %{abi: abi}} = Verifier.evaluate_authenticity(contract_address.hash, params) + assert abi != nil + end + + test "returns error when constructor arguments do not match", %{ + contract_code_info: contract_code_info + } do + contract_address = insert(:contract_address, contract_code: contract_code_info.bytecode) + + constructor_arguments = "0102030405" + + params = %{ + "contract_source_code" => contract_code_info.source_code, + "compiler_version" => contract_code_info.version, + "name" => contract_code_info.name, + "optimization" => contract_code_info.optimized, + "constructor_arguments" => constructor_arguments + } + + :transaction + |> insert( + created_contract_address_hash: contract_address.hash, + input: Verifier.extract_bytecode(contract_code_info.bytecode) <> "010203" + ) + |> with_block() + + assert {:error, :constructor_arguments} = Verifier.evaluate_authenticity(contract_address.hash, params) + 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)