|
|
|
@ -7,9 +7,11 @@ defmodule Explorer.SmartContract.Vyper.Verifier do |
|
|
|
|
against the existing Creation Address Bytecode, if it matches the contract is |
|
|
|
|
then Verified. |
|
|
|
|
""" |
|
|
|
|
require Logger |
|
|
|
|
|
|
|
|
|
alias Explorer.Chain |
|
|
|
|
alias Explorer.SmartContract.Vyper.CodeCompiler |
|
|
|
|
alias Explorer.SmartContract.RustVerifierInterface |
|
|
|
|
|
|
|
|
|
def evaluate_authenticity(_, %{"name" => ""}), do: {:error, :name} |
|
|
|
|
|
|
|
|
@ -17,6 +19,39 @@ defmodule Explorer.SmartContract.Vyper.Verifier do |
|
|
|
|
do: {:error, :contract_source_code} |
|
|
|
|
|
|
|
|
|
def evaluate_authenticity(address_hash, params) do |
|
|
|
|
try do |
|
|
|
|
evaluate_authenticity_inner(RustVerifierInterface.enabled?(), address_hash, params) |
|
|
|
|
rescue |
|
|
|
|
exception -> |
|
|
|
|
Logger.error(fn -> |
|
|
|
|
[ |
|
|
|
|
"Error while verifying smart-contract address: #{address_hash}, params: #{inspect(params, limit: :infinity, printable_limit: :infinity)}: ", |
|
|
|
|
Exception.format(:error, exception) |
|
|
|
|
] |
|
|
|
|
end) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
defp evaluate_authenticity_inner(true, address_hash, params) do |
|
|
|
|
deployed_bytecode = Chain.smart_contract_bytecode(address_hash) |
|
|
|
|
|
|
|
|
|
creation_tx_input = |
|
|
|
|
case Chain.smart_contract_creation_tx_bytecode(address_hash) do |
|
|
|
|
%{init: init, created_contract_code: _created_contract_code} -> |
|
|
|
|
init |
|
|
|
|
|
|
|
|
|
_ -> |
|
|
|
|
"" |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
params |
|
|
|
|
|> Map.put("creation_bytecode", creation_tx_input) |
|
|
|
|
|> Map.put("deployed_bytecode", deployed_bytecode) |
|
|
|
|
|> Map.put("sources", %{"#{params["name"]}.vy" => params["contract_source_code"]}) |
|
|
|
|
|> RustVerifierInterface.vyper_verify_multipart() |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
defp evaluate_authenticity_inner(false, address_hash, params) do |
|
|
|
|
verify(address_hash, params) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|