diff --git a/queries/risczero_verification_base.sql b/queries/risczero_verification_base.sql new file mode 100644 index 0000000..aa46e08 --- /dev/null +++ b/queries/risczero_verification_base.sql @@ -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 \ No newline at end of file