Skip to content

Commit 87580e1

Browse files
Simplify the bytes decoding using hex::decode
1 parent 189a135 commit 87580e1

File tree

1 file changed

+20
-40
lines changed
  • aggregation_mode/src/backend

1 file changed

+20
-40
lines changed

aggregation_mode/src/backend/mod.rs

Lines changed: 20 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -191,24 +191,15 @@ impl ProofAggregator {
191191
) -> Result<H256, AggregatedProofSubmissionError> {
192192
let calldata = match aggregated_proof {
193193
AlignedProof::SP1(proof) => {
194-
let vk_hash: [u8; 32] = {
195-
let hex_str = self
196-
.config
197-
.sp1_chunk_aggregator_vk_hash
198-
.strip_prefix("0x")
199-
.unwrap_or(&self.config.sp1_chunk_aggregator_vk_hash);
200-
let bytes = hex::decode(hex_str).map_err(|e| {
201-
AggregatedProofSubmissionError::BuildingVKHash(e.to_string())
202-
})?;
203-
if bytes.len() != 32 {
204-
return Err(AggregatedProofSubmissionError::BuildingVKHash(
205-
"vk hash not 32 bytes".into(),
206-
));
207-
}
208-
let mut arr = [0u8; 32];
209-
arr.copy_from_slice(&bytes);
210-
arr
211-
};
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+
})?;
212203

213204
encode_calldata(
214205
"verifySP1(bytes32,bytes,bytes,bytes32)",
@@ -222,7 +213,7 @@ impl ProofAggregator {
222213
ethrex_l2_common::calldata::Value::Bytes(
223214
proof.proof_with_pub_values.bytes().into(),
224215
),
225-
ethrex_l2_common::calldata::Value::FixedBytes(vk_hash.to_vec().into()),
216+
ethrex_l2_common::calldata::Value::FixedBytes(vk_hash),
226217
],
227218
)
228219
.map_err(|e| AggregatedProofSubmissionError::BuildingCalldata(e.to_string()))?
@@ -232,24 +223,15 @@ impl ProofAggregator {
232223
AggregatedProofSubmissionError::Risc0EncodingSeal(e.to_string())
233224
})?;
234225

235-
let risc0_image_id: [u8; 32] = {
236-
let hex_str = self
237-
.config
238-
.risc0_chunk_aggregator_image_id
239-
.strip_prefix("0x")
240-
.unwrap_or(&self.config.risc0_chunk_aggregator_image_id);
241-
let bytes = hex::decode(hex_str).map_err(|e| {
242-
AggregatedProofSubmissionError::BuildingVKHash(e.to_string())
243-
})?;
244-
if bytes.len() != 32 {
245-
return Err(AggregatedProofSubmissionError::BuildingVKHash(
246-
"risc0 image id not 32 bytes".into(),
247-
));
248-
}
249-
let mut arr = [0u8; 32];
250-
arr.copy_from_slice(&bytes);
251-
arr
252-
};
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+
})?;
253235

254236
encode_calldata(
255237
"verifyRisc0(bytes32,bytes,bytes,bytes32)",
@@ -261,9 +243,7 @@ impl ProofAggregator {
261243
ethrex_l2_common::calldata::Value::Bytes(
262244
proof.receipt.journal.bytes.into(),
263245
),
264-
ethrex_l2_common::calldata::Value::FixedBytes(
265-
risc0_image_id.to_vec().into(),
266-
),
246+
ethrex_l2_common::calldata::Value::FixedBytes(risc0_image_id),
267247
],
268248
)
269249
.map_err(|e| AggregatedProofSubmissionError::BuildingCalldata(e.to_string()))?

0 commit comments

Comments
 (0)