process new metadata format for whisper

Solidity >= 0.5.11 has new whisper metadata format
Metadata: Update the swarm hash to the current specification,
changes bzzr0 to bzzr1 and urls to use bzz-raw://

https://github.com/ethereum/solidity/blob/develop/Changelog.md#0511-2019-08-12
pull/2592/head
Ayrat Badykov 5 years ago
parent 0879b060ff
commit 642cfd01cd
No known key found for this signature in database
GPG Key ID: B44668E265E9396F
  1. 8
      apps/explorer/lib/explorer/smart_contract/verifier.ex
  2. 10
      apps/explorer/lib/explorer/smart_contract/verifier/constructor_arguments.ex
  3. 27
      apps/explorer/test/explorer/smart_contract/verifier_test.exs
  4. 7
      apps/explorer/test/support/fixture/smart_contract/solidity_5.11_new_whisper_metadata.json

@ -115,6 +115,14 @@ defmodule Explorer.SmartContract.Verifier do
|> Enum.reverse() |> Enum.reverse()
|> :binary.list_to_bin() |> :binary.list_to_bin()
# Solidity >= 0.5.11 https://github.com/ethereum/solidity/blob/develop/Changelog.md#0511-2019-08-12
# Metadata: Update the swarm hash to the current specification, changes bzzr0 to bzzr1 and urls to use bzz-raw://
"a265627a7a72315820" <>
<<_::binary-size(64)>> <> "64736f6c6343" <> <<_::binary-size(6)>> <> "0032" <> _constructor_arguments ->
extracted
|> Enum.reverse()
|> :binary.list_to_bin()
<<next::binary-size(2)>> <> rest -> <<next::binary-size(2)>> <> rest ->
do_extract_bytecode([next | extracted], rest) do_extract_bytecode([next | extracted], rest)
end end

@ -48,6 +48,16 @@ defmodule Explorer.SmartContract.Verifier.ConstructorArguments do
extract_constructor_arguments(constructor_arguments, passed_constructor_arguments) extract_constructor_arguments(constructor_arguments, passed_constructor_arguments)
end end
# Solidity >= 0.5.11 https://github.com/ethereum/solidity/blob/develop/Changelog.md#0511-2019-08-12
# Metadata: Update the swarm hash to the current specification, changes bzzr0 to bzzr1 and urls to use bzz-raw://
"a265627a7a72315820" <>
<<_::binary-size(64)>> <> "64736f6c6343" <> <<_::binary-size(6)>> <> "0032" <> constructor_arguments ->
if passed_constructor_arguments == constructor_arguments do
true
else
extract_constructor_arguments(constructor_arguments, passed_constructor_arguments)
end
<<>> -> <<>> ->
passed_constructor_arguments == "" passed_constructor_arguments == ""

@ -56,6 +56,33 @@ defmodule Explorer.SmartContract.VerifierTest do
assert abi != nil assert abi != nil
end end
test "verifies smart contract with new `whisper` metadata (bzz0 => bzz1) in solidity 0.5.11" do
contract_data =
"#{File.cwd!()}/test/support/fixture/smart_contract/solidity_5.11_new_whisper_metadata.json"
|> File.read!()
|> Jason.decode!()
compiler_version = contract_data["compiler_version"]
name = contract_data["name"]
optimize = false
contract = contract_data["contract"]
expected_bytecode = contract_data["bytecode"]
evm_version = contract_data["evm_version"]
contract_address = insert(:contract_address, contract_code: "0x" <> expected_bytecode)
params = %{
"contract_source_code" => contract,
"compiler_version" => compiler_version,
"evm_version" => evm_version,
"name" => name,
"optimization" => optimize
}
assert {:ok, %{abi: abi}} = Verifier.evaluate_authenticity(contract_address.hash, params)
assert abi != nil
end
test "verifies smart contract with constructor arguments", %{ test "verifies smart contract with constructor arguments", %{
contract_code_info: contract_code_info contract_code_info: contract_code_info
} do } do

Loading…
Cancel
Save