@@ -36,6 +36,7 @@ use ethrex_sdk::{build_generic_tx, calldata::encode_calldata, send_generic_trans
3636use fetcher:: { ProofsFetcher , ProofsFetcherError } ;
3737use merkle_tree:: compute_proofs_merkle_root;
3838use risc0_ethereum_contracts:: encode_seal;
39+ use risc0_zkvm:: Bytes ;
3940use secp256k1:: SecretKey ;
4041use std:: str:: FromStr ;
4142use tracing:: { error, info, warn} ;
@@ -65,6 +66,8 @@ pub struct ProofAggregator {
6566 config : Config ,
6667 ethrex_eth_client : EthClient ,
6768 ethrex_signer : ethrex_l2_rpc:: signer:: Signer ,
69+ sp1_chunk_aggregator_vk_hash_bytes : Bytes ,
70+ risc0_chunk_aggregator_image_id_bytes : Bytes ,
6871}
6972
7073impl ProofAggregator {
@@ -102,13 +105,33 @@ impl ProofAggregator {
102105 let ethrex_signer =
103106 ethrex_l2_rpc:: signer:: Signer :: Local ( EthrexLocalSigner :: new ( secret_key) ) ;
104107
108+ let sp1_chunk_aggregator_vk_hash_bytes: Bytes =
109+ hex:: decode ( self . config . sp1_chunk_aggregator_vk_hash . clone ( ) )
110+ . map_err ( |e| AggregatedProofSubmissionError :: BuildingVKHash ( e. to_string ( ) ) ) ?
111+ . try_into ( )
112+ . map_err ( |_| {
113+ AggregatedProofSubmissionError :: BuildingVKHash ( "VK hash is not 32 bytes" . into ( ) )
114+ } ) ?;
115+
116+ let risc0_chunk_aggregator_image_id_bytes: Bytes =
117+ hex:: decode ( self . config . risc0_chunk_aggregator_image_id . clone ( ) )
118+ . map_err ( |e| AggregatedProofSubmissionError :: BuildingVKHash ( e. to_string ( ) ) ) ?
119+ . try_into ( )
120+ . map_err ( |_| {
121+ AggregatedProofSubmissionError :: BuildingVKHash (
122+ "Risc0 image id is not 32 bytes" . into ( ) ,
123+ )
124+ } ) ?;
125+
105126 Self {
106127 engine,
107128 proof_aggregation_service,
108129 fetcher,
109130 config,
110131 ethrex_eth_client,
111132 ethrex_signer,
133+ sp1_chunk_aggregator_vk_hash_bytes,
134+ risc0_chunk_aggregator_image_id_bytes,
112135 }
113136 }
114137
@@ -190,49 +213,29 @@ impl ProofAggregator {
190213 aggregated_proof : AlignedProof ,
191214 ) -> Result < H256 , AggregatedProofSubmissionError > {
192215 let calldata = match aggregated_proof {
193- AlignedProof :: SP1 ( proof) => {
194- let vk_hash: risc0_zkvm:: Bytes =
195- hex:: decode ( self . config . sp1_chunk_aggregator_vk_hash . clone ( ) )
196- . map_err ( |e| AggregatedProofSubmissionError :: BuildingVKHash ( e. to_string ( ) ) ) ?
197- . try_into ( )
198- . map_err ( |_| {
199- AggregatedProofSubmissionError :: BuildingVKHash (
200- "VK hash is not 32 bytes" . into ( ) ,
201- )
202- } ) ?;
203-
204- encode_calldata (
205- "verifySP1(bytes32,bytes,bytes,bytes32)" ,
206- & [
207- ethrex_l2_common:: calldata:: Value :: FixedBytes (
208- blob_versioned_hash. to_vec ( ) . into ( ) ,
209- ) ,
210- ethrex_l2_common:: calldata:: Value :: Bytes (
211- proof. proof_with_pub_values . public_values . to_vec ( ) . into ( ) ,
212- ) ,
213- ethrex_l2_common:: calldata:: Value :: Bytes (
214- proof. proof_with_pub_values . bytes ( ) . into ( ) ,
215- ) ,
216- ethrex_l2_common:: calldata:: Value :: FixedBytes ( vk_hash) ,
217- ] ,
218- )
219- . map_err ( |e| AggregatedProofSubmissionError :: BuildingCalldata ( e. to_string ( ) ) ) ?
220- }
216+ AlignedProof :: SP1 ( proof) => encode_calldata (
217+ "verifySP1(bytes32,bytes,bytes,bytes32)" ,
218+ & [
219+ ethrex_l2_common:: calldata:: Value :: FixedBytes (
220+ blob_versioned_hash. to_vec ( ) . into ( ) ,
221+ ) ,
222+ ethrex_l2_common:: calldata:: Value :: Bytes (
223+ proof. proof_with_pub_values . public_values . to_vec ( ) . into ( ) ,
224+ ) ,
225+ ethrex_l2_common:: calldata:: Value :: Bytes (
226+ proof. proof_with_pub_values . bytes ( ) . into ( ) ,
227+ ) ,
228+ ethrex_l2_common:: calldata:: Value :: FixedBytes (
229+ self . sp1_chunk_aggregator_vk_hash_bytes . clone ( ) ,
230+ ) ,
231+ ] ,
232+ )
233+ . map_err ( |e| AggregatedProofSubmissionError :: BuildingCalldata ( e. to_string ( ) ) ) ?,
221234 AlignedProof :: Risc0 ( proof) => {
222235 let encoded_seal = encode_seal ( & proof. receipt ) . map_err ( |e| {
223236 AggregatedProofSubmissionError :: Risc0EncodingSeal ( e. to_string ( ) )
224237 } ) ?;
225238
226- let risc0_image_id: risc0_zkvm:: Bytes =
227- hex:: decode ( self . config . risc0_chunk_aggregator_image_id . clone ( ) )
228- . map_err ( |e| AggregatedProofSubmissionError :: BuildingVKHash ( e. to_string ( ) ) ) ?
229- . try_into ( )
230- . map_err ( |_| {
231- AggregatedProofSubmissionError :: BuildingVKHash (
232- "Risc0 image id is not 32 bytes" . into ( ) ,
233- )
234- } ) ?;
235-
236239 encode_calldata (
237240 "verifyRisc0(bytes32,bytes,bytes,bytes32)" ,
238241 & [
@@ -243,7 +246,9 @@ impl ProofAggregator {
243246 ethrex_l2_common:: calldata:: Value :: Bytes (
244247 proof. receipt . journal . bytes . into ( ) ,
245248 ) ,
246- ethrex_l2_common:: calldata:: Value :: FixedBytes ( risc0_image_id) ,
249+ ethrex_l2_common:: calldata:: Value :: FixedBytes (
250+ self . risc0_chunk_aggregator_image_id_bytes . clone ( ) ,
251+ ) ,
247252 ] ,
248253 )
249254 . map_err ( |e| AggregatedProofSubmissionError :: BuildingCalldata ( e. to_string ( ) ) ) ?
0 commit comments