@@ -6,6 +6,7 @@ use crate::{
66 execution_result:: EC_OP_BUILTIN_SIZE ,
77 libfuncs:: increment_builtin_counter_conditionally_by,
88 metadata:: { runtime_bindings:: RuntimeBindingsMeta , MetadataStorage } ,
9+ types:: { ec_point:: ec_point_ty, ec_state:: ec_state_ty} ,
910 utils:: { get_integer_layout, ProgramRegistryExt , PRIME } ,
1011} ;
1112use cairo_lang_sierra:: {
@@ -178,14 +179,7 @@ pub fn build_point_from_x<'ctx, 'this>(
178179 metadata : & mut MetadataStorage ,
179180 _info : & SignatureOnlyConcreteLibfunc ,
180181) -> Result < ( ) > {
181- let ec_point_ty = llvm:: r#type:: r#struct (
182- context,
183- & [
184- IntegerType :: new ( context, 252 ) . into ( ) ,
185- IntegerType :: new ( context, 252 ) . into ( ) ,
186- ] ,
187- false ,
188- ) ;
182+ let ec_point_ty = ec_point_ty ( context) ;
189183
190184 let point_ptr = helper. init_block ( ) . alloca1 (
191185 context,
@@ -240,14 +234,7 @@ pub fn build_state_add<'ctx, 'this>(
240234 metadata : & mut MetadataStorage ,
241235 _info : & SignatureOnlyConcreteLibfunc ,
242236) -> Result < ( ) > {
243- let ec_state_ty = llvm:: r#type:: r#struct (
244- context,
245- & [
246- IntegerType :: new ( context, 252 ) . into ( ) ,
247- IntegerType :: new ( context, 252 ) . into ( ) ,
248- ] ,
249- false ,
250- ) ;
237+ let ec_state_ty = ec_state_ty ( context) ;
251238
252239 let state_ptr = helper. init_block ( ) . alloca1 (
253240 context,
@@ -258,7 +245,7 @@ pub fn build_state_add<'ctx, 'this>(
258245 let point_ptr = helper. init_block ( ) . alloca1 (
259246 context,
260247 location,
261- ec_state_ty ,
248+ ec_point_ty ( context ) ,
262249 get_integer_layout ( 252 ) . align ( ) ,
263250 ) ?;
264251
@@ -296,8 +283,8 @@ pub fn build_state_add_mul<'ctx, 'this>(
296283 ) ?;
297284
298285 let felt252_ty = IntegerType :: new ( context, 252 ) . into ( ) ;
299- let ec_state_ty = llvm :: r#type :: r#struct ( context, & [ felt252_ty , felt252_ty ] , false ) ;
300- let ec_point_ty = llvm :: r#type :: r#struct ( context, & [ felt252_ty , felt252_ty ] , false ) ;
286+ let ec_state_ty = ec_state_ty ( context) ;
287+ let ec_point_ty = ec_point_ty ( context) ;
301288
302289 let state_ptr = helper. init_block ( ) . alloca1 (
303290 context,
@@ -344,9 +331,8 @@ pub fn build_state_finalize<'ctx, 'this>(
344331 metadata : & mut MetadataStorage ,
345332 _info : & SignatureOnlyConcreteLibfunc ,
346333) -> Result < ( ) > {
347- let felt252_ty = IntegerType :: new ( context, 252 ) . into ( ) ;
348- let ec_state_ty = llvm:: r#type:: r#struct ( context, & [ felt252_ty, felt252_ty] , false ) ;
349- let ec_point_ty = llvm:: r#type:: r#struct ( context, & [ felt252_ty, felt252_ty] , false ) ;
334+ let ec_state_ty = ec_state_ty ( context) ;
335+ let ec_point_ty = ec_point_ty ( context) ;
350336
351337 let point_ptr = helper. init_block ( ) . alloca1 (
352338 context,
@@ -385,13 +371,17 @@ pub fn build_state_init<'ctx, 'this>(
385371 _metadata : & mut MetadataStorage ,
386372 _info : & SignatureOnlyConcreteLibfunc ,
387373) -> Result < ( ) > {
388- let felt252_ty = IntegerType :: new ( context, 252 ) . into ( ) ;
389- let ec_state_ty = llvm:: r#type:: r#struct ( context, & [ felt252_ty, felt252_ty] , false ) ;
374+ let ec_state_ty = ec_state_ty ( context) ;
390375
376+ // The canonical projective identity `[0 : 1 : 0]`. Any `Z == 0` is the point
377+ // at infinity, but emitting the canonical form keeps memory dumps readable
378+ // and matches `ProjectivePoint::identity`.
391379 let k0 = entry. const_int ( context, location, 0 , 252 ) ?;
380+ let k1 = entry. const_int ( context, location, 1 , 252 ) ?;
392381 let state = entry. append_op_result ( llvm:: undef ( ec_state_ty, location) ) ?;
393382 let state = entry. insert_value ( context, location, state, k0, 0 ) ?;
394- let state = entry. insert_value ( context, location, state, k0, 1 ) ?;
383+ let state = entry. insert_value ( context, location, state, k1, 1 ) ?;
384+ let state = entry. insert_value ( context, location, state, k0, 2 ) ?;
395385
396386 helper. br ( entry, 0 , & [ state] , location)
397387}
@@ -406,14 +396,7 @@ pub fn build_try_new<'ctx, 'this>(
406396 metadata : & mut MetadataStorage ,
407397 _info : & SignatureOnlyConcreteLibfunc ,
408398) -> Result < ( ) > {
409- let ec_point_ty = llvm:: r#type:: r#struct (
410- context,
411- & [
412- IntegerType :: new ( context, 252 ) . into ( ) ,
413- IntegerType :: new ( context, 252 ) . into ( ) ,
414- ] ,
415- false ,
416- ) ;
399+ let ec_point_ty = ec_point_ty ( context) ;
417400
418401 let point_ptr = helper. init_block ( ) . alloca1 (
419402 context,
0 commit comments