Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
15 changes: 12 additions & 3 deletions explorer/lib/explorer/eth_client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand All @@ -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}} ->
Expand Down
4 changes: 3 additions & 1 deletion explorer/lib/explorer/models/aggregated_proofs.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -33,7 +34,8 @@ defmodule AggregatedProofs do
:block_number,
:block_timestamp,
:tx_hash,
:number_of_proofs
:number_of_proofs,
:aggregator
])
|> validate_required([
:merkle_root,
Expand Down
3 changes: 3 additions & 0 deletions explorer/lib/explorer/periodically.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
27 changes: 27 additions & 0 deletions explorer/lib/explorer_web/components/agg_proofs_table.ex
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,34 @@ defmodule ExplorerWeb.AggProofsTable do
<:col :let={proof} label="Number of proofs">
<%= proof.number_of_proofs |> Helpers.format_number() %>
</:col>

<:col :let={proof} label="Aggregator">
<%= case proof.aggregator do %>
<% :sp1 -> %>
<.sp1_badge />
<% :risc0 -> %>
<.risc0_badge />
<% _ -> %>
<span>Unknown</span>
<% end %>
</:col>
</.table>
"""
end

defp sp1_badge(assigns) do
~H"""
<div class="rounded-full p-1 px-5 border w-fit" style="border-color: #FE11C5">
<p style="color: #FE11C5">SP1</p>
</div>
"""
end

defp risc0_badge(assigns) do
~H"""
<div class="rounded-full p-1 px-5 w-fit" style="background-color: #FEFF9D">
<p class="text-black">RISC0</p>
</div>
"""
end
end
14 changes: 13 additions & 1 deletion explorer/lib/explorer_web/live/pages/agg_proof/index.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@
</p>
</div>

<div>
<h3>
Aggregator:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd change "Aggregator" for "Proving System"

</h3>
<%= case @agg_proof.aggregator do %>
<% :sp1 -> %>
<p>SP1</p>
<% :risc0 -> %>
<p>RISC0</p>
<% end %>
</div>

<div>
<h3>
Number of Proofs included:
Expand Down Expand Up @@ -110,7 +122,7 @@
<div class="flex flex-col space-y-6 justify-center grow relative text-center md:pt-14">
<h1 class="text-5xl font-semibold">Oops!</h1>
<h2 class="text-xl font-medium">
The batch you are looking for <br /> doesn't exist.
The aggregated proof you are looking for <br /> doesn't exist.
</h2>
<img
class="z-0 w-64 rounded-xl mx-auto"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
defmodule Explorer.Repo.Migrations.AddAggregatorToAggProofs do
use Ecto.Migration

def change do
alter table(:aggregated_proofs) do
add(:aggregator, :string, default: nil)
end
end
end