Merge pull request #1790 from poanetwork/ab-fix-contructor-verification-with-contructor-arguments

fix constructor arguments verification
pull/1802/head
Victor Baranov 6 years ago committed by GitHub
commit e93ecb510c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 2
      apps/explorer/lib/explorer/smart_contract/verifier.ex
  3. 10
      apps/explorer/lib/explorer/smart_contract/verifier/constructor_arguments.ex
  4. 21
      apps/explorer/test/explorer/smart_contract/verifier/constructor_arguments_test.exs

@ -19,6 +19,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
- [#1793](https://github.com/poanetwork/blockscout/pull/1793) - fix top nav autocomplete
- [#1795](https://github.com/poanetwork/blockscout/pull/1795) - fix line numbers for decompiled contracts

@ -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 ->

@ -5,13 +5,19 @@ 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)
data_with_swarm =
creation_input_data
|> String.split("0029")
|> List.first()
|> Kernel.<>("0029")
expected_arguments_data =
creation_input_data
|> String.split(bytecode)
|> String.split(data_with_swarm)
|> List.last()
|> String.replace("0x", "")

@ -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

Loading…
Cancel
Save