@@ -3,8 +3,34 @@ use sha3::{Digest, Keccak256};
33
44use 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 ) ]
1036pub 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 ( )
0 commit comments