Skip to content

Commit c4b5f75

Browse files
feat: explorer show aggregtor (risc0, sp1) on aggregation mode views (#1904)
1 parent d2c297b commit c4b5f75

File tree

7 files changed

+86
-5
lines changed

7 files changed

+86
-5
lines changed

explorer/lib/explorer/contract_managers/aligned_proof_aggregation_service.ex

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ defmodule AlignedProofAggregationService do
22
require Logger
33

44
@aligned_config_file System.get_env("ALIGNED_PROOF_AGG_CONFIG_FILE")
5+
@verifyRisc0_solidity_signature "0x015f8668"
6+
@verifySp1_solidity_signature "0x39c94cbf"
57

68
config_file_path =
79
case @aligned_config_file do
@@ -66,6 +68,23 @@ defmodule AlignedProofAggregationService do
6668
end
6769
end
6870

71+
# From a given aggregated proof event, it fetches the transaction
72+
# and returns the aggregator (:sp1, :risc0) based on the function signature
73+
def get_aggregator!(agg_proof) do
74+
tx_hash = agg_proof.tx_hash
75+
{:ok, tx} = Explorer.EthClient.get_transaction_by_hash(tx_hash)
76+
input = Map.get(tx, "input")
77+
# In solidity, the function signatures are the first 4 bytes of the input
78+
# Note: first two characters are the 0x
79+
function_signature = String.slice(input, 0..9)
80+
81+
case function_signature do
82+
@verifyRisc0_solidity_signature -> :risc0
83+
@verifySp1_solidity_signature -> :sp1
84+
_ -> nil
85+
end
86+
end
87+
6988
def get_block_timestamp(block_number) do
7089
case Ethers.Utils.get_block_timestamp(block_number) do
7190
{:ok, timestamp} -> DateTime.from_unix!(timestamp)

explorer/lib/explorer/eth_client.ex

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ defmodule Explorer.EthClient do
66
eth_send("eth_getBlockByNumber", [block_number, false])
77
end
88

9+
def get_transaction_by_hash(tx_hash) do
10+
eth_send("eth_getTransactionByHash", [tx_hash])
11+
end
12+
913
defp eth_send(method, params, id \\ 1) do
1014
headers = [{"Content-Type", "application/json"}]
1115
body = Jason.encode!(%{jsonrpc: "2.0", method: method, params: params, id: id})
@@ -15,9 +19,14 @@ defmodule Explorer.EthClient do
1519
case response do
1620
{:ok, %Finch.Response{status: 200, body: body}} ->
1721
case Jason.decode(body) do
18-
{:ok, %{error: error} = _} -> {:error, error.message}
19-
{:ok, body} -> {:ok, Map.get(body, "result")}
20-
{:error, _} -> {:error, :invalid_json}
22+
{:ok, %{"error" => %{"message" => message}}} ->
23+
{:error, message}
24+
25+
{:ok, body} ->
26+
{:ok, Map.get(body, "result")}
27+
28+
{:error, _} ->
29+
{:error, :invalid_json}
2130
end
2231

2332
{:ok, %Finch.Response{status: status}} ->

explorer/lib/explorer/models/aggregated_proofs.ex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ defmodule AggregatedProofs do
1212
field(:block_timestamp, :utc_datetime)
1313
field(:tx_hash, :string)
1414
field(:number_of_proofs, :integer)
15+
field(:aggregator, Ecto.Enum, values: [:sp1, :risc0])
1516

1617
has_many(:proofs_agg_mode, AggregationModeProof,
1718
foreign_key: :agg_proof_id,
@@ -33,7 +34,8 @@ defmodule AggregatedProofs do
3334
:block_number,
3435
:block_timestamp,
3536
:tx_hash,
36-
:number_of_proofs
37+
:number_of_proofs,
38+
:aggregator
3739
])
3840
|> validate_required([
3941
:merkle_root,

explorer/lib/explorer/periodically.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,11 @@ defmodule Explorer.Periodically do
113113
proofs
114114
|> Enum.zip(proof_hashes)
115115
|> Enum.map(fn {agg_proof, hashes} ->
116+
aggregator = AlignedProofAggregationService.get_aggregator!(agg_proof)
117+
116118
agg_proof =
117119
agg_proof
120+
|> Map.merge(%{aggregator: aggregator})
118121
|> Map.merge(%{number_of_proofs: length(hashes)})
119122

120123
{:ok, %{id: id}} = AggregatedProofs.insert_or_update(agg_proof)

explorer/lib/explorer_web/components/agg_proofs_table.ex

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,34 @@ defmodule ExplorerWeb.AggProofsTable do
4444
<:col :let={proof} label="Number of proofs">
4545
<%= proof.number_of_proofs |> Helpers.format_number() %>
4646
</:col>
47+
48+
<:col :let={proof} label="Aggregator">
49+
<%= case proof.aggregator do %>
50+
<% :sp1 -> %>
51+
<.sp1_badge />
52+
<% :risc0 -> %>
53+
<.risc0_badge />
54+
<% _ -> %>
55+
<span>Unknown</span>
56+
<% end %>
57+
</:col>
4758
</.table>
4859
"""
4960
end
61+
62+
defp sp1_badge(assigns) do
63+
~H"""
64+
<div class="rounded-full p-1 px-5 border w-fit" style="border-color: #FE11C5">
65+
<p style="color: #FE11C5">SP1</p>
66+
</div>
67+
"""
68+
end
69+
70+
defp risc0_badge(assigns) do
71+
~H"""
72+
<div class="rounded-full p-1 px-5 w-fit" style="background-color: #FEFF9D">
73+
<p class="text-black">RISC0</p>
74+
</div>
75+
"""
76+
end
5077
end

explorer/lib/explorer_web/live/pages/agg_proof/index.html.heex

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@
2222
</p>
2323
</div>
2424

25+
<div>
26+
<h3>
27+
Aggregator:
28+
</h3>
29+
<%= case @agg_proof.aggregator do %>
30+
<% :sp1 -> %>
31+
<p>SP1</p>
32+
<% :risc0 -> %>
33+
<p>RISC0</p>
34+
<% end %>
35+
</div>
36+
2537
<div>
2638
<h3>
2739
Number of Proofs included:
@@ -110,7 +122,7 @@
110122
<div class="flex flex-col space-y-6 justify-center grow relative text-center md:pt-14">
111123
<h1 class="text-5xl font-semibold">Oops!</h1>
112124
<h2 class="text-xl font-medium">
113-
The batch you are looking for <br /> doesn't exist.
125+
The aggregated proof you are looking for <br /> doesn't exist.
114126
</h2>
115127
<img
116128
class="z-0 w-64 rounded-xl mx-auto"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
defmodule Explorer.Repo.Migrations.AddAggregatorToAggProofs do
2+
use Ecto.Migration
3+
4+
def change do
5+
alter table(:aggregated_proofs) do
6+
add(:aggregator, :string, default: nil)
7+
end
8+
end
9+
end

0 commit comments

Comments
 (0)