Skip to content

Commit 6f47f54

Browse files
committed
refactor: proving system id replace constants for enum
1 parent d26fb28 commit 6f47f54

File tree

5 files changed

+39
-13
lines changed

5 files changed

+39
-13
lines changed

aggregation_mode/src/aggregators/risc0_aggregator.rs

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

3-
use aligned_sdk::aggregation_layer::RISC0_PROVING_SYSTEM_ID;
3+
use aligned_sdk::aggregation_layer::AggregationModeProvingSystem;
44
use risc0_zkvm::{default_prover, ExecutorEnv, ProverOpts, Receipt};
55
use sha3::{Digest, Keccak256};
66

@@ -81,7 +81,7 @@ pub const RISC0_CHUNK_AGGREGATOR_PROGRAM_ID_BYTES: [u8; 32] = {
8181
impl Risc0ProofReceiptAndImageId {
8282
pub fn hash_image_id_and_public_inputs(&self) -> [u8; 32] {
8383
let mut hasher = Keccak256::new();
84-
hasher.update(&[RISC0_PROVING_SYSTEM_ID]);
84+
hasher.update(&[AggregationModeProvingSystem::RISC0.id()]);
8585
hasher.update(self.image_id);
8686
hasher.update(self.public_inputs());
8787
hasher.finalize().into()

aggregation_mode/src/aggregators/sp1_aggregator.rs

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

3-
use aligned_sdk::aggregation_layer::SP1_PROVING_SYSTEM_ID;
3+
use aligned_sdk::aggregation_layer::AggregationModeProvingSystem;
44
use alloy::primitives::Keccak256;
55
use sp1_aggregation_program::SP1VkAndPubInputs;
66
#[cfg(feature = "prove")]
@@ -64,7 +64,7 @@ impl SP1ProofWithPubValuesAndElf {
6464

6565
pub fn hash_vk_and_pub_inputs(&self) -> [u8; 32] {
6666
let mut hasher = Keccak256::new();
67-
hasher.update(&[SP1_PROVING_SYSTEM_ID]);
67+
hasher.update(&[AggregationModeProvingSystem::SP1.id()]);
6868
let vk_bytes = &self.vk.hash_bytes();
6969
hasher.update(vk_bytes);
7070
hasher.update(self.proof_with_pub_values.public_values.as_slice());

crates/sdk/src/aggregation_layer/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ mod types;
44

55
// Makes only the two types on this use public
66
pub use types::{
7-
AggregationModeVerificationData, ProofVerificationAggModeError, RISC0_PROVING_SYSTEM_ID,
8-
SP1_PROVING_SYSTEM_ID,
7+
AggregationModeProvingSystem, AggregationModeVerificationData, ProofVerificationAggModeError,
98
};
109

1110
use crate::{

crates/sdk/src/aggregation_layer/types.rs

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,34 @@ 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;
6+
#[repr(u8)]
7+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8+
pub enum AggregationModeProvingSystem {
9+
SP1 = 0,
10+
RISC0 = 1,
11+
}
12+
13+
impl AggregationModeProvingSystem {
14+
pub const fn as_u8(self) -> u8 {
15+
self as u8
16+
}
17+
18+
pub const fn id(self) -> u8 {
19+
self.as_u8()
20+
}
21+
}
22+
23+
impl TryFrom<u8> for AggregationModeProvingSystem {
24+
type Error = ();
25+
26+
fn try_from(v: u8) -> Result<Self, Self::Error> {
27+
match v {
28+
0 => Ok(AggregationModeProvingSystem::SP1),
29+
1 => Ok(AggregationModeProvingSystem::RISC0),
30+
_ => Err(()),
31+
}
32+
}
33+
}
834

935
#[derive(Debug)]
1036
pub enum AggregationModeVerificationData {
@@ -35,16 +61,16 @@ impl AggregationModeVerificationData {
3561

3662
pub fn proving_system_id(&self) -> u8 {
3763
match self {
38-
Self::SP1 { .. } => SP1_PROVING_SYSTEM_ID,
39-
Self::Risc0 { .. } => RISC0_PROVING_SYSTEM_ID,
64+
Self::SP1 { .. } => AggregationModeProvingSystem::SP1.id(),
65+
Self::Risc0 { .. } => AggregationModeProvingSystem::RISC0.id(),
4066
}
4167
}
4268

4369
pub fn commitment(&self) -> [u8; 32] {
4470
match self {
4571
AggregationModeVerificationData::SP1 { vk, public_inputs } => {
4672
let mut hasher = Keccak256::new();
47-
hasher.update(&[0u8]);
73+
hasher.update(&[self.proving_system_id()]);
4874
hasher.update(vk);
4975
hasher.update(public_inputs);
5076
hasher.finalize().into()
@@ -54,7 +80,7 @@ impl AggregationModeVerificationData {
5480
public_inputs,
5581
} => {
5682
let mut hasher = Keccak256::new();
57-
hasher.update(&[1u8]);
83+
hasher.update(&[self.proving_system_id()]);
5884
hasher.update(image_id);
5985
hasher.update(public_inputs);
6086
hasher.finalize().into()

examples/l2/crates/l2/src/eth.rs

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

3+
use aligned_sdk::aggregation_layer::AggregationModeProvingSystem;
34
use alloy::{
45
network::EthereumWallet, primitives::Address, providers::ProviderBuilder,
56
rpc::types::TransactionReceipt, signers::local::LocalSigner, sol,
@@ -37,7 +38,7 @@ pub async fn send_state_transition_to_chain(
3738

3839
let res = state_transition_contract
3940
.updateState(
40-
SP1_PROVING_SYSTEM_ID.into(),
41+
AggregationModeProvingSystem::SP1.id().into(),
4142
public_inputs.into(),
4243
merkle_proof,
4344
)

0 commit comments

Comments
 (0)