Merge pull request #5136 from blockscout/np-fix-verifying-without-bytecodeHash

Add ability to verify bytecode without bytecode hash
pull/5300/head
Victor Baranov 3 years ago committed by GitHub
commit ba8e41c018
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 2
      apps/explorer/config/test.exs
  3. 5
      apps/explorer/lib/explorer/smart_contract/solidity/verifier.ex
  4. 25
      apps/explorer/test/explorer/smart_contract/solidity/publisher_test.exs
  5. 170
      apps/explorer/test/explorer/smart_contract/solidity/verifier_test.exs

@ -4,6 +4,7 @@
- [#5268](https://github.com/blockscout/blockscout/pull/5268) - Contract names display improvement - [#5268](https://github.com/blockscout/blockscout/pull/5268) - Contract names display improvement
### Fixes ### Fixes
- [#5136](https://github.com/blockscout/blockscout/pull/5136) - Improve contract verification
- [#5285](https://github.com/blockscout/blockscout/pull/5285) - Fix verified smart-contract bytecode twins feature - [#5285](https://github.com/blockscout/blockscout/pull/5285) - Fix verified smart-contract bytecode twins feature
- [#5269](https://github.com/blockscout/blockscout/pull/5269) - Address Page: Fix implementation address align - [#5269](https://github.com/blockscout/blockscout/pull/5269) - Address Page: Fix implementation address align
- [#5264](https://github.com/blockscout/blockscout/pull/5264) - Fix bug with 500 response on `partial` sourcify status - [#5264](https://github.com/blockscout/blockscout/pull/5264) - Fix bug with 500 response on `partial` sourcify status

@ -9,7 +9,7 @@ config :explorer, Explorer.Repo,
hostname: "localhost", hostname: "localhost",
pool: Ecto.Adapters.SQL.Sandbox, pool: Ecto.Adapters.SQL.Sandbox,
# Default of `5_000` was too low for `BlockFetcher` test # Default of `5_000` was too low for `BlockFetcher` test
ownership_timeout: :timer.minutes(1), ownership_timeout: :timer.minutes(7),
timeout: :timer.seconds(60), timeout: :timer.seconds(60),
queue_target: 1000 queue_target: 1000

@ -203,7 +203,7 @@ defmodule Explorer.SmartContract.Solidity.Verifier do
init_without_0x init_without_0x
_ -> _ ->
bytecode ""
end end
%{ %{
@ -218,6 +218,9 @@ defmodule Explorer.SmartContract.Solidity.Verifier do
compiler_version_from_input != generated_compiler_version -> compiler_version_from_input != generated_compiler_version ->
{:error, :compiler_version} {:error, :compiler_version}
bytecode <> arguments_data == blockchain_created_tx_input ->
{:ok, %{abi: abi, constructor_arguments: arguments_data}}
generated_bytecode != blockchain_bytecode_without_whisper && generated_bytecode != blockchain_bytecode_without_whisper &&
!try_library_verification(generated_bytecode, blockchain_bytecode_without_whisper) -> !try_library_verification(generated_bytecode, blockchain_bytecode_without_whisper) ->
{:error, :generated_bytecode} {:error, :generated_bytecode}

@ -13,10 +13,13 @@ defmodule Explorer.SmartContract.Solidity.PublisherTest do
describe "publish/2" do describe "publish/2" do
test "with valid data creates a smart_contract" do test "with valid data creates a smart_contract" do
contract_code_info = Factory.contract_code_info() contract_code_info = Factory.contract_code_info_modern_compilator()
contract_address = insert(:contract_address, contract_code: contract_code_info.bytecode) contract_address = insert(:contract_address, contract_code: contract_code_info.bytecode)
insert(:transaction, created_contract_address_hash: contract_address.hash, input: contract_code_info.tx_input)
:transaction
|> insert(created_contract_address_hash: contract_address.hash, input: contract_code_info.tx_input)
|> with_block(status: :ok)
valid_attrs = %{ valid_attrs = %{
"contract_source_code" => contract_code_info.source_code, "contract_source_code" => contract_code_info.source_code,
@ -57,7 +60,7 @@ defmodule Explorer.SmartContract.Solidity.PublisherTest do
created_contract_address_hash: contract_address.hash, created_contract_address_hash: contract_address.hash,
input: input <> expected_constructor_arguments input: input <> expected_constructor_arguments
) )
|> with_block() |> with_block(status: :ok)
params = %{ params = %{
"contract_source_code" => contract, "contract_source_code" => contract,
@ -73,10 +76,13 @@ defmodule Explorer.SmartContract.Solidity.PublisherTest do
end end
test "corresponding contract_methods are created for the abi" do test "corresponding contract_methods are created for the abi" do
contract_code_info = Factory.contract_code_info() contract_code_info = Factory.contract_code_info_modern_compilator()
contract_address = insert(:contract_address, contract_code: contract_code_info.bytecode) contract_address = insert(:contract_address, contract_code: contract_code_info.bytecode)
insert(:transaction, created_contract_address_hash: contract_address.hash, input: contract_code_info.tx_input)
:transaction
|> insert(created_contract_address_hash: contract_address.hash, input: contract_code_info.tx_input)
|> with_block(status: :ok)
valid_attrs = %{ valid_attrs = %{
"contract_source_code" => contract_code_info.source_code, "contract_source_code" => contract_code_info.source_code,
@ -96,7 +102,7 @@ defmodule Explorer.SmartContract.Solidity.PublisherTest do
end end
test "creates a smart contract with constructor arguments" do test "creates a smart contract with constructor arguments" do
contract_code_info = Factory.contract_code_info() contract_code_info = Factory.contract_code_info_modern_compilator()
contract_address = insert(:contract_address, contract_code: contract_code_info.bytecode) contract_address = insert(:contract_address, contract_code: contract_code_info.bytecode)
@ -115,7 +121,7 @@ defmodule Explorer.SmartContract.Solidity.PublisherTest do
created_contract_address_hash: contract_address.hash, created_contract_address_hash: contract_address.hash,
input: contract_code_info.tx_input <> constructor_arguments input: contract_code_info.tx_input <> constructor_arguments
) )
|> with_block() |> with_block(status: :ok)
response = Publisher.publish(contract_address.hash, params) response = Publisher.publish(contract_address.hash, params)
assert {:ok, %SmartContract{} = smart_contract} = response assert {:ok, %SmartContract{} = smart_contract} = response
@ -152,7 +158,10 @@ defmodule Explorer.SmartContract.Solidity.PublisherTest do
tx_input = contract_data["tx_input"] tx_input = contract_data["tx_input"]
contract_address = insert(:contract_address, contract_code: "0x" <> expected_bytecode) contract_address = insert(:contract_address, contract_code: "0x" <> expected_bytecode)
insert(:transaction, created_contract_address_hash: contract_address.hash, input: "0x" <> tx_input)
:transaction
|> insert(created_contract_address_hash: contract_address.hash, input: "0x" <> tx_input)
|> with_block(status: :ok)
params = %{ params = %{
"contract_source_code" => contract, "contract_source_code" => contract,

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save