diff --git a/explorer/lib/explorer/contract_managers/aligned_proof_aggregation_service.ex b/explorer/lib/explorer/contract_managers/aligned_proof_aggregation_service.ex index 4040370a2c..a290201fdb 100644 --- a/explorer/lib/explorer/contract_managers/aligned_proof_aggregation_service.ex +++ b/explorer/lib/explorer/contract_managers/aligned_proof_aggregation_service.ex @@ -2,6 +2,8 @@ defmodule AlignedProofAggregationService do require Logger @aligned_config_file System.get_env("ALIGNED_PROOF_AGG_CONFIG_FILE") + @verifyRisc0_solidity_signature "0x015f8668" + @verifySp1_solidity_signature "0x39c94cbf" config_file_path = case @aligned_config_file do @@ -66,6 +68,23 @@ defmodule AlignedProofAggregationService do end end + # From a given aggregated proof event, it fetches the transaction + # and returns the aggregator (:sp1, :risc0) based on the function signature + def get_aggregator!(agg_proof) do + tx_hash = agg_proof.tx_hash + {:ok, tx} = Explorer.EthClient.get_transaction_by_hash(tx_hash) + input = Map.get(tx, "input") + # In solidity, the function signatures are the first 4 bytes of the input + # Note: first two characters are the 0x + function_signature = String.slice(input, 0..9) + + case function_signature do + @verifyRisc0_solidity_signature -> :risc0 + @verifySp1_solidity_signature -> :sp1 + _ -> nil + end + end + def get_block_timestamp(block_number) do case Ethers.Utils.get_block_timestamp(block_number) do {:ok, timestamp} -> DateTime.from_unix!(timestamp) diff --git a/explorer/lib/explorer/eth_client.ex b/explorer/lib/explorer/eth_client.ex index 61756e01ac..4c790374ca 100644 --- a/explorer/lib/explorer/eth_client.ex +++ b/explorer/lib/explorer/eth_client.ex @@ -6,6 +6,10 @@ defmodule Explorer.EthClient do eth_send("eth_getBlockByNumber", [block_number, false]) end + def get_transaction_by_hash(tx_hash) do + eth_send("eth_getTransactionByHash", [tx_hash]) + end + defp eth_send(method, params, id \\ 1) do headers = [{"Content-Type", "application/json"}] body = Jason.encode!(%{jsonrpc: "2.0", method: method, params: params, id: id}) @@ -15,9 +19,14 @@ defmodule Explorer.EthClient do case response do {:ok, %Finch.Response{status: 200, body: body}} -> case Jason.decode(body) do - {:ok, %{error: error} = _} -> {:error, error.message} - {:ok, body} -> {:ok, Map.get(body, "result")} - {:error, _} -> {:error, :invalid_json} + {:ok, %{"error" => %{"message" => message}}} -> + {:error, message} + + {:ok, body} -> + {:ok, Map.get(body, "result")} + + {:error, _} -> + {:error, :invalid_json} end {:ok, %Finch.Response{status: status}} -> diff --git a/explorer/lib/explorer/models/aggregated_proofs.ex b/explorer/lib/explorer/models/aggregated_proofs.ex index 639603843c..d43dc34efd 100644 --- a/explorer/lib/explorer/models/aggregated_proofs.ex +++ b/explorer/lib/explorer/models/aggregated_proofs.ex @@ -12,6 +12,7 @@ defmodule AggregatedProofs do field(:block_timestamp, :utc_datetime) field(:tx_hash, :string) field(:number_of_proofs, :integer) + field(:aggregator, Ecto.Enum, values: [:sp1, :risc0]) has_many(:proofs_agg_mode, AggregationModeProof, foreign_key: :agg_proof_id, @@ -33,7 +34,8 @@ defmodule AggregatedProofs do :block_number, :block_timestamp, :tx_hash, - :number_of_proofs + :number_of_proofs, + :aggregator ]) |> validate_required([ :merkle_root, diff --git a/explorer/lib/explorer/periodically.ex b/explorer/lib/explorer/periodically.ex index 077519a46c..377870e6fa 100644 --- a/explorer/lib/explorer/periodically.ex +++ b/explorer/lib/explorer/periodically.ex @@ -113,8 +113,11 @@ defmodule Explorer.Periodically do proofs |> Enum.zip(proof_hashes) |> Enum.map(fn {agg_proof, hashes} -> + aggregator = AlignedProofAggregationService.get_aggregator!(agg_proof) + agg_proof = agg_proof + |> Map.merge(%{aggregator: aggregator}) |> Map.merge(%{number_of_proofs: length(hashes)}) {:ok, %{id: id}} = AggregatedProofs.insert_or_update(agg_proof) diff --git a/explorer/lib/explorer_web/components/agg_proofs_table.ex b/explorer/lib/explorer_web/components/agg_proofs_table.ex index 727f51cb4f..6f39e53891 100644 --- a/explorer/lib/explorer_web/components/agg_proofs_table.ex +++ b/explorer/lib/explorer_web/components/agg_proofs_table.ex @@ -44,7 +44,34 @@ defmodule ExplorerWeb.AggProofsTable do <:col :let={proof} label="Number of proofs"> <%= proof.number_of_proofs |> Helpers.format_number() %> + + <:col :let={proof} label="Aggregator"> + <%= case proof.aggregator do %> + <% :sp1 -> %> + <.sp1_badge /> + <% :risc0 -> %> + <.risc0_badge /> + <% _ -> %> + Unknown + <% end %> + """ end + + defp sp1_badge(assigns) do + ~H""" +
SP1
+RISC0
+SP1
+ <% :risc0 -> %> +RISC0
+ <% end %> +