Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Project RiscZero #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
40 changes: 40 additions & 0 deletions queries/risczero_verification_base.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
-- part of a query repo
-- query name: RiscZero verification base
-- query link: https://dune.com/queries/tbd

with eth_gas_price as (
SELECT DATE_TRUNC('day', tx.block_time) AS day
, APPROX_PERCENTILE(tx.gas_price / 1e18, 0.5) AS median_legacy_gas_price
, APPROX_PERCENTILE( (b.base_fee_per_gas + tx.priority_fee_per_gas) / 1e18, 0.5) AS median_dynamic_gas_price
from ethereum.transactions tx
INNER JOIN ethereum.blocks b ON tx.block_number = b.number
group by 1
)
, eth_usd_price as (
select date_trunc('day', minute) as day
, avg(price) as avg_eth_price
from prices.usd
where blockchain is null and symbol = 'ETH'
group by 1
)

select tr.block_date
, count(distinct tx_hash) as verifying_calls
, sum(case when tx.type = 'DynamicFee' then cast(tr.gas_used as double) * median_dynamic_gas_price -- dynamic
else cast(tr.gas_used as double) * median_legacy_gas_price -- legacy
end) as verifying_cost_ETH
, sum(case when tx.type = 'DynamicFee' then cast(tr.gas_used as double) * median_dynamic_gas_price * avg_eth_price -- dynamic
else cast(tr.gas_used as double) * median_legacy_gas_price * avg_eth_price -- legacy
end) as verifying_cost_usd
from
ethereum.traces tr
left join ethereum.transactions tx on tr.block_number = tx.block_number and tr.tx_hash = tx.hash
left join eth_usd_price ep on tr.block_date = ep.day
left join eth_gas_price gp on tr.block_date = gp.day
where
tr.to = 0x8EaB2D97Dfce405A1692a21b3ff3A172d593D319 -- RiscZeroVerifierRouter
and tr.call_type = 'staticcall'
and bytearray_substring (tr.input, 1, 4) = 0xab750e75 -- verify
and tr.block_number > 20079231 -- RiscZeroVerifierRouter deployed at block 20079232
group by
1