From f764f2ea6a0c671298da3713d34f1d72b2aa2ca9 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Fri, 19 Apr 2019 13:01:40 +0300 Subject: [PATCH 1/3] fix contructor arguments verification --- .../lib/explorer/smart_contract/verifier.ex | 2 +- .../verifier/constructor_arguments.ex | 4 ++-- .../verifier/constructor_arguments_test.exs | 21 +------------------ 3 files changed, 4 insertions(+), 23 deletions(-) diff --git a/apps/explorer/lib/explorer/smart_contract/verifier.ex b/apps/explorer/lib/explorer/smart_contract/verifier.ex index 576b1fcef1..0fc9f6b21b 100644 --- a/apps/explorer/lib/explorer/smart_contract/verifier.ex +++ b/apps/explorer/lib/explorer/smart_contract/verifier.ex @@ -74,7 +74,7 @@ defmodule Explorer.SmartContract.Verifier do generated_bytecode != blockchain_bytecode_without_whisper -> {:error, :generated_bytecode} - !ConstructorArguments.verify(address_hash, blockchain_bytecode, arguments_data) -> + !ConstructorArguments.verify(address_hash, arguments_data) -> {:error, :constructor_arguments} true -> diff --git a/apps/explorer/lib/explorer/smart_contract/verifier/constructor_arguments.ex b/apps/explorer/lib/explorer/smart_contract/verifier/constructor_arguments.ex index d8b982cc40..3a7a3a1f6c 100644 --- a/apps/explorer/lib/explorer/smart_contract/verifier/constructor_arguments.ex +++ b/apps/explorer/lib/explorer/smart_contract/verifier/constructor_arguments.ex @@ -5,13 +5,13 @@ defmodule Explorer.SmartContract.Verifier.ConstructorArguments do alias Explorer.Chain - def verify(address_hash, bytecode, arguments_data) do + def verify(address_hash, arguments_data) do arguments_data = String.replace(arguments_data, "0x", "") creation_input_data = Chain.contract_creation_input_data(address_hash) expected_arguments_data = creation_input_data - |> String.split(bytecode) + |> String.split("0029") |> List.last() |> String.replace("0x", "") 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 a9de1e2e5e..9fe219719d 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 @@ -6,26 +6,7 @@ defmodule Explorer.SmartContract.Verifier.ConstructorArgumentsTest do alias Explorer.Chain.Data alias Explorer.SmartContract.Verifier.ConstructorArguments - describe "verify/3" do - test "verifies constructor arguments" do - bytecode = "0x0102030" - constructor_arguments = "0x405" - address = insert(:address) - - input = %Data{ - bytes: <<1, 2, 3, 4, 5>> - } - - :transaction - |> insert(created_contract_address_hash: address.hash, input: input) - |> with_block() - - 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) @@ -39,6 +20,6 @@ defmodule Explorer.SmartContract.Verifier.ConstructorArgumentsTest do |> insert(created_contract_address_hash: address.hash, input: input) |> with_block() - assert ConstructorArguments.verify(address.hash, bytecode, constructor_arguments) + assert ConstructorArguments.verify(address.hash, constructor_arguments) end end From fc97527ca162d62d30f0813223f75b18022efacc Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Fri, 19 Apr 2019 13:10:58 +0300 Subject: [PATCH 2/3] add CHANGELOG.md entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 99dc22475f..5f33aa1331 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ - [#1769](https://github.com/poanetwork/blockscout/pull/1769) - add timestamp to block overview - [#1768](https://github.com/poanetwork/blockscout/pull/1768) - fix first block parameter - [#1778](https://github.com/poanetwork/blockscout/pull/1778) - Make websocket optional for realtime fetcher + - [#1790](https://github.com/poanetwork/blockscout/pull/1790) - fix constructor arguments verification ### Chore From 720a556f587541c408732fd7572174b000317267 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Mon, 22 Apr 2019 11:21:39 +0300 Subject: [PATCH 3/3] fix detecting swarm code --- .../smart_contract/verifier/constructor_arguments.ex | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/explorer/lib/explorer/smart_contract/verifier/constructor_arguments.ex b/apps/explorer/lib/explorer/smart_contract/verifier/constructor_arguments.ex index 3a7a3a1f6c..b60bd01927 100644 --- a/apps/explorer/lib/explorer/smart_contract/verifier/constructor_arguments.ex +++ b/apps/explorer/lib/explorer/smart_contract/verifier/constructor_arguments.ex @@ -9,9 +9,15 @@ defmodule Explorer.SmartContract.Verifier.ConstructorArguments do arguments_data = String.replace(arguments_data, "0x", "") creation_input_data = Chain.contract_creation_input_data(address_hash) - expected_arguments_data = + data_with_swarm = creation_input_data |> String.split("0029") + |> List.first() + |> Kernel.<>("0029") + + expected_arguments_data = + creation_input_data + |> String.split(data_with_swarm) |> List.last() |> String.replace("0x", "")