Merge branch 'master' into ab-tab-for-decompiled-contracts

pull/1654/head
Ayrat Badykov 6 years ago committed by GitHub
commit 0047b82db5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 33
      apps/explorer/lib/explorer/smart_contract/verifier.ex
  3. 35
      apps/explorer/test/explorer/smart_contract/verifier_test.exs

@ -3,6 +3,7 @@
### Features ### Features
- [1654](https://github.com/poanetwork/blockscout/pull/1654) - add decompiled code tab - [1654](https://github.com/poanetwork/blockscout/pull/1654) - add decompiled code tab
- [1661](https://github.com/poanetwork/blockscout/pull/1661) - try to compile smart contract with the latest evm version
### Fixes ### Fixes

@ -28,7 +28,25 @@ defmodule Explorer.SmartContract.Verifier do
solc_output = solc_output =
CodeCompiler.run(name, compiler_version, contract_source_code, optimization, evm_version, external_libraries) CodeCompiler.run(name, compiler_version, contract_source_code, optimization, evm_version, external_libraries)
compare_bytecodes(solc_output, address_hash, constructor_arguments) case compare_bytecodes(solc_output, address_hash, constructor_arguments) do
{:error, :generated_bytecode} ->
next_evm_version = next_evm_version(evm_version)
second_solc_output =
CodeCompiler.run(
name,
compiler_version,
contract_source_code,
optimization,
next_evm_version,
external_libraries
)
compare_bytecodes(second_solc_output, address_hash, constructor_arguments)
result ->
result
end
end end
defp compare_bytecodes({:error, :name}, _, _), do: {:error, :name} defp compare_bytecodes({:error, :name}, _, _), do: {:error, :name}
@ -71,4 +89,17 @@ defmodule Explorer.SmartContract.Verifier do
bytecode bytecode
end end
def next_evm_version(current_evm_version) do
[prev_version, last_version] =
CodeCompiler.allowed_evm_versions()
|> Enum.reverse()
|> Enum.take(2)
if current_evm_version != last_version do
last_version
else
prev_version
end
end
end end

@ -82,6 +82,41 @@ defmodule Explorer.SmartContract.VerifierTest do
assert abi != nil assert abi != nil
end end
test "tries to compile with the latest evm version if wrong evm version was provided" do
bytecode =
"0x60606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063256fec88146100545780633fa4f245146100a9578063812600df146100d2575b600080fd5b341561005f57600080fd5b6100676100f5565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34156100b457600080fd5b6100bc61011b565b6040518082815260200191505060405180910390f35b34156100dd57600080fd5b6100f36004808035906020019091905050610121565b005b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60005481565b806000540160008190555033600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505b505600a165627a7a72305820b81379d1ae9d8e0fde05ee02b8bd170f43f8bd3d54da8b7ec203434a23a298980029"
contract_address = insert(:contract_address, contract_code: bytecode)
code = """
pragma solidity ^0.4.15;
contract Incrementer {
event Incremented(address indexed sender, uint256 newValue);
uint256 public value;
address public lastSender;
function Incrementer(uint256 initialValue) {
value = initialValue;
lastSender = msg.sender;
}
function inc(uint256 delta) {
value = value + delta;
lastSender = msg.sender;
}
}
"""
params = %{
"contract_source_code" => code,
"compiler_version" => "v0.4.15+commit.bbb8e64f",
"evm_version" => "homestead",
"name" => "Incrementer",
"optimization" => false
}
assert {:ok, %{abi: abi}} = Verifier.evaluate_authenticity(contract_address.hash, params)
assert abi != nil
end
test "returns error when constructor arguments do not match", %{ test "returns error when constructor arguments do not match", %{
contract_code_info: contract_code_info contract_code_info: contract_code_info
} do } do

Loading…
Cancel
Save