@@ -142,7 +142,11 @@ impl Ty {
142142 pub fn serialize ( & self , legacy_storage : bool ) -> Result < Vec < Felt > , PrimitiveError > {
143143 let mut felts = vec ! [ ] ;
144144
145- fn serialize_inner ( ty : & Ty , felts : & mut Vec < Felt > , legacy_storage : bool ) -> Result < ( ) , PrimitiveError > {
145+ fn serialize_inner (
146+ ty : & Ty ,
147+ felts : & mut Vec < Felt > ,
148+ legacy_storage : bool ,
149+ ) -> Result < ( ) , PrimitiveError > {
146150 match ty {
147151 Ty :: Primitive ( c) => {
148152 felts. extend ( c. serialize ( ) ?) ;
@@ -155,21 +159,20 @@ impl Ty {
155159 Ty :: Enum ( e) => {
156160 if let Some ( option) = e. option {
157161 // For new storage system, enum variant indices start from 1
158- let serialized_option = if legacy_storage {
159- option
160- } else {
161- option + 1
162- } ;
163- felts. push ( Felt :: from ( serialized_option) ) ;
164-
162+ let mut serialized_option = Felt :: from ( option) ;
163+ if !legacy_storage {
164+ serialized_option += Felt :: ONE ;
165+ }
166+ felts. push ( serialized_option) ;
167+
165168 // Only serialize the selected option
166169 if let Some ( selected_option) = e. options . get ( option as usize ) {
167170 serialize_inner ( & selected_option. ty , felts, legacy_storage) ?;
168171 }
169172 } else {
170173 // For uninitialized enum in new storage system, use 0
171174 if !legacy_storage {
172- felts. push ( Felt :: from ( 0u8 ) ) ;
175+ felts. push ( Felt :: ZERO ) ;
173176 } else {
174177 return Err ( PrimitiveError :: MissingFieldElement ) ;
175178 }
0 commit comments