@@ -10,7 +10,7 @@ use crate::{
1010 aggregators:: { AlignedProof , ProofAggregationError , ZKVMEngine } ,
1111 backend:: {
1212 db:: { Db , DbError } ,
13- retry:: { retry_function, RetryError } ,
13+ retry:: { retry_function, wait_and_send_proof_to_verify_on_chain } ,
1414 } ,
1515} ;
1616
@@ -19,22 +19,20 @@ use aligned_sdk::common::constants::{
1919 ETHEREUM_CALL_MIN_RETRY_DELAY ,
2020} ;
2121use alloy:: {
22- consensus:: { BlobTransactionSidecar , EnvKzgSettings , EthereumTxEnvelope , TxEip4844WithSidecar } ,
23- eips:: { eip4844:: BYTES_PER_BLOB , eip7594 :: BlobTransactionSidecarEip7594 , Encodable2718 } ,
22+ consensus:: BlobTransactionSidecar ,
23+ eips:: eip4844:: BYTES_PER_BLOB ,
2424 hex,
2525 network:: EthereumWallet ,
26- primitives:: { utils:: parse_ether, Address , U256 } ,
27- providers:: { PendingTransactionError , Provider , ProviderBuilder } ,
26+ primitives:: { utils:: parse_ether, Address } ,
27+ providers:: { PendingTransactionError , ProviderBuilder } ,
2828 rpc:: types:: TransactionReceipt ,
2929 signers:: local:: LocalSigner ,
3030} ;
3131use config:: Config ;
3232use fetcher:: { ProofsFetcher , ProofsFetcherError } ;
3333use merkle_tree:: compute_proofs_merkle_root;
34- use risc0_ethereum_contracts:: encode_seal;
3534use sqlx:: types:: Uuid ;
36- use std:: thread:: sleep;
37- use std:: { str:: FromStr , time:: Duration } ;
35+ use std:: str:: FromStr ;
3836use tracing:: { error, info, warn} ;
3937use types:: { AlignedProofAggregationService , AlignedProofAggregationServiceContract } ;
4038
@@ -319,136 +317,14 @@ impl ProofAggregator {
319317 }
320318}
321319
322- async fn wait_until_can_submit_aggregated_proof (
323- proof_aggregation_service : AlignedProofAggregationServiceContract ,
324- monthly_budget_eth : f64 ,
325- ) -> Result < ( ) , RetryError < AggregatedProofSubmissionError > > {
326- // We start on 24 hours because the proof aggregator runs once a day, so the time elapsed
327- // should be considered over a 24h period.
328- let mut time_elapsed = Duration :: from_secs ( 24 * 3600 ) ;
329-
330- // Iterate until we can send the proof on-chain
331- loop {
332- // Fetch gas price from network
333- let gas_price = proof_aggregation_service
334- . provider ( )
335- . get_gas_price ( )
336- . await
337- . map_err ( |e| {
338- RetryError :: Transient ( AggregatedProofSubmissionError :: GasPriceError ( e. to_string ( ) ) )
339- } ) ?;
340-
341- if helpers:: should_send_proof_to_verify_on_chain (
342- time_elapsed,
343- monthly_budget_eth,
344- U256 :: from ( gas_price) ,
345- ) {
346- break ;
347- } else {
348- info ! ( "Skipping sending proof to ProofAggregationService contract due to budget/time constraints." ) ;
349- }
350-
351- // Sleep for 3 minutes (15 blocks) before re-evaluating
352- let time_to_sleep = Duration :: from_secs ( 180 ) ;
353- time_elapsed += time_to_sleep;
354- sleep ( time_to_sleep) ;
355- }
356-
357- Ok ( ( ) )
358- }
359-
360- async fn wait_and_send_proof_to_verify_on_chain (
361- blob : BlobTransactionSidecar ,
362- blob_versioned_hash : [ u8 ; 32 ] ,
363- aggregated_proof : AlignedProof ,
364- proof_aggregation_service : AlignedProofAggregationServiceContract ,
365- sp1_chunk_aggregator_vk_hash_bytes : [ u8 ; 32 ] ,
366- risc0_chunk_aggregator_image_id_bytes : [ u8 ; 32 ] ,
367- monthly_budget_eth : f64 ,
368- ) -> Result < TransactionReceipt , RetryError < AggregatedProofSubmissionError > > {
369- wait_until_can_submit_aggregated_proof ( proof_aggregation_service. clone ( ) , monthly_budget_eth)
370- . await ?;
371-
372- info ! ( "Sending proof to ProofAggregationService contract..." ) ;
373-
374- let tx_req = match aggregated_proof {
375- AlignedProof :: SP1 ( proof) => proof_aggregation_service
376- . verifyAggregationSP1 (
377- blob_versioned_hash. into ( ) ,
378- proof. proof_with_pub_values . public_values . to_vec ( ) . into ( ) ,
379- proof. proof_with_pub_values . bytes ( ) . into ( ) ,
380- sp1_chunk_aggregator_vk_hash_bytes. into ( ) ,
381- )
382- . sidecar ( blob)
383- . into_transaction_request ( ) ,
384- AlignedProof :: Risc0 ( proof) => {
385- let encoded_seal = encode_seal ( & proof. receipt )
386- . map_err ( |e| AggregatedProofSubmissionError :: Risc0EncodingSeal ( e. to_string ( ) ) )
387- . map_err ( RetryError :: Transient ) ?;
388- proof_aggregation_service
389- . verifyAggregationRisc0 (
390- blob_versioned_hash. into ( ) ,
391- encoded_seal. into ( ) ,
392- proof. receipt . journal . bytes . into ( ) ,
393- risc0_chunk_aggregator_image_id_bytes. into ( ) ,
394- )
395- . sidecar ( blob)
396- . into_transaction_request ( )
397- }
398- } ;
399-
400- let provider = proof_aggregation_service. provider ( ) ;
401- let envelope = provider
402- . fill ( tx_req)
403- . await
404- . map_err ( |err| {
405- AggregatedProofSubmissionError :: SendVerifyAggregatedProofTransaction ( err. to_string ( ) )
406- } )
407- . map_err ( RetryError :: Transient ) ?
408- . try_into_envelope ( )
409- . map_err ( |err| {
410- AggregatedProofSubmissionError :: SendVerifyAggregatedProofTransaction ( err. to_string ( ) )
411- } )
412- . map_err ( RetryError :: Transient ) ?;
413- let tx: EthereumTxEnvelope < TxEip4844WithSidecar < BlobTransactionSidecarEip7594 > > = envelope
414- . try_into_pooled ( )
415- . map_err ( |err| {
416- AggregatedProofSubmissionError :: SendVerifyAggregatedProofTransaction ( err. to_string ( ) )
417- } )
418- . map_err ( RetryError :: Transient ) ?
419- . try_map_eip4844 ( |tx| {
420- tx. try_map_sidecar ( |sidecar| sidecar. try_into_7594 ( EnvKzgSettings :: Default . get ( ) ) )
421- } )
422- . map_err ( |err| {
423- AggregatedProofSubmissionError :: SendVerifyAggregatedProofTransaction ( err. to_string ( ) )
424- } )
425- . map_err ( RetryError :: Transient ) ?;
426-
427- let encoded_tx = tx. encoded_2718 ( ) ;
428- let pending_tx = provider
429- . send_raw_transaction ( & encoded_tx)
430- . await
431- . map_err ( |err| {
432- AggregatedProofSubmissionError :: SendVerifyAggregatedProofTransaction ( err. to_string ( ) )
433- } )
434- . map_err ( RetryError :: Transient ) ?;
435-
436- let receipt = pending_tx
437- . get_receipt ( )
438- . await
439- . map_err ( |err| {
440- AggregatedProofSubmissionError :: SendVerifyAggregatedProofTransaction ( err. to_string ( ) )
441- } )
442- . map_err ( RetryError :: Transient ) ?;
443-
444- Ok ( receipt)
445- }
446-
447320#[ cfg( test) ]
448321mod tests {
322+
449323 use super :: * ;
450324
325+ use alloy:: primitives:: U256 ;
451326 use helpers:: should_send_proof_to_verify_on_chain;
327+ use std:: time:: Duration ;
452328
453329 #[ test]
454330 fn test_should_send_proof_to_verify_on_chain_updated_cases ( ) {
0 commit comments