consider whisper data when verifying constructor arguments

pull/1414/head
Ayrat Badykov 6 years ago
parent 2da0eb48ab
commit 86b0518cfe
No known key found for this signature in database
GPG Key ID: B44668E265E9396F
  1. 5
      apps/explorer/lib/explorer/smart_contract/verifier.ex
  2. 3
      apps/explorer/test/explorer/smart_contract/publisher_test.exs
  3. 11
      apps/explorer/test/explorer/smart_contract/solidity/code_compiler_test.exs
  4. 20
      apps/explorer/test/explorer/smart_contract/verifier/constructor_arguments_test.exs
  5. 2
      apps/explorer/test/explorer/smart_contract/verifier_test.exs

@ -38,10 +38,11 @@ defmodule Explorer.SmartContract.Verifier do
"0x" <> blockchain_bytecode = "0x" <> blockchain_bytecode =
address_hash address_hash
|> Chain.smart_contract_bytecode() |> Chain.smart_contract_bytecode()
|> extract_bytecode
blockchain_bytecode_without_whisper = extract_bytecode(blockchain_bytecode)
cond do cond do
generated_bytecode != blockchain_bytecode -> generated_bytecode != blockchain_bytecode_without_whisper ->
{:error, :generated_bytecode} {:error, :generated_bytecode}
!ConstructorArguments.verify(address_hash, blockchain_bytecode, arguments_data) -> !ConstructorArguments.verify(address_hash, blockchain_bytecode, arguments_data) ->

@ -7,7 +7,6 @@ defmodule Explorer.SmartContract.PublisherTest do
alias Explorer.Chain.SmartContract alias Explorer.Chain.SmartContract
alias Explorer.SmartContract.Publisher alias Explorer.SmartContract.Publisher
alias Explorer.SmartContract.Verifier
alias Explorer.Factory alias Explorer.Factory
describe "publish/2" do describe "publish/2" do
@ -53,7 +52,7 @@ defmodule Explorer.SmartContract.PublisherTest do
:transaction :transaction
|> insert( |> insert(
created_contract_address_hash: contract_address.hash, 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() |> with_block()

@ -163,9 +163,12 @@ defmodule Explorer.SmartContract.Solidity.CodeCompilerTest do
end end
defp remove_init_data_and_whisper_data(code) do defp remove_init_data_and_whisper_data(code) do
code {res, _} =
|> String.split("0029") code
|> List.first() |> String.split("0029")
|> String.split_at(-64) |> List.first()
|> String.split_at(-64)
res
end end
end end

@ -7,7 +7,7 @@ defmodule Explorer.SmartContract.Verifier.ConstructorArgumentsTest do
alias Explorer.SmartContract.Verifier.ConstructorArguments alias Explorer.SmartContract.Verifier.ConstructorArguments
describe "verify/3" do describe "verify/3" do
test "verifies construct arguments" do test "verifies constructor arguments" do
bytecode = "0x0102030" bytecode = "0x0102030"
constructor_arguments = "0x405" constructor_arguments = "0x405"
address = insert(:address) address = insert(:address)
@ -23,4 +23,22 @@ defmodule Explorer.SmartContract.Verifier.ConstructorArgumentsTest do
assert ConstructorArguments.verify(address.hash, bytecode, constructor_arguments) assert ConstructorArguments.verify(address.hash, bytecode, constructor_arguments)
end end
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 end

@ -74,7 +74,7 @@ defmodule Explorer.SmartContract.VerifierTest do
:transaction :transaction
|> insert( |> insert(
created_contract_address_hash: contract_address.hash, 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() |> with_block()

Loading…
Cancel
Save