@@ -21,10 +21,11 @@ use ethrex_common::{
2121 H256 ,
2222} ;
2323use ethrex_l2_rpc:: signer:: LocalSigner as EthrexLocalSigner ;
24- use ethrex_rpc:: clients:: Overrides ;
24+ use ethrex_rpc:: { clients:: Overrides , EthClient } ;
2525use ethrex_sdk:: { build_generic_tx, calldata:: encode_calldata, send_generic_transaction} ;
2626use fetcher:: { ProofsFetcher , ProofsFetcherError } ;
2727use merkle_tree:: compute_proofs_merkle_root;
28+ use risc0_ethereum_contracts:: encode_seal;
2829use secp256k1:: SecretKey ;
2930use std:: str:: FromStr ;
3031use tracing:: { error, info, warn} ;
@@ -49,6 +50,8 @@ pub struct ProofAggregator {
4950 proof_aggregation_service : AlignedProofAggregationServiceContract ,
5051 fetcher : ProofsFetcher ,
5152 config : Config ,
53+ ethrex_eth_client : EthClient ,
54+ ethrex_signer : ethrex_l2_rpc:: signer:: Signer ,
5255}
5356
5457impl ProofAggregator {
@@ -70,12 +73,18 @@ impl ProofAggregator {
7073 let engine =
7174 ZKVMEngine :: from_env ( ) . expect ( "AGGREGATOR env variable to be set to one of sp1|risc0" ) ;
7275 let fetcher = ProofsFetcher :: new ( & config) ;
76+ let ethrex_eth_client = ethrex_rpc:: EthClient :: new ( & config. eth_rpc_url ) . unwrap ( ) ;
77+ let secret_key = SecretKey :: from_str ( & config. ecdsa . private_key ) . unwrap ( ) ;
78+ let ethrex_signer =
79+ ethrex_l2_rpc:: signer:: Signer :: Local ( EthrexLocalSigner :: new ( secret_key) ) ;
7380
7481 Self {
7582 engine,
7683 proof_aggregation_service,
7784 fetcher,
7885 config,
86+ ethrex_eth_client,
87+ ethrex_signer,
7988 }
8089 }
8190
@@ -151,20 +160,16 @@ impl ProofAggregator {
151160 }
152161
153162 async fn send_proof_to_verify_on_chain (
154- & self ,
163+ & mut self ,
155164 blob_bundle : BlobsBundle ,
156165 blob_versioned_hash : [ u8 ; 32 ] ,
157166 aggregated_proof : AlignedProof ,
158167 ) -> Result < H256 , AggregatedProofSubmissionError > {
168+ // TODO: see how to get this
169+ self . ethrex_eth_client . maximum_allowed_max_fee_per_blob_gas = Some ( 1 ) ;
170+
159171 match aggregated_proof {
160172 AlignedProof :: SP1 ( proof) => {
161- let mut client = ethrex_rpc:: EthClient :: new ( & self . config . eth_rpc_url ) . unwrap ( ) ;
162- client. maximum_allowed_max_fee_per_blob_gas = Some ( 5 ) ;
163-
164- let secret_key = SecretKey :: from_str ( "<SECRET_KEY>" . into ( ) ) . unwrap ( ) ;
165- let signer =
166- ethrex_l2_rpc:: signer:: Signer :: Local ( EthrexLocalSigner :: new ( secret_key) ) ;
167-
168173 let calldata = encode_calldata (
169174 "verifySP1(bytes32,bytes,bytes)" ,
170175 & [
@@ -179,48 +184,68 @@ impl ProofAggregator {
179184 ) ,
180185 ] ,
181186 )
182- . unwrap ( ) ;
187+ . expect ( "Calldata to be valid" ) ;
183188
184- let gas_price = client. get_gas_price_with_extra ( 20 ) . await . unwrap ( ) ;
185189 let tx = build_generic_tx (
186- & client ,
190+ & self . ethrex_eth_client ,
187191 ethrex_common:: types:: TxType :: EIP4844 ,
188192 self . proof_aggregation_service . address ( ) . 0 . 0 . into ( ) ,
189- signer . address ( ) ,
193+ self . ethrex_signer . address ( ) ,
190194 calldata. into ( ) ,
191195 Overrides {
192- max_fee_per_gas : Some ( gas_price. try_into ( ) . unwrap ( ) ) ,
193- max_priority_fee_per_gas : Some ( gas_price. try_into ( ) . unwrap ( ) ) ,
194- gas_price_per_blob : Some ( gas_price) ,
195196 blobs_bundle : Some ( blob_bundle) ,
196197 ..Default :: default ( )
197198 } ,
198199 )
199200 . await
200- . unwrap ( ) ;
201-
202- println ! ( "TX {:?}" , tx) ;
201+ . expect ( "Tx to be built correctly" ) ;
203202
204- let tx_hash = send_generic_transaction ( & client, tx, & signer)
205- . await
206- . unwrap ( ) ;
203+ let tx_hash =
204+ send_generic_transaction ( & self . ethrex_eth_client , tx, & self . ethrex_signer )
205+ . await
206+ . expect ( "Transaction to be sent" ) ;
207207
208208 Ok ( tx_hash)
209209 }
210210 AlignedProof :: Risc0 ( proof) => {
211- // let encoded_seal = encode_seal(&proof.receipt).map_err(|e| {
212- // AggregatedProofSubmissionError::Risc0EncodingSeal(e.to_string())
213- // })?;
214- // self.proof_aggregation_service
215- // .verifyRisc0(
216- // blob_versioned_hash.into(),
217- // encoded_seal.into(),
218- // proof.receipt.journal.bytes.into(),
219- // )
220- // .sidecar(blob)
221- // .send()
222- // .await
223- Ok ( H256 :: default ( ) )
211+ let encoded_seal = encode_seal ( & proof. receipt ) . map_err ( |e| {
212+ AggregatedProofSubmissionError :: Risc0EncodingSeal ( e. to_string ( ) )
213+ } ) ?;
214+
215+ let calldata = encode_calldata (
216+ "verifyRisc0(bytes32,bytes,bytes)" ,
217+ & [
218+ ethrex_l2_common:: calldata:: Value :: FixedBytes (
219+ blob_versioned_hash. to_vec ( ) . into ( ) ,
220+ ) ,
221+ ethrex_l2_common:: calldata:: Value :: Bytes ( encoded_seal. into ( ) ) ,
222+ ethrex_l2_common:: calldata:: Value :: Bytes (
223+ proof. receipt . journal . bytes . into ( ) ,
224+ ) ,
225+ ] ,
226+ )
227+ . expect ( "Calldata to be valid" ) ;
228+
229+ let tx = build_generic_tx (
230+ & self . ethrex_eth_client ,
231+ ethrex_common:: types:: TxType :: EIP4844 ,
232+ self . proof_aggregation_service . address ( ) . 0 . 0 . into ( ) ,
233+ self . ethrex_signer . address ( ) ,
234+ calldata. into ( ) ,
235+ Overrides {
236+ blobs_bundle : Some ( blob_bundle) ,
237+ ..Default :: default ( )
238+ } ,
239+ )
240+ . await
241+ . expect ( "Tx to be built correctly" ) ;
242+
243+ let tx_hash =
244+ send_generic_transaction ( & self . ethrex_eth_client , tx, & self . ethrex_signer )
245+ . await
246+ . expect ( "Transaction to be sent" ) ;
247+
248+ Ok ( tx_hash)
224249 }
225250 }
226251 }
0 commit comments