Skip to content

Commit a47f3c5

Browse files
committed
refactor: centralize proving system id constant
1 parent 9ac3a59 commit a47f3c5

File tree

6 files changed

+19
-7
lines changed

6 files changed

+19
-7
lines changed

aggregation_mode/aggregation_programs/risc0/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ use lambdaworks_crypto::merkle_tree::traits::IsMerkleTreeBackend;
22
use serde::{Deserialize, Serialize};
33
use tiny_keccak::{Hasher, Keccak};
44

5+
const RISC0_PROVING_SYSTEM_ID: u8 = 1;
6+
57
#[derive(Serialize, Deserialize)]
68
pub struct Risc0ImageIdAndPubInputs {
79
pub image_id: [u8; 32],
@@ -11,7 +13,7 @@ pub struct Risc0ImageIdAndPubInputs {
1113
impl Risc0ImageIdAndPubInputs {
1214
pub fn commitment(&self) -> [u8; 32] {
1315
let mut hasher = Keccak::v256();
14-
hasher.update(&[1u8]);
16+
hasher.update(&[RISC0_PROVING_SYSTEM_ID]);
1517
for &word in &self.image_id {
1618
hasher.update(&word.to_be_bytes());
1719
}

aggregation_mode/aggregation_programs/sp1/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ use lambdaworks_crypto::merkle_tree::traits::IsMerkleTreeBackend;
22
use serde::{Deserialize, Serialize};
33
use sha3::{Digest, Keccak256};
44

5+
const SP1_PROVING_SYSTEM_ID: u8 = 0;
6+
57
#[derive(Serialize, Deserialize)]
68
pub struct SP1VkAndPubInputs {
79
pub vk: [u32; 8],
@@ -11,7 +13,7 @@ pub struct SP1VkAndPubInputs {
1113
impl SP1VkAndPubInputs {
1214
pub fn commitment(&self) -> [u8; 32] {
1315
let mut hasher = Keccak256::new();
14-
hasher.update(&[0u8]);
16+
hasher.update(&[SP1_PROVING_SYSTEM_ID]);
1517
for &word in &self.vk {
1618
hasher.update(word.to_be_bytes());
1719
}

aggregation_mode/src/aggregators/risc0_aggregator.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
include!(concat!(env!("OUT_DIR"), "/methods.rs"));
22

3+
use aligned_sdk::aggregation_layer::RISC0_PROVING_SYSTEM_ID;
34
use risc0_zkvm::{default_prover, ExecutorEnv, ProverOpts, Receipt};
45
use sha3::{Digest, Keccak256};
56

@@ -80,7 +81,7 @@ pub const RISC0_CHUNK_AGGREGATOR_PROGRAM_ID_BYTES: [u8; 32] = {
8081
impl Risc0ProofReceiptAndImageId {
8182
pub fn hash_image_id_and_public_inputs(&self) -> [u8; 32] {
8283
let mut hasher = Keccak256::new();
83-
hasher.update(&[1u8]);
84+
hasher.update(&[RISC0_PROVING_SYSTEM_ID]);
8485
hasher.update(self.image_id);
8586
hasher.update(self.public_inputs());
8687
hasher.finalize().into()

aggregation_mode/src/aggregators/sp1_aggregator.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::sync::LazyLock;
22

3+
use aligned_sdk::aggregation_layer::SP1_PROVING_SYSTEM_ID;
34
use alloy::primitives::Keccak256;
45
use sp1_aggregation_program::SP1VkAndPubInputs;
56
#[cfg(feature = "prove")]
@@ -63,7 +64,7 @@ impl SP1ProofWithPubValuesAndElf {
6364

6465
pub fn hash_vk_and_pub_inputs(&self) -> [u8; 32] {
6566
let mut hasher = Keccak256::new();
66-
hasher.update(&[0u8]);
67+
hasher.update(&[SP1_PROVING_SYSTEM_ID]);
6768
let vk_bytes = &self.vk.hash_bytes();
6869
hasher.update(vk_bytes);
6970
hasher.update(self.proof_with_pub_values.public_values.as_slice());

crates/sdk/src/aggregation_layer/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ mod helpers;
33
mod types;
44

55
// Makes only the two types on this use public
6-
pub use types::{AggregationModeVerificationData, ProofVerificationAggModeError};
6+
pub use types::{
7+
AggregationModeVerificationData, ProofVerificationAggModeError, RISC0_PROVING_SYSTEM_ID,
8+
SP1_PROVING_SYSTEM_ID,
9+
};
710

811
use crate::{
912
common::types::Network, eth::aligned_proof_agg_service::aligned_proof_aggregation_service,

crates/sdk/src/aggregation_layer/types.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ use sha3::{Digest, Keccak256};
33

44
use crate::beacon::BeaconClientError;
55

6+
pub const SP1_PROVING_SYSTEM_ID: u8 = 0;
7+
pub const RISC0_PROVING_SYSTEM_ID: u8 = 1;
8+
69
#[derive(Debug)]
710
pub enum AggregationModeVerificationData {
811
SP1 {
@@ -32,8 +35,8 @@ impl AggregationModeVerificationData {
3235

3336
pub fn proving_system_id(&self) -> u8 {
3437
match self {
35-
Self::SP1 { .. } => 0u8,
36-
Self::Risc0 { .. } => 1u8,
38+
Self::SP1 { .. } => SP1_PROVING_SYSTEM_ID,
39+
Self::Risc0 { .. } => RISC0_PROVING_SYSTEM_ID,
3740
}
3841
}
3942

0 commit comments

Comments
 (0)