Skip to content

Commit 7fd5272

Browse files
move chunk aggregator image IDs parsing to initialization
1 parent 87580e1 commit 7fd5272

File tree

1 file changed

+44
-39
lines changed
  • aggregation_mode/src/backend

1 file changed

+44
-39
lines changed

aggregation_mode/src/backend/mod.rs

Lines changed: 44 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ use ethrex_sdk::{build_generic_tx, calldata::encode_calldata, send_generic_trans
3636
use fetcher::{ProofsFetcher, ProofsFetcherError};
3737
use merkle_tree::compute_proofs_merkle_root;
3838
use risc0_ethereum_contracts::encode_seal;
39+
use risc0_zkvm::Bytes;
3940
use secp256k1::SecretKey;
4041
use std::str::FromStr;
4142
use 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

7073
impl 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

Comments
 (0)