From 6d89303f7694a2e241c71ad069f6ea734f9ac015 Mon Sep 17 00:00:00 2001 From: Kevin Ayling Date: Wed, 18 Sep 2024 13:44:30 -0700 Subject: [PATCH 1/2] Add new query for Succinct --- queries/succinct_verification_base.sql | 35 ++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 queries/succinct_verification_base.sql diff --git a/queries/succinct_verification_base.sql b/queries/succinct_verification_base.sql new file mode 100644 index 0000000..f42c28f --- /dev/null +++ b/queries/succinct_verification_base.sql @@ -0,0 +1,35 @@ +-- part of a query repo +-- query name: Succinct 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 + block_date, + count(distinct tx_hash) as verifying_calls, + sum(cast(gas_used as double) / 1e9 * median_gas_price) as verifying_cost_ETH, + sum( + cast(gas_used as double) / 1e9 * median_gas_price * avg_eth_price + ) as verifying_cost_usd +from + ethereum.traces + left join eth_usd_price ep on block_date = ep.day + left join eth_gas_price gp on block_date = gp.day +where + to = 0x3B6041173B80E77f038f3F2C0f9744f04837185e -- SP1VerifierGateway + and bytearray_substring (input, 1, 4) = 0x41493c60 -- verifyProof +group by 1 \ No newline at end of file From 94a30acf548856a0fc87edce7aa6facf3df29868 Mon Sep 17 00:00:00 2001 From: Kevin Ayling Date: Wed, 18 Sep 2024 14:08:22 -0700 Subject: [PATCH 2/2] update succinct query to support dynamic fee txns --- queries/succinct_verification_base.sql | 28 ++++++++++++++------------ 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/queries/succinct_verification_base.sql b/queries/succinct_verification_base.sql index f42c28f..a2512cf 100644 --- a/queries/succinct_verification_base.sql +++ b/queries/succinct_verification_base.sql @@ -18,18 +18,20 @@ with eth_gas_price as ( group by 1 ) -select - block_date, - count(distinct tx_hash) as verifying_calls, - sum(cast(gas_used as double) / 1e9 * median_gas_price) as verifying_cost_ETH, - sum( - cast(gas_used as double) / 1e9 * median_gas_price * avg_eth_price - ) as verifying_cost_usd -from - ethereum.traces - left join eth_usd_price ep on block_date = ep.day - left join eth_gas_price gp on block_date = gp.day +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 - to = 0x3B6041173B80E77f038f3F2C0f9744f04837185e -- SP1VerifierGateway - and bytearray_substring (input, 1, 4) = 0x41493c60 -- verifyProof + tr.to = 0x3B6041173B80E77f038f3F2C0f9744f04837185e -- SP1VerifierGateway + and tr.call_type = 'staticcall' + and bytearray_substring (input, 1, 4) = 0x41493c60 -- verifyProof group by 1 \ No newline at end of file