diff --git a/apps/explorer/lib/explorer/smart_contract/verifier.ex b/apps/explorer/lib/explorer/smart_contract/verifier.ex index b72aa470f8..d7df613f33 100644 --- a/apps/explorer/lib/explorer/smart_contract/verifier.ex +++ b/apps/explorer/lib/explorer/smart_contract/verifier.ex @@ -38,10 +38,11 @@ defmodule Explorer.SmartContract.Verifier do "0x" <> blockchain_bytecode = address_hash |> Chain.smart_contract_bytecode() - |> extract_bytecode + + blockchain_bytecode_without_whisper = extract_bytecode(blockchain_bytecode) cond do - generated_bytecode != blockchain_bytecode -> + generated_bytecode != blockchain_bytecode_without_whisper -> {:error, :generated_bytecode} !ConstructorArguments.verify(address_hash, blockchain_bytecode, arguments_data) -> diff --git a/apps/explorer/test/explorer/smart_contract/publisher_test.exs b/apps/explorer/test/explorer/smart_contract/publisher_test.exs index b459bed32a..2807dd3189 100644 --- a/apps/explorer/test/explorer/smart_contract/publisher_test.exs +++ b/apps/explorer/test/explorer/smart_contract/publisher_test.exs @@ -7,7 +7,6 @@ defmodule Explorer.SmartContract.PublisherTest do alias Explorer.Chain.SmartContract alias Explorer.SmartContract.Publisher - alias Explorer.SmartContract.Verifier alias Explorer.Factory describe "publish/2" do @@ -53,7 +52,7 @@ defmodule Explorer.SmartContract.PublisherTest do :transaction |> insert( created_contract_address_hash: contract_address.hash, - input: Verifier.extract_bytecode(contract_code_info.bytecode) <> constructor_arguments + input: contract_code_info.bytecode <> constructor_arguments ) |> with_block() 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 5bd3b24103..b030c900bb 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 @@ -163,9 +163,12 @@ defmodule Explorer.SmartContract.Solidity.CodeCompilerTest do end defp remove_init_data_and_whisper_data(code) do - code - |> String.split("0029") - |> List.first() - |> String.split_at(-64) + {res, _} = + code + |> String.split("0029") + |> List.first() + |> String.split_at(-64) + + res end end diff --git a/apps/explorer/test/explorer/smart_contract/verifier/constructor_arguments_test.exs b/apps/explorer/test/explorer/smart_contract/verifier/constructor_arguments_test.exs index 989f07dbce..a9de1e2e5e 100644 --- a/apps/explorer/test/explorer/smart_contract/verifier/constructor_arguments_test.exs +++ b/apps/explorer/test/explorer/smart_contract/verifier/constructor_arguments_test.exs @@ -7,7 +7,7 @@ defmodule Explorer.SmartContract.Verifier.ConstructorArgumentsTest do alias Explorer.SmartContract.Verifier.ConstructorArguments describe "verify/3" do - test "verifies construct arguments" do + test "verifies constructor arguments" do bytecode = "0x0102030" constructor_arguments = "0x405" address = insert(:address) @@ -23,4 +23,22 @@ defmodule Explorer.SmartContract.Verifier.ConstructorArgumentsTest do assert ConstructorArguments.verify(address.hash, bytecode, constructor_arguments) end end + + test "veriies constructor constructor arguments with whisper data" do + bytecode = "0x0102035d943c575be8a2aee2bb7737a765fdd2c6e49b74cd2c92ab0fa8e4282d1a75ae0029" + constructor_arguments = "0x0405" + address = insert(:address) + + input = %Data{ + bytes: + <<1, 2, 3, 93, 148, 60, 87, 91, 232, 162, 174, 226, 187, 119, 55, 167, 101, 253, 210, 198, 228, 155, 116, 205, + 44, 146, 171, 15, 168, 228, 40, 45, 26, 117, 174, 0, 41, 4, 5>> + } + + :transaction + |> insert(created_contract_address_hash: address.hash, input: input) + |> with_block() + + assert ConstructorArguments.verify(address.hash, bytecode, constructor_arguments) + end end diff --git a/apps/explorer/test/explorer/smart_contract/verifier_test.exs b/apps/explorer/test/explorer/smart_contract/verifier_test.exs index a536532739..584bb568ef 100644 --- a/apps/explorer/test/explorer/smart_contract/verifier_test.exs +++ b/apps/explorer/test/explorer/smart_contract/verifier_test.exs @@ -74,7 +74,7 @@ defmodule Explorer.SmartContract.VerifierTest do :transaction |> insert( created_contract_address_hash: contract_address.hash, - input: Verifier.extract_bytecode(contract_code_info.bytecode) <> constructor_arguments + input: contract_code_info.bytecode <> constructor_arguments ) |> with_block()